0

有一个 Alexa 技能,可以读出一个随机的报价。会话以“shouldEndSession”结束:false。

如何保持会话打开并询问用户是否想听到另一个报价?这会触发 YesIntent。我正在使用 ':askWithCard' 使会话保持打开状态但不会触发 YesIntent

const handlers = {
  'LaunchRequest': function () {
      this.emit('Introduction');

  },
  'Introduction': function() {
    console.log("Introduction Handler called.");
    var speechOutput =  "Just say give me an office space quote";
    var repromptText = "I did not recieve any input. Thank you and good bye";
    this.emit(':askWithCard', speechOutput, repromptText);
  },

  'RandomQuoteIntent': function() {
    const quoteOfficeSpace = data;
    const quoteIndex = Math.floor(Math.random() * quoteOfficeSpace.length);
    const randomQuote = quoteOfficeSpace[quoteIndex];
    const speechOutput = randomQuote;

    this.response.cardRenderer(SKILL_NAME);

    this.response.speak(speechOutput);
    this.emit(':responseReady');


  },
   'AMAZON.YesIntent': function() {
    this.emit(':RandomQuoteIntent');
  },
  'AMAZON.HelpIntent': function () {
    const speechOutput = HELP_MESSAGE;
    const reprompt = HELP_REPROMPT;
    this.response.speak(speechOutput).listen(reprompt);
    this.emit(':responseReady');
  },
  'AMAZON.CancelIntent': function () {
      this.emit(':tell', "Okay! Goodbye, just don't forget to fill out your TPS reports");
  },
  'AMAZON.StopIntent': function () {
      this.emit(':tell', "Goodbye ");
  },
  'Unhandled': function () {
    console.log("Unhandled Intent Handler Called.");
    this.emit(':tell', "Sorry, I am unable to understand what you said. just say give me an office space quote");
  },

};


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

尝试了response.shouldEndSession(false, "would you like to hear another quote ");RandomQuoteIntent 但会话在读出第一个报价后关闭

4

1 回答 1

0

有一个 hacky 方法可以做到这一点:在提示问题后使用静音音频流。由于每个音频不应超过 90 秒,因此您最多可以有大约 180 秒的窗口来等待用户的下一次输入。

唯一需要注意的是,用户必须在实际命令之前中断音频,因此需要额外的“Alexa”或您选择的任何调用名称。

确切的代码和步骤在这里

于 2018-05-17T23:50:50.377 回答