在dialogflow v2 api中使用app.setContext()? [英] app.setContext() in dialogflow v2 api?
本文介绍了在dialogflow v2 api中使用app.setContext()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
v2 API中来自v1的dialogflow的app.setContext()等价于什么?给定迁移指南概述的设置(如下),当在下面的演示代码中触发欢迎意图时,您会打电话(例如)设置上下文?
What is the equivalent of dialogflow's app.setContext() from v1 in the v2 API? Given the setup that the migration guide outlines (below), what call would you make to--for example--set a context when the welcome intent is triggered in the demo code below?
// v2
const functions = require('firebase-functions');
const { dialogflow } = require('actions-on-google');
const app = dialogflow();
app.intent('Default Welcome Intent', conv => {
conv.ask('How are you?');
});
exports.factsAboutGoogle = functions.https.onRequest(app);
推荐答案
像这样设置上下文:
const parameters = { // Custom parameters to pass with context
welcome: true,
};
conv.contexts.set('welcome-context', 5, parameters);
第二个参数是上下文寿命。
The second parametr is for context lifespan.
在您的示例代码中:
const functions = require('firebase-functions');
const { dialogflow } = require('actions-on-google');
const app = dialogflow();
app.intent('Default Welcome Intent', conv => {
conv.ask('How are you?');
const parameters = { // Custom parameters to pass with context
welcome: true,
};
conv.contexts.set('welcome-context', 5, parameters);
});
exports.factsAboutGoogle = functions.https.onRequest(app);
然后,您可以使用以下内容访问上下文:
Then you can access the contexts with:
const contexts = conv.contexts;
这篇关于在dialogflow v2 api中使用app.setContext()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文