Alexa Skills: Как вставить AMAZON.yesintent и AMAZON.nointent в этом примере? - PullRequest
0 голосов
/ 29 марта 2019

Этот навык Alexa предоставляет информацию о книгах в мягкой обложке или онлайн-книгах. Это всего лишь пример, а не реальная вещь. Итак, вот пример Пользователь: «Алекса, найди лучшую книгу с одним автором». Алекса: «Хорошо! Вот книга, бла-бла». Алекса: "Хотели бы вы услышать это снова?" Пользователь: "Да!" Алекса: повторить ту же информацию. Я хочу знать, как я могу реализовать код, чтобы Alexa ответила на вопрос «да / нет» и повторила сказанное. Я провел обширное исследование по этому поводу, но до сих пор не могу понять. Кстати, я новичок в этом.

'booksIntent': function () {
        var speechOutput = '';
        var speechReprompt = '';

        var sourceSlot = resolveCanonical(this.event.request.intent.slots.source);
        console.log('User requested source: ' + sourceSlot);

        var authorSlot = resolveCanonical(this.event.request.intent.slots.author);
        console.log('User requested author: ' + authorSlot);

        var sources = {
            'basic book' : {
                'one author' : "Blah blah one author",

                'two authors' : "Blah blah two authors",

                'multiple authors' : "blah blah multiple authors"
            },

            'basic electronic' : {
                'one author' : "Blah blah...some electronic information"
            },

        }

         var authors = [
            'one author',
            'two authors',
            'multiple authors'
            ];

        var source =sourceSlot.toLowerCase();

        if(sourceSlot && sources[source]){
            var standardSource = '';
            var author = 'one author'; //default author choice

            if(authorSlot && author.indexOf(authorSlot) - 1){
                author = authorSlot;
            }

            var getSource = sources[source][author];

                speechOutput = 'Ok! ' + getSource;
                speechReprompt= 'Would you like to hear this again?'; //I want the user to answer with a yes or no and the program to respond accordingly. 


        }
            else{
                speechOutput = 'Sorry, the information you asked is not supported yet'
                speechReprompt = 'I support: this and that!'
            }
            this.emit(":ask", speechOutput, speechReprompt)

    },

1 Ответ

1 голос
/ 08 апреля 2019

Во-первых, вы должны обновить версию Alexa SDK.

Вы можете решить Да, Нет намерений, используя состояние.

Например, перед тем как вернуть речь, вы можете сохранить состояниекуда идти дальше.

Использование атрибутов для хранения состояний и всего.

attributes.state ="YES_MODE"

В Да, намерение,

вы должны проверить, соответствует ли это состояние или нет, затем разрешитьдля выполнения операции.

Вот код:

attributes.data = "You can store the data. What you want to repeat"
attributes.state = "YES_MODE"

return handlerInput.responseBuilder
  .speak(speechText)
  .reprompt(repromptText)
  .getResponse();

In Да Намерение:

 const YesIntentHandler = {
 canHandle(handlerInput) {
const attributes = handlerInput.attributesManager.getSessionAttributes();
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
  && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.YesIntent'
  && attributes.state === "YES_MODE";
},
handle(handlerInput) {
const attributes = handlerInput.attributesManager.getSessionAttributes();
let data = attributes.data

//write your logic 

return handlerInput.responseBuilder
  .speak(speechText)
  .reprompt(repromptText)
  .getResponse();
},
};
...