Scenario 3: Create a custom intent confirmation that provides the price to the user
When an intent request has potentially high consequences, it’s good practice to confirm the request with the user and mention those potential consequences. For example, if users ask to book a flight to Miami, they should know the cost of the flight before confirming the intent. They may change their minds if it’s too expensive.
In this case,
repromptSpeech in the intent confirmation would mention the price of the flight:
this.emit(':confirmIntent', speechOutput, repromptSpeech);
How to access values
These values have already been stored as variables for you:
const departureCityRequestedByUser = 'new york'; //defaulting departureCity to new york const arrivalCityRequestedByUser = this.event.request.intent.slots.arrivalCity.value; const departureDateRequestedByUser = this.event.request.intent.slots.departureDate.value; const departureDateConfirmationStatus = this.event.request.intent.slots.departureDate.confirmationStatus; const intentConfirmationStatus = this.event.request.intent.confirmationStatus;
How to determine price
The price of the flight can accessed with:
const recommendedFlight = flights [departureCityRequestedByUser.toLowerCase()] [arrivalCityRequestedByUser.toLowerCase()] [departureDateRequestedByUser]; const price = recommendedFlight['price'];
Once a user has provided enough slot values to book a flight (
departureCity, which may be set by default), determine the price of the flight and use the
:confirmIntent dialog directive to indicate that price. The skill should create conversations similar to those linked here.
For simplicity, the departure city is set to
'new york' within the
You can move on when your code passes the following tests:
- If (i) dialog is not completed, (ii) all three slot values are collected, (iii)
departureDatehas been confirmed, and (iv) the intent has not been confirmed or denied, then confirm the intent with the price.
The confirmation should include the price, which can be accessed with the code above.
- If the intent is denied, then reprompt the user for the arrival city (using the code below).
this.response.speak('Ok, canceling...What city would you like to fly to?' + HELP_REPROMPT).listen('What city would you like to fly to?' + HELP_REPROMPT); this.emit(':responseReady');
You’ve completed this checkpoint when your code passes this test: