亚马逊 Alexa 技能 [英] Amazon Alexa Skill

查看:38
本文介绍了亚马逊 Alexa 技能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问 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);

推荐答案

首先,不要创建自定义的 YesIntentNoIntent,而是使用 AMAZON.YesIntentAMAZON.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.YesIntentAMAZON.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);
    },

一旦设置了 state,下次将触发在该特定状态处理程序中定义的意图处理程序.相应地更改您的 state,完成后将其删除.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆