Learn
Control Dialog in Lambda
Overriding Slot Confirmation

“Deliver a specific confirmation prompt for each slot value using the :confirmSlot directive”

Now that we understand confirmationStatus, we can write custom slot confirmations!

ALEXA: What genre would you like? USER: Horror. ALEXA: I heard horror, correct? USER: Yes.

We can use the directive :confirmSlot to create a custom confirmation for the horror genre. In this case, we’d like to warn users about the R rating of available horror movies.

ALEXA: What genre would you like? USER: Horror. ALEXA: Horror movies are rated R. Do you still want that genre? USER: Yes.

Use the :confirmSlot directive in your Lambda function like this:

this.emit(':confirmSlot', slotToConfirm, speechOutput, repromptSpeech, updatedIntent);
  • The :confirmSlot directive is used to confirm the slot value the user has provided
  • slotToConfirm is the name of the slot to confirm, like genre
  • speechOutput is the string that will be used as the prompt, like “Horror movies are rated R. Do you still want that genre?”
  • repromptSpeech is the prompt used if the user takes longer than 8 seconds to reply or if the response was incomprehensible for Alexa. It is optional, but it’s good practice to use this parameter to provide context and guidance towards a valid response.
  • updatedIntent is used to update the state of the conversation. This will be explained later in the lesson. Optional.

Instructions

1.

Let’s implement the custom slot confirmation mentioned above. In index.js in the FindVideoByGenreIntent handler, the genre slot value is stored in genreRequestedByUser and the slotToConfirm is genre, the if-else statements are already set up, the main functionality (recommending a video) is included in the last else block. There are a two scenarios to consider:

  • First, if dialog is not completed, genre has been collected, but is has not been confirmed or denied, check if the genre is horror. If it is, use the custom slot elicitation.

Your code will look similar to this (You’ll need to add four arguments to this.emit()):

if (genreRequestedByUser == 'horror') { const speechOutput = genreRequestedByUser + ' is an R-rated genre. Are you sure?'; const repromptSpeech = speechOutput; this.emit( , , , ); }

Scroll down on index.js to find where this code belongs.

2.

If the genre is NOT horror, use the standard slot confirmation.

Your code will look similar to this (You’ll need to add four arguments to this.emit()):

else { const speechOutput = "So you're looking for " + genreRequestedByUser + ", correct?"; const repromptSpeech = speechOutput; this.emit( , , , ); }
Folder Icon

Take this course for free

Already have an account?