【发布时间】:2018-10-17 23:41:50
【问题描述】:
如何使用 Dialogflow Fulfillment Library WebhookClient 类设置“结束对话”标志?我正在使用由 Cloud Functions for Firebase 提供支持的内联编辑器,以防万一。
这种情况是特定意图的访问次数不能超过 3 次。在第一次和第二次访问时,您会得到回复,它允许您说些什么并继续;在第三次访问时,它应该给出响应然后结束对话/关闭麦克风/杀死应用程序(无论这个术语是什么)
对于非结束响应,我使用的是 WebhookClient.add(),并且我使用了丰富的响应和文本到语音的字符串。
根据我在 github (https://github.com/dialogflow/dialogflow-fulfillment-nodejs) 上阅读的内容,我认为 WebhookClient.end() 将是我想要的。但是当我使用它时,sript 崩溃了,我什么也得不到。
以下都是exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {...}里面的内容@
const agent = new WebhookClient({ request, response });
const fbContext = 'fallbackcount';
function fallback(agent) {
//all fallbacks use this fulfillment, we give up after 3 bunk responses
//check if we've been here before - we will find a context with a counter if we have
let countContext = agent.getContext(fbContext);
let fbcount = 0;
if (countContext)
{
if (typeof countContext.parameters !== "undefined" )
{
if(typeof countContext.parameters.count !== "undefined" )
{
fbcount = countContext.parameters.count;
}
}
}
console.log("current tracking" + fbcount.toString());
switch(fbcount) {
case 0:
{
agent.add(`Fallback response 1");
break;
}
case 1:
{
agent.add("Fallback response 2");
break;
}
default:
{
//intention: die on third bunk response
//reality: following line causes a problem and i get no response, and the app doesn't close
agent.end("Fallback response 3 - Goodbye!");
}
}
let newcount = fbcount + 1;
console.log("new tracking " + newcount.toString());
agent.setContext({
name: fbContext,
lifespan: 1,
parameters:{count: newcount}
});
}
我做错了什么?
请注意,这不是 Actions on Google: Unable to Close Convo in DialogFlow Fulfillment 的重复项,因为他在询问有关 actions-on-google 库的问题,而我正在使用 dialogflow-fulfillment-nodejs
我还看到了Dialogflow API V2 "End of conversation" flag in webhook request,这似乎是在处理原始 json,我认为这应该可以从我在文档中看到的内容中避免
【问题讨论】:
-
对于任何发现这个的人,我从来没有找到一个令人满意的方法来做到这一点,只使用 dialogflow-fulfillment-nodejs 库(没有以一种没有记录的奇怪方式做),并将一切都交换到使用 actions-on-google 库
标签: javascript node.js firebase webhooks dialogflow-es