Skip to Content
Learn
Control Dialog in Lambda
Setting Default Values

Remember the updatedIntent parameter in our directives? Here’s one example:

this.emit(':confirmSlot', slotToConfirm, speechOutput, repromptSpeech, updatedIntent);

We can use this parameter to overwrite values or set default values for the intent. For example, if a user doesn’t provide a value for the optional decade slot, we can set it to '90s' by default.

First, capture the current intent with:

const updatedIntent = this.event.request.intent;

Then add a default slot value with:

updatedIntent.slots.decade.value = '90s';

Include updatedIntent in our call to emit:

this.emit(':confirmSlot', 'decade', "I'll look for something in the 90s. Is that okay?", 'Is the decade 90s alright?', updatedIntent);

The conversation would go something like this:

ALEXA: What genre would you like? USER: Action. ALEXA: I can find movies or tv shows. Which would you like? USER: I'd like a movie. ALEXA: I'll look for something in the 90s. Is that okay? USER: Yes. ALEXA: You might like Die Hard.

Instructions

1.

Let’s use updatedIntent as mentioned above.

In index.js in the FindVideoByGenreIntent handler, the if-else statements are already set up, the main functionality (recommending a video) is included in the last else block.

Scroll down to this point in the code:

else if ((this.event.request.intent.slots.genre.value) && (this.event.request.intent.slots.genre.confirmationStatus == 'CONFIRMED') && (this.event.request.intent.slots.videoType.value) && this.event.request.intent.confirmationStatus == 'NONE')

At this point in the logic, dialog is not completed, a genre value has been provided and confirmed, and videoType have been provided and not confirmed.

In this case, check if the user provided a value for the decade slot. If a value is not provided, set a default decade value and confirm the slot.

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

if (!this.event.request.intent.slots.decade.value){ const updatedIntent = this.event.request.intent; updatedIntent.slots.decade.value = '80s'; this.emit( , , , , ); }
2.

Else if the decade was provided, check the confirmation status of that slot. If confirmed, delegate to Alexa

Your code will look similar to this (You’ll need to add the correct argument to this.emit()):

else if (this.event.request.intent.slots.decade.value) { if (this.event.request.intent.slots.decade.confirmationStatus == 'CONFIRMED'){ this.emit( ); }
3.

Else if decade was provided and the slot confirmation was denied, provide the standard slot elicitation for decade.

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

else if (this.event.request.intent.slots.decade.confirmationStatus == 'DENIED') { const slotToElicit = 'decade'; const speechOutput = 'What decade would you like. You can say 70s, 80s, or 90s'; const repromptSpeech = 'Say a decade, like 70s, 80s or 90s'; this.emit( , , , ); }

Folder Icon

Take this course for free

Already have an account?