Amazon Alexa Skill - PullRequest
       10

Amazon Alexa Skill

0 голосов
/ 29 августа 2018

Я хочу задать Алексе разные вопросы, а затем в конце хочу спросить: «Есть ли что-то еще, что вы хотели бы знать?» и когда я говорю «да» (где «да» - это действующее предложение), он должен предлагать меня в соответствии с намерением, в котором я нахожусь. Например, если я нахожусь в

IncityIntent:

    'InCityIntent': function () {
        speechOutput = '';


speechOutput = "The atmosphere in the city is beautiful. Is there anything else you would like to know";
        this.emit(":ask", speechOutput, speechOutput);


'YesIntent': function () {
        speechOutput = '';
/*when the user say yes, he should get this output*/  
            speechOutput = You can learn more about city by trying, alexa what are the best places in the city";
            this.emit(":tell",speechOutput, speechOutput);

FoodIntent:

    'FoodIntent': function () {
        speechOutput = '';


speechOutput = "Food in the city is delicious. Is there anything else you would like to know";
        this.emit(":ask", speechOutput, speechOutput);

'YesIntent': function () {
        speechOutput = '';
/*change in response here*/
            speechOutput = You can learn more about food by trying, alexa what are the best restaurants in the city";
            this.emit(":tell",speechOutput, speechOutput);

1 Ответ

0 голосов
/ 29 августа 2018

Во-первых, не создавайте пользовательские YesIntent и NoIntent, вместо этого используйте AMAZON.YesIntent и AMAZON.NoIntent. Вы всегда можете добавить высказывания к этим предопределенным намерениям, если хотите.

Ваши проблемы могут быть решены несколькими способами.

Использование атрибутов сессии :
Добавьте атрибут previousIntent или что-то еще, чтобы отслеживать разговор в sessionAttributes при получении первоначального запроса, скажем InCityIntent. А в вашем обработчике AMAZON.YesIntent или AMAZON.NoIntent проверьте предыдущее намерение и ответьте соответственно.

 'InCityIntent': function () {
       const speechOutput = "The atmosphere in the city is beautiful. Is there anything else you would like to know";
       const reprompt = "Is there anything else you would like to know";
       this.attributes['previousIntent'] = "InCityIntent";
       this.emit(":ask", speechOutput, reprompt);
  }

 'Amazon.YesIntent': function () {
     var speechOutput =  "";
     var reprompt = "";
     if (this.attributes 
        && this.attributes.previousIntent
        && this.attributes.previousIntent === 'InCityIntent' ) {
        speechOutput = "You can learn more about city by trying, Alexa what are the best places in the city";
        reprompt = "your reprompt";
     } else if ( //check for FoodIntent ) {

       // do accordingly
     }
     this.attributes['previousIntent'] = "Amazon.YesIntent";
     this.emit(":ask", speechOutput, reprompt);
  }

Использование обработчиков STATE
ask-nodejs-sdk v1 имеет обработчики состояний для генерации ответа на основе состояний. Идея похожа, SDK добавит для вас параметр sessionAttribute, а когда автоматически сопоставит обработчик с этим состоянием.

 'InCityIntent': function () {
       const speechOutput = "The atmosphere in the city is beautiful. Is there anything else you would like to know";
       const reprompt = "Is there anything else you would like to know";
       this.handler.state = "ANYTHING_ELSE";
       this.emit(":ask", speechOutput, reprompt);
  }

const stateHandlers = Alexa.CreateStateHandler("ANYTHING_ELSE", {
    "AMAZON.YesIntent": function () {
       var speechOutput =  "You can learn more about city by trying, Alexa what are the best places in the city";
       var reprompt = "your reprompt";
       this.emit(":ask", speechOutput, reprompt);
    },

После установки state в следующий раз будут запущены обработчики намерений, определенные в этом конкретном обработчике состояний. Измените ваш state соответственно и, когда закончите, удалите его.

...