【问题标题】:Intent not moving to next intent意图不移动到下一个意图
【发布时间】:2021-02-25 07:28:10
【问题描述】:

first intent second intent 如下代码所示,流程不是从 Number Intent 到 First Intent,而是循环到 number 循环中。在对话流中,每一个意图也会产生相应的上下文。流程没有根据上下文移动,并且卡在 NumberIntent 中。

流程应该像 google 询问用户的调查 id,用户说它的 id 612020 并且 google 开始询问它的问题。在问题类型为评分(即用户必须说出数字)之前,流程运行良好。当要求用户以描述性方式回答时会出现错误。

'use strict';
 
// Import the Dialogflow module from the Actions on Google client library.
const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');

// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});

const axios = require('axios').default;

global.ques = [];
global.i=0;

app.intent('Default Welcome Intent', (conv) => {
   conv.add('Hello! What is your survey id?');
      });

app.intent('NumberIntent', (conv,{number}) => {

  return axios.get('https://www.openeyessurvey.com/api/get_open_survey_info/612020')
  .then((result) => {
      result.data.Item.QUESTIONS.map(questionobj => {
      ques.push(questionobj.question);
     })
     conv.ask(ques[i]);
     i+=1;
  }).catch( err => {
        console.log("error", JSON.stringify(err,null,2));
        conv.close('This is not a valid survey ID');
      });
});

app.intent('FirstIntent', (conv, {number}) => {
      conv.ask(ques[i]);
      i+=1; 
});

app.intent('SecondIntent', (conv) => {
      const des = conv.parameters.any;
      if(des === 'ankit'){
      conv.ask(ques[i]);  
      i+=1;
      }
});

app.intent('ThirdIntent', (conv) => {
      conv.ask(ques[i]);  
      i+=1;
});

app.intent('FourthIntent', (conv, {number}) => {
      conv.ask(ques[i]);
      i+=1;  
});

app.intent('FifthIntent', (conv) => {
      conv.ask(ques[i]);  
      i+=1;
      conv.close('Goodbye!')
});


// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

Output Output2

INVALID INTENT NAME ERROR

【问题讨论】:

  • 欢迎来到 StackOverflow!如果不了解 Intent 本身是如何设置的,就很难诊断您的问题。您能否更新您的问题以包含所有引用的意图的屏幕截图?特别是示例短语以及输入和输出上下文。查看有关您期望的内容和实际发生的情况的示例对话也将有所帮助。见How do I ask a good question?
  • 我已经添加了相应的意图截图
  • 请查看intents及其输出的代码和截图。

标签: actions-on-google dialogflow-es-fulfillment


【解决方案1】:

我怀疑问题在于 i 从未真正得到更新。

您将 quesi 视为全局对象,但由于这是在 Firebase Cloud Functions 下运行的,因此每次调用都可能是该函数的一个新实例。作为一个新实例,它们会被重新初始化。

另一方面,如果您没有获得一个新实例,它还有一个问题是,如果多个人同时使用该操作,这将无法正常工作,因为他们都会共享i 的相同值。

两者的解决方案是,与其将 i 存储为全局变量,不如将其存储在 Actions on Google 会话存储或 Dialogflow 上下文参数中。

将其存储为会话参数,您将获取该值、使用它、递增它,然后将其再次保存在会话参数中。它可能看起来像这样:

const i = conv.data.i;
conv.ask(ques[i]);
conv.data.i = i+1;

【讨论】:

  • 感谢您的支持。正如您所说,我对代码进行了更改,但 Invalid Intent Name 的问题仍然存在。我附上了相同的屏幕截图。 @囚徒
  • 这有很多可能的原因,但它们听起来与您的原始问题无关。如果这已经解决了问题,我建议您接受答案并发布一个关于 Invalid Intent Name 的新答案,准确显示您是如何编辑和部署更新的,并概述您导致该错误所采取的步骤。
  • 好的。感谢您的支持。
  • 不客气。如果答案有帮助,欢迎接受和/或点赞。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-18
  • 1970-01-01
  • 2021-11-12
  • 2015-07-11
相关资源
最近更新 更多