简体   繁体   English

如何在谷歌助手的上下文未定义问题中修复参数

[英]How to fix parameters in the context undefined issue in google assistant

I have a problem with getting parameters in context.我在上下文中获取参数时遇到问题。

For example, I have 2 intents like "Question Intent" and "Answer Intent".例如,我有 2 个意图,如“问题意图”和“回答意图”。

In Question Intent, I have passing parameters with lifespan in context but in Answer Intent I'm getting context is undefined.在问题意图中,我在上下文中传递了具有生命周期的参数,但在回答意图中,我得到的上下文未定义。

Note: It works fine in the development version, Once I have deployed to production this issue came.注意:它在开发版本中运行良好,一旦我部署到生产中,这个问题就出现了。

Here is the code:这是代码:

Question Intent:提问意图:

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)

Answer intent:回答意图:

var conv = agent.conv();
let context = agent.context.get('data_req');
let userid = context.parameters['userid'];

I am getting parameters in the context is undefined我在上下文中获取参数未定义

A few questions, for context:几个问题,对于上下文:

  1. Have you tried out the Actions on Google codelabs?您是否尝试过 Actions on Google Codelabs? ( level one , level two , level three ) 一级二级三级

  2. Are you following any sort of tutorial?你在学习任何类型的教程吗?

I ask because I'm curious why you're storing the conv object in its own variable, and I don't see Dialogflow .intent() methods to handle your intents.我问是因为我很好奇你为什么将 conv 对象存储在它自己的变量中,而且我没有看到 Dialogflow .intent() 方法来处理你的意图。 A sample fulfillment I'm familiar with looks like...我熟悉的示例实现看起来像......

'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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM