【发布时间】:2018-09-04 16:00:11
【问题描述】:
我正在构建一个聊天机器人,我想对地址进行一些验证(荷兰的邮政编码必须写成 [1234XX]。但是在我的意图和 webhook 被调用之后,没有任何内容返回到对话中。它只是说“空响应”
在 Firebase 中出现以下错误:
Error: No handler for requested intent
at WebhookClient.handleRequest (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:287:29)
at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/user_code/index.js:49:9)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:26:47)
at /var/tmp/worker/worker.js:689:7
at /var/tmp/worker/worker.js:673:9
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
我运行的代码如下:
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function woningwaarde_instant_function (agent) {
// get the employee ID parameter from the request header received from Dialogflow
let zipcode = agent.parameters.zipcode;
if (zipcode.length === 6) {
agent.add(`The length of the Employee ID should be six characters. Please enter the correct ID.`);
} else { agent.add('lengte van postcode == 6'); }
}
function welcome (agent) {
agent.add(`Welcome to my agent!`);
agent.add(agent.request_.body.queryResult.fulfillmentText);
}
function fallback (agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('woningwaarde_instant', woningwaarde_instant_function);
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
agent.handleRequest(intentMap);
});
好像 agent.handleRequest(intentMap); 不满意,但我不知道如何解决这个问题,我整天都在尝试我能在网上找到的一切......
【问题讨论】:
-
能展示一下Dialogflow测试区吗?那里显示的已识别意图是什么?
-
我编辑了原始帖子,但正如您所见,它显示了 woningwaarde_instant 作为已识别的意图。
-
您是否能够访问默认欢迎意图和回退意图的功能
-
是的,如果我访问默认后备意图,它会返回此处定义的两个字符串:agent.add(
I didn't understand); agent.add(I'm sorry, can you try again?); -
当您发出错误的调用时,
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));行显示的 JSON 是什么? (你能用这个更新问题吗)。如果您将 Intent 的名称更改为更短的名称(例如“i1”)并在 webhook 中也进行更改,是否还会出现错误?
标签: javascript firebase google-cloud-functions dialogflow-es