Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get and use confirmation 'yes' or 'no' for Alexa skill intent response

I am developing a Alexa skill in which on launch it will ask Do you want to perform something ?
Depending upon user's reply 'yes' or 'no' I want to launch another intent.

var handlers = {
  'LaunchRequest': function () {
    let prompt = this.t("ASK_FOR_SOMETHING");
    let reprompt = this.t("LAUNCH_REPROMPT");
    this.response.speak(this.t("WELCOME_MSG") + ' ' + prompt).listen(reprompt);
    this.emit(':responseReady');
  },
  "SomethingIntent": function () {
    //Launch this intent if the user's response is 'yes'
  }
};

I did have a look at dialog model and it seems that it will serve the purpose. But I am not sure how to implement it.

like image 876
AkshayM Avatar asked Mar 31 '18 13:03

AkshayM


People also ask

Can Alexa ask yes or no questions?

Open your skill by saying, "Alexa, ask Yes No Maybe…" followed by your quesiton. Enjoy Alexa's response!

How do you set skill permissions on Alexa?

Open your skill in the developer console. Go to the Build page, and scroll down to Permissions on the lower left. Toggle the permission on for the permission that corresponds to the information your skill requires.

How long does Alexa skill review take?

Available times are in six-hour windows, and the publishing process starts at the beginning of the window. Expect the publishing process to take up to six hours.


1 Answers

The simplest way to do what you're looking for from the skill, is to handle the AMAZON.YesIntent and AMAZON.NoIntent from your skill (make sure to add them to the interaction model as well):

var handlers = {
  'LaunchRequest': function () {
    let prompt = this.t("ASK_FOR_SOMETHING");
    let reprompt = this.t("LAUNCH_REPROMPT");
    this.response.speak(this.t("WELCOME_MSG") + ' ' + prompt).listen(reprompt);
    this.emit(':responseReady');
  },
  "AMAZON.YesIntent": function () { 
    // raise the `SomethingIntent` event, to pass control to the "SomethingIntent" handler below 
    this.emit('SomethingIntent');
  },
  "AMAZON.NoIntent": function () {
    // handle the case when user says No
    this.emit(':responseReady');
  }
  "SomethingIntent": function () {
    // handle the "Something" intent here
  }
};

Note, that in a more complex skill you might have to store some state to figure out that the user sent a 'Yes' intent in response to your question as to whether to "do something". You can save this state using the skill session attributes in the session object. For instance:

var handlers = {
  'LaunchRequest': function () {
    let prompt = this.t("ASK_FOR_SOMETHING");
    let reprompt = this.t("LAUNCH_REPROMPT");
    this.response.speak(this.t("WELCOME_MSG") + ' ' + prompt).listen(reprompt);
    this.attributes.PromptForSomething = true;
    this.emit(':responseReady');
  },
  "AMAZON.YesIntent": function () { 
    if (this.attributes.PromptForSomething === true) {
      // raise the `SomethingIntent` event, to pass control to the "SomethingIntent" handler below 
      this.emit('SomethingIntent');
    } else {
      // user replied Yes in another context.. handle it some other way
      //  .. TODO ..
      this.emit(':responseReady');
    }
  },
  "AMAZON.NoIntent": function () {
    // handle the case when user says No
    this.emit(':responseReady');
  }
  "SomethingIntent": function () {
    // handle the "Something" intent here
    //  .. TODO ..
  }
};

Finally, you could also look into using the Dialog Interface as you alluded to in your question but if all you're trying to do is get a simple Yes/No confirmation as a prompt from the launch request than I think my example above would be pretty straight forward to implement.

like image 141
Mike Dinescu Avatar answered Sep 28 '22 06:09

Mike Dinescu