亚马逊Alexa技能 [英] Amazon Alexa Skill
问题描述
我想问alexa不同类型的问题,然后最后我要问您还有其他想知道的吗?当我说是(在这里是可行的建议)时,应该根据我的意图向我建议。就像我在
I want to ask alexa different sorts of questions and then at the end I want it should ask "Is there anything else you would like to know?" and when I say yes (where yes is working suggestion) it should suggest me according to the intent I am in. Like if I am in
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);
推荐答案
第一件事,不要创建自定义 YesIntent
和 NoIntent
,而是使用 AMAZON.YesIntent
和 AMAZON.NoIntent
。如果您愿意,可以随时将话语添加到这些预定义的意图中。
First thing, do not create custom YesIntent
and NoIntent
, instead use AMAZON.YesIntent
and AMAZON.NoIntent
. You can always add utterences to these predefined intents if you want to.
您的问题可以通过两种方式解决。
Your issues can be solved in a couple of ways.
使用sessionAttributes :
添加 previousIntent
属性或某些内容以跟踪转换 sessionAttributes
,当您收到初始请求时,说 InCityIntent
。然后在您的 AMAZON.YesIntent
或 AMAZON.NoIntent
处理程序中,检查先前的意图并相应地进行回复。
Using sessionAttributes:
Add a previousIntent
attribute or something to keep a track of the converstation in the sessionAttributes
when you receive the initial request, say InCityIntent
. And in your AMAZON.YesIntent
or AMAZON.NoIntent
handler check for the previous intent and reply accordingly.
'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);
}
使用STATE处理程序
ask-nodejs-sdk
v1具有状态处理程序,可基于状态生成响应。这个想法很相似,sdk将为您添加 sessionAttribute
参数,并且when将自动针对该状态映射处理程序。
Using STATE handlers
ask-nodejs-sdk
v1 has state handlers to generate response based on states. The idea is similar, the sdk will add the sessionAttribute
parameter for you and the when will automatically map the handler with respect to that state.
'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);
},
一旦设置了状态
,然后下次触发在该特定状态处理程序中定义的意图处理程序。相应地更改您的状态
,一旦完成,将其删除。
Once a state
is set, then next time the the intent handlers defined in that particular state handler will be triggered. Change your state
accordingly and once done, remove it.
这篇关于亚马逊Alexa技能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!