首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Alexa技能循环:基于用户的输入,Alexa会说些什么。

Alexa技能循环:基于用户的输入,Alexa会说些什么。
EN

Stack Overflow用户
提问于 2018-05-03 15:52:44
回答 2查看 531关注 0票数 0

我的技能:做一个果汁建议,当用户说一个状态时,Alexa会根据这个状态给出一个果汁建议。状态和果汁对被存储在一个数组中。

挑战:目前,我的技能只执行一次。有什么方法可以让我有一个循环,在Alexa提出建议之后,Alexa会再次问这个问题,然后等待用户的响应吗?附随的是我用我的技巧所拥有的密码。谢谢。

代码语言:javascript
复制
var Alexa = require('alexa-sdk');

const APP_ID = undefined;

const skillData = [
    {
        state: "FLORIDA",
        suggestion: "My suggestion for Florida is organic orange juice by Naked"
    },
    {
        state: "CALIFORNIA",
        suggestion: "My suggestion for California is pomegrante by POM!!"
    },
    {
        state: "NEW JERSEY",
        suggestion: "My suggestion for Jersey is blueberry by Jersey Fresh"
    }
];

var number = 0;
while(number<3){
var handlers = {
  'LaunchRequest': function () {

    this.emit(':ask', 'I can suggest a juice from any state in the United States. What state would you like a juice suggestion for?', 'Tell me a state name and I will suggest a local juice from there.');
  
      
    },
  'MakeSuggestion': function() {
      var stateSlot = this.event.request.intent.slots.state.value;

      this.emit(':tell', getSuggestion(skillData, 'state', stateSlot.toUpperCase()).suggestion);

  },
  'Unhandled': function () {
    this.emit(':tell', 'Sorry, I don\'t know what to do');
  },
  'AMAZON.HelpIntent': function () {
      this.emit(':ask', "What can I help you with?", "How can I help?");
  },
  'AMAZON.CancelIntent': function () {
      this.emit(':tell', "Okay!");
  },
  'AMAZON.StopIntent': function () {
      this.emit(':tell', "Goodbye!");
  },
}
number = number+1;
};

exports.handler = function(event, context){
  var alexa = Alexa.handler(event, context);
  alexa.registerHandlers(handlers);
  alexa.execute();
};

function getSuggestion(arr, propName, stateName) {
  for (var i=0; i < arr.length; i++) {
    if (arr[i][propName] == stateName) {
      return arr[i];
    }
  }
}

EN

回答 2

Stack Overflow用户

发布于 2018-05-04 14:39:27

在您的MakeSuggestion函数中,使用ask而不是tell,并再次附加问题:

代码语言:javascript
复制
this.emit(':ask', getSuggestion(skillData, 'state', stateSlot.toUpperCase()).suggestion + '. Tell me another state and I give you another suggestion!');
票数 1
EN

Stack Overflow用户

发布于 2018-05-04 00:54:29

是的,您可以通过使用state来完成这一任务,而不是使用":tell",您可以通过":ask“来响应,这样alexa麦克风就可以保持开放状态以进行用户交互。

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

https://stackoverflow.com/questions/50159227

复制
相关文章

相似问题

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