Learn
Control Dialog in Lambda
Overriding Slot Elicitation

“Change the slot elicitation prompt based on the available options using the :elicitSlot directive”

ALEXA: What genre would you like? USER: German Expressionism. ALEXA: What genre would you like? USER: I'd like German Expressionism. ALEXA: What genre would you like? USER: German Expressionism, please.

This conversation is not ideal. It’s fine if the skill doesn’t support “German Expressionism”, but it doesn’t guide the user towards a successful dialog by providing them available options. With the :elicitSlot directive, we can write code for our skill that dynamically generates the available genres.

ALEXA: What genre would you like? USER: German Expressionism. ALEXA: What genre would you like? USER: I'd like German Expressionism. ALEXA: I'm not familiar with that one, but you can say action, horror, comedy, and drama. USER: Drama.

You can use the :elicitSlot directive like this in your Lambda function:

this.emit(':elicitSlot', slotToElicit, speechOutput, repromptSpeech, updatedIntent);
  • The :elicitSlot directive is used to prompt the user for the value of a slot
  • slotToElicit is the name of the slot to be filled, like genre
  • speechOutput is the string that will be used as the prompt, like “I’m not familiar with that one, but you can say action, horror, comedy, and drama.”
  • 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 elicitation mentioned above. In index.js in the FindVideoByGenreIntent handler, the list of available genres is stored in listOfGenres, the if-else statements are already set up, the main functionality (recommending a video) is included in the last else block. There are three scenarios to consider:

  • if dialog is not 'COMPLETED'
    • if the genre slot value has not been collected, use the custom elicitation
    • else delegate to alexa
  • else use the main functionality

For the first scenario: use the custom elicitation when dialogState is not 'COMPLETED' and the genre.value is not collected.

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

if (this.event.request.dialogState !== 'COMPLETED') { if (!this.event.request.intent.slots.genre.value) { const slotToElicit = 'genre'; const speechOutput = 'What genre would you like. You can say ' + listOfGenres; const repromptSpeech = 'Please tell me the genre for the video you would like. You can say ' + listOfGenres; this.emit( , , , ); }
2.

Delegate to Alexa otherwise.

In the first else block, your code will look similar to this (You’ll need to add the correct argument to this.emit()):

else { this.emit( ); }

Folder Icon

Take this course for free

Already have an account?