首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Amazon Alexa技能

Amazon Alexa技能
EN

Stack Overflow用户
提问于 2018-08-29 20:13:34
回答 1查看 209关注 0票数 0

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

代码语言:javascript
复制
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);
EN

回答 1

Stack Overflow用户

发布于 2018-08-29 21:26:30

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

你的问题可以通过几种方式来解决。

使用sessionAttributes的

添加一个previousIntent属性或其他东西,以便在收到初始请求时在sessionAttributes中跟踪转换器,比如InCityIntent。在您的AMAZON.YesIntentAMAZON.NoIntent处理程序中,检查以前的意图并相应地进行回复。

代码语言:javascript
复制
 '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将自动将处理程序映射到该状态。

代码语言:javascript
复制
 '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,并在完成后将其删除。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52077201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档