簡體   English   中英

如何在谷歌助手的上下文未定義問題中修復參數

[英]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'];

我在上下文中獲取參數未定義

幾個問題,對於上下文:

  1. 您是否嘗試過 Actions on Google Codelabs? 一級二級三級

  2. 你在學習任何類型的教程嗎?

我問是因為我很好奇你為什么將 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM