我想问alexa不同类型的问题,然后在最后我希望它应该问“还有什么你想知道的吗?”当我说是(其中yes是工作建议)时,它应该根据我所在的意图来建议我。就像如果我在
IncityIntent:
'InCityIntent': function () {
speechOutput = '';
speechOutput = "The atmosphere in the city is beautiful. Is there anything else you would like to know";
this.emit(":ask", speechOutput, speechOutput);
'YesIntent': function () {
speechOutput = '';
/*when the user say yes, he should get this output*/
speechOutput = You can learn more about city by trying, alexa what are the best places in the city";
this.emit(":tell",speechOutput, speechOutput);
FoodIntent:
'FoodIntent': function () {
speechOutput = '';
speechOutput = "Food in the city is delicious. Is there anything else you would like to know";
this.emit(":ask", speechOutput, speechOutput);
'YesIntent': function () {
speechOutput = '';
/*change in response here*/
speechOutput = You can learn more about food by trying, alexa what are the best restaurants in the city";
this.emit(":tell",speechOutput, speechOutput);发布于 2018-08-29 21:26:30
首先,不要创建自定义的YesIntent和NoIntent,而要使用AMAZON.YesIntent和AMAZON.NoIntent。如果您愿意,您可以随时向这些预定义意图中添加话语。
你的问题可以通过几种方式来解决。
使用sessionAttributes的
添加一个previousIntent属性或其他东西,以便在收到初始请求时在sessionAttributes中跟踪转换器,比如InCityIntent。在您的AMAZON.YesIntent或AMAZON.NoIntent处理程序中,检查以前的意图并相应地进行回复。
'InCityIntent': function () {
const speechOutput = "The atmosphere in the city is beautiful. Is there anything else you would like to know";
const reprompt = "Is there anything else you would like to know";
this.attributes['previousIntent'] = "InCityIntent";
this.emit(":ask", speechOutput, reprompt);
}
'Amazon.YesIntent': function () {
var speechOutput = "";
var reprompt = "";
if (this.attributes
&& this.attributes.previousIntent
&& this.attributes.previousIntent === 'InCityIntent' ) {
speechOutput = "You can learn more about city by trying, Alexa what are the best places in the city";
reprompt = "your reprompt";
} else if ( //check for FoodIntent ) {
// do accordingly
}
this.attributes['previousIntent'] = "Amazon.YesIntent";
this.emit(":ask", speechOutput, reprompt);
}使用状态处理程序的
ask-nodejs-sdk v1具有基于状态生成响应的状态处理程序。想法类似,软件开发工具包将为您添加sessionAttribute参数,而when将自动将处理程序映射到该状态。
'InCityIntent': function () {
const speechOutput = "The atmosphere in the city is beautiful. Is there anything else you would like to know";
const reprompt = "Is there anything else you would like to know";
this.handler.state = "ANYTHING_ELSE";
this.emit(":ask", speechOutput, reprompt);
}
const stateHandlers = Alexa.CreateStateHandler("ANYTHING_ELSE", {
"AMAZON.YesIntent": function () {
var speechOutput = "You can learn more about city by trying, Alexa what are the best places in the city";
var reprompt = "your reprompt";
this.emit(":ask", speechOutput, reprompt);
},一旦设置了state,下一次将触发在该特定状态处理程序中定义的意图处理程序。相应地更改您的state,并在完成后将其删除。
https://stackoverflow.com/questions/52077201
复制相似问题