【发布时间】: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);
【问题讨论】:
-
欢迎来到 StackOverflow!如果不了解 Intent 本身是如何设置的,就很难诊断您的问题。您能否更新您的问题以包含所有引用的意图的屏幕截图?特别是示例短语以及输入和输出上下文。查看有关您期望的内容和实际发生的情况的示例对话也将有所帮助。见How do I ask a good question?
-
我已经添加了相应的意图截图
-
请查看intents及其输出的代码和截图。
标签: actions-on-google dialogflow-es-fulfillment