【问题标题】:Amazon Alexa Skill亚马逊 Alexa 技能
【发布时间】:2019-02-04 05:28:53
【问题描述】:

我想问 alexa 不同类型的问题,最后我希望它应该问“你还有什么想知道的吗?”当我说是时(是的工作建议),它应该根据我的意图向我提出建议。就像我在

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);

【问题讨论】:

    标签: alexa alexa-skills-kit alexa-skill


    【解决方案1】:

    首先,不要创建自定义YesIntentNoIntent,而是使用AMAZON.YesIntentAMAZON.NoIntent。如果您愿意,您可以随时向这些预定义的意图添加话语。

    您的问题可以通过多种方式解决。

    使用 sessionAttributes
    当您收到初始请求时,添加previousIntent 属性或其他内容以跟踪sessionAttributes 中的转换,例如InCityIntent。在您的 AMAZON.YesIntentAMAZON.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 具有状态处理程序来根据状态生成响应。思路类似,sdk 会为你添加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,完成后将其删除。

    【讨论】:

    • 感谢您的回复,但以上方法均无效。它给出了没有响应的错误。
    • 请勿复制粘贴代码,仅供参考。
    • 我没有复制粘贴。当我尝试运行此代码时,如果我用我的技能名称说是,比如告诉 citytravel 是,那么它会从我第一次声明是的意图重复对话,如果我只是说是,那么它会说存在问题请求技能的响应。
    • 进入技能会话后,您不必每次都使用技能调用名称。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-21
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多