简体   繁体   中英

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

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? ( 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. 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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