Alexa Skill: Обработка ShouldEndSession для сохранения сессии открытой - PullRequest
0 голосов
/ 17 мая 2018

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

1 Ответ

0 голосов
/ 18 мая 2018

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

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

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

...