[英]How to fix parameters in the context undefined issue in google assistant
我在上下文中获取参数时遇到问题。
例如,我有 2 个意图,如“问题意图”和“回答意图”。
在问题意图中,我在上下文中传递了具有生命周期的参数,但在回答意图中,我得到的上下文未定义。
注意:它在开发版本中运行良好,一旦我部署到生产中,这个问题就出现了。
这是代码:
提问意图:
var conv = agent.conv();
conv.ask("What's your age?");
let context = {'name':'data_req','lifespan':'5','parameters':{'userid':12,'country':'IN'}};
agent.context.set(context);
agent.add(conv)
回答意图:
var conv = agent.conv();
let context = agent.context.get('data_req');
let userid = context.parameters['userid'];
我在上下文中获取参数未定义
几个问题,对于上下文:
我问是因为我很好奇你为什么将 conv 对象存储在它自己的变量中,而且我没有看到 Dialogflow .intent() 方法来处理你的意图。 我熟悉的示例实现看起来像......
'use strict';
// Import the Dialogflow module and response creation dependencies from the
// Actions on Google client library.
const {
dialogflow,
Permission,
Suggestions,
BasicCard,
List,
Image
} = require('actions-on-google');
// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');
// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});
// Handle the Dialogflow intent named 'Default Welcome Intent'.
app.intent('Default Welcome Intent', (conv) => {
conv.ask(`Hey, welcome to the Greeting Card Store! You can browse and buy handmade cards, available to ship anywhere in the contiguous United States. What kind of card are you looking for?`);
conv.ask(new Suggestions('Birthday', 'Romantic'));
});
// Handle the Dialogflow intent named 'favorite color'.
// The intent collects a parameter named 'color'.
app.intent('favorite color', (conv, {color}) => {
const luckyNumber = color.length;
// Respond with the user's lucky number and end the conversation.
conv.close('Your lucky number is ' + luckyNumber);
});
// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.