我试图从对话框流中调用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);
});
答案 0 :(得分:10)
我刚遇到了同样的错误,之所以这是因为我忘记将我的意图名称放在Enter action name
部分的Actions
字段中。
所以,它传递了null
作为意图名称,因为我没有指定一个。
我只是非常认真地 重新阅读https://developers.google.com/actions/dialogflow/first-app。
答案 1 :(得分:2)
谢谢大家的宝贵回应。不知何故,我能够修复此null错误。实际上,我在代理的API版本部分启用了“Dialogflow V2 API”。现在,我已禁用它,它对我有用。
答案 2 :(得分:1)
对于每个代理,都需要一个unknown
Intent处理程序来处理意外情况,例如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);
}