Alexa Skill: обработка ShouldEndSession для сохранения сеанса открытым

Иметь навык 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, но сеанс был закрыт после того, как он прочитал первую цитату


person Neil    schedule 17.05.2018    source источник


Ответы (1)


Есть хакерский способ сделать это: использовать тихую потоковую передачу звука после запроса вопроса. Поскольку каждый звук должен длиться не более 90 секунд, у вас может быть максимум примерно 180 секунд для ожидания следующего ввода пользователя.

Единственное предостережение заключается в том, что пользователю придется прерывать звук, таким образом, добавляя дополнительное «Alexa» или любое другое имя вызова, которое вы выберете, перед фактической командой.

Точный код и шаги здесь

person Alex Xiong    schedule 17.05.2018