node.js - Dialogflow:在 Dialogflow 中使用实现库 (node.js) 设置多个上下文
问题描述
我正在尝试根据用户的响应设置/更改多个上下文。为此,我试图通过内联编辑器(node.js)使用实现库通过agent.setContext()设置输出上下文。我想删除对话流中按意图设置的上下文,并在 Dialogflow 的输出上下文中添加新上下文。
通过在 node.js 中调用 agent.setContext() 来设置一个输出上下文时它工作正常,但是当我在 agent.setContext() 中传递多个上下文的列表时它会抛出错误,如下所示:
注意:我在 Dialogflow Intent 的输出上下文中给出了 3 个输出上下文(context_name_1、context_name_2、context_name_3)
代码片段:
function intent_name(agent) {
... // defined text response for user
...
agent.setContext([{
'name':'context_name_1',
'lifespan': 10
},
{
'name':'context_name_2',
'lifespan': 0
},
{
'name':'context_name_3',
'lifespan': 0
},
{
'name':'context_name_4',
'lifespan': 3
}]);
....
}
我得到错误:
Error: context must be provided and must have a name
at WebhookClient.setContext (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:343:13)
at prepaidRecharge (/srv/index.js:45:15)
at WebhookClient.handleRequest (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:303:44)
at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/srv/index.js:92:9)
at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:57:9)
at /worker/worker.js:783:7
at /worker/worker.js:766:11
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickDomainCallback (internal/process/next_tick.js:219:9)
任何帮助,将不胜感激。
解决方案
分别设置它们...
agent.setContext({ name: 'context_name_1', lifespan: 10, parameters: { city: 'Rome' }});
agent.setContext({ name: 'context_name_2', lifespan: 11, parameters: { continent: 'eu' }});
或者使用新的方式:
agent.context.set('context_name_1', 10, {'param1' : 'abc'});
agent.context.set('context_name_2', 11, {'param2' : 2});
推荐阅读
- android - 实时下载优化。如何找到泄漏点?
- ajax - 谷歌分析/标签管理器内部站点搜索 API
- excel - F1 在我的 Excel-VBA 中不起作用,我该如何解决?
- apache-kafka - \Java\jdk1.6.0_26\lib 此时出乎意料。在运行 apache kafka 时
- asp.net - MVC Repository 类中缺少显式强制转换
- python - 给定一个点列表 (x,y),创建一个新的点列表,这些点彼此不靠近
- redux - 在构建 redux 应用程序时,combineReducers 中 reducer 的顺序排列是否重要?
- arrays - 在给定数组中查找阈值
- delphi - Delphi TFileStream WriteBuffer Int64的大小不是吗?我一次只能写少量
- python - 如何使用 python-pptx 删除聚集条形图中的轴线?