concept dialog in category alexa

This is an excerpt from Manning's book Voice Applications for Alexa and Google Assistant.
We can let Alexa handle the dialog because at each step in the dialog, Alexa sends the fulfillment an intent request that also contains a property named
dialogState. In figure 8.2, you see thedialogStatechange as the dialog moves forward. Until every slot is filled and all information is confirmed,dialogStatewill have a value other thanCOMPLETED. The intent can check for the presence of this value and pass back control to Alexa if it’s not present. Alexa will use responses defined in the dialog model to speak to the user.Figure 8.2 The states of a dialog
![]()
Setting the groundwork for the elicitation requires a new addition to the interaction model, outlining the dialog.
Listing 8.3 A
dialogobject in the interaction model (./models/en-US.json){ "interactionModel": { "languageModel": { ... }, "dialog": { #1 "intents": [ #1 { #1 "name": "BuyTicketsIntent", #1 "slots": [] #1 } #1 ] #1 }, #1 "prompts": [] } } #1 A new object to hold the dialog model
When Alexa handles most or all of the elicitation and confirmation, the fulfillment still has two tasks. The first is to delegate control back to Alexa if the dialog isn’t complete—if not all of the slots that need further action are complete. If all of the elicitation and confirmation is complete, the second task is to provide Alexa with the speech it will use to respond.
Listing 8.14 The handler for the
BuyTicketsIntent(./lambda/custom/index.js)... const BuyTicketsIntentHandler = { ... handle(handlerInput) { const dialogComplete = "COMPLETED"; const dialogStarted = "STARTED"; const intent = handlerInput.requestEnvelope.request.intent; const ticketPrice = 10; if (handlerInput.requestEnvelope.request.dialogState !== dialogComplete) { #1 if (handlerInput.requestEnvelope.request.dialogState === dialogStarted) { #2 intent.slots.TicketsNumber.value = intent.slots.TicketsNumber.value || 1; #2 } #2 } else { #3 const movieName = intent.slots.MovieName.value; #3 const movieTime = intent.slots.MovieTime.value; #3 let ticketsNumber = intent.slots.TicketsNumber.value; #3 if (ticketsNumber) { #3 ticketsNumber = parseInt(ticketsNumber); #3 } else { #3 ticketsNumber = 1; #3 } #3 const price = ticketsNumber * ticketPrice; #3 const speech = `Alright <break strength="strong" /> ${ticketsNumber} ` + #3 `for ${movieName}. Total cost, $${price}, and the movie ➥` + #3 `starts at ${movieTime}.`; #3 return handlerInput.responseBuilder #3 .speak(speech) #3 .getResponse(); #3 } #3 } }; ... #1 At each step of the dialog, the inbound request specifies whether the dialog is complete. #2 Initializes the number of tickets when the dialog starts #3 Provides the final response