Nee*_*ngh 8 json node.js actions-on-google dialogflow-es
我试图从对话框流中调用webhook,而不是从webhook获得响应,我从响应部分得到的响应,我已将其置于意图中.我还为每个意图启用了webhook,并且还放置了webhook URL,该URL是从firebase CLI在履行URL部分生成的.我附上了firebase日志和JSON响应的屏幕截图,我们在对话框流程"show JSON"和index.js文件中也看到了.我被困了2周才解决它.
'use strict';
process.env.DEBUG = 'actions-on-google:*';
const { DialogflowApp } = require('actions-on-google');
const functions = require('firebase-functions');
let express = require('express');
let bodyParser = require('body-parser');
// Constants for Dialogflow Agent Actions
let app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({type: 'application/json'}));
const BYE_RESPONSE = 'input.search';
const WELCOME = 'input.welcome';
exports.helloAssistant = functions.https.onRequest((req, res) => {
console.log('Request headers: ' + JSON.stringify(req.headers));
console.log('Request body: ' + JSON.stringify(req.body));
const asst = new DialogflowApp({request: req, response: res});
// Welcome
function welcome(asst) {
asst.ask('Want to search product or order history');
asst.tell('hello Neeraj!');
}
// Leave conversation with SimpleResponse
function byeResponse (asst) {
app.post('/',function (req, res) {
var myProduct = req.body.result.parameters["productParameter"];
//let intent=asst.getIntent();
var address ="https://ipadress/rest/v2/electronics/products/search";
var address1="https://ipadress";
switch(myProduct){
case 'BYE_RESPONSE':
req.post(address);
break;
case 'WELCOME':
asst.tell('welcome!');
break;
default:
req.post(address1);
break;
}
asst.tell('We swear to serve the master of the Precious.');
});
}
const actionMap = new Map();
actionMap.set(WELCOME, welcome);
actionMap.set(BYE_RESPONSE, byeResponse);
actionMap.set(WELCOME, welcome);
asst.handleRequest(actionMap);
});Run Code Online (Sandbox Code Playgroud)
Top*_*gio 10
我刚刚遇到了这个完全相同的错误,这是因为我忘记将我的意图名称放在Enter action name该Actions部分的字段中.
因此,它是null作为意图名称传递的,因为我没有指定一个.
我只是通过非常仔细地重新阅读https://developers.google.com/actions/dialogflow/first-app来解决这个问题.
对于每个代理都需要有一个unknownIntent 处理程序来处理意外情况,例如 null 等
'input.unknown': () => {
// The default fallback intent has been matched, try to recover.
// Define the response users will hear
responseJson.speech = 'I\'m having trouble, can you try that again?';
// Define the response users will see
responseJson.displayText = 'I\'m having trouble :-/ can you try that again?';
// Send the response to API.AI
// response.json(responseJson);
callback(null, responseJson);
}
Run Code Online (Sandbox Code Playgroud)