Exercise 2: Review the conversation flow
In this exercise you review the JSON structures that are sent between your client application and the Amazon Lex V2 bot that you created in Exercise 1: Create a bot from an example. The conversation uses the RecognizeText operation to generate the JSON structures. The RecognizeUtterance returns the same information as HTTP headers in the response.
The JSON structures are divided by each turn of the conversation. A turn is a request from the client application and a response from the bot.
Turn 1
During the first turn of the conversation, the client application initiates the conversation with your bot. Both the URI and the body of the request provide information about the request.
POST /bots/botId
/botAliases/botAliasId
/botLocales/localeId
/sessions/sessionId
/text HTTP/1.1
Content-type: application/json
{
"text": "I would like to order flowers"
}
-
The URI identifies the bot that the client application is communicating with. It also includes a session identifier generated by the client application that identifies a specific conversation between a user and the bot.
-
The body of the request contains the text that the user typed to the client application. In this case, only the text is sent, however your application can send additional information, such as request attributes or session state. For more information, see the RecognizeText operation.
From text
, Amazon Lex V2 detects the user's intent, to order
flowers. Amazon Lex V2 chooses one of the intent's slots
(FlowerType
) and one of the prompts for the slot,
and then sends the following response to the client application. The
client displays the response to the user.
{
"interpretations": [
{
"intent": {
"confirmationState": "None",
"name": "OrderFlowers",
"slots": {
"FlowerType": null,
"PickupDate": null,
"PickupTime": null
},
"state": "InProgress"
},
"nluConfidence": {
"score": 0.95
}
},
{
"intent": {
"name": "FallbackIntent",
"slots": {}
}
}
],
"messages": [
{
"content": "What type of flowers would you like to order?",
"contentType": "PlainText"
}
],
"sessionId": "bf445a49-7165-4fcd-9a9c-a782493fba5c",
"sessionState": {
"dialogAction": {
"slotToElicit": "FlowerType",
"type": "ElicitSlot"
},
"intent": {
"confirmationState": "None",
"name": "OrderFlowers",
"slots": {
"FlowerType": null,
"PickupDate": null,
"PickupTime": null
},
"state": "InProgress"
},
"originatingRequestId": "9e8add70-4106-4a10-93f5-2ce2cb959e5f"
}
}
Turn 2
In turn 2, the user responds to the prompt from the Amazon Lex V2 bot
in turn 1 with a value that fills the FlowerType
slot.
{
"text": "1 dozen roses"
}
The response for turn 2 shows the FlowerType
slot
filled and provides a prompt to elicit the next slot value.
{
"interpretations": [
{
"intent": {
"confirmationState": "None",
"name": "OrderFlowers",
"slots": {
"FlowerType": {
"value": {
"interpretedValue": "dozen roses",
"originalValue": "dozen roses",
"resolvedValues": []
}
},
"PickupDate": null,
"PickupTime": null
},
"state": "InProgress"
},
"nluConfidence": {
"score": 0.98
}
},
{
"intent": {
"name": "FallbackIntent",
"slots": {}
}
}
],
"messages": [
{
"content": "What day do you want the dozen roses to be picked up?",
"contentType": "PlainText"
}
],
"sessionId": "bf445a49-7165-4fcd-9a9c-a782493fba5c",
"sessionState": {
"dialogAction": {
"slotToElicit": "PickupDate",
"type": "ElicitSlot"
},
"intent": {
"confirmationState": "None",
"name": "OrderFlowers",
"slots": {
"FlowerType": {
"value": {
"interpretedValue": "dozen roses",
"originalValue": "dozen roses",
"resolvedValues": []
}
},
"PickupDate": null,
"PickupTime": null
},
"state": "InProgress"
},
"originatingRequestId": "9e8add70-4106-4a10-93f5-2ce2cb959e5f"
}
}
Turn 3
In turn 3, the user responds to the prompt from the Amazon Lex V2 bot
in turn 2 with a value that fills the PickupDate
slot.
{
"text": "next monday"
}
The response for turn 3 both the FlowerType
and
PickupDate
slots filled and provides a prompt to elicit
the last slot value.
{
"interpretations": [
{
"intent": {
"confirmationState": "None",
"name": "OrderFlowers",
"slots": {
"FlowerType": {
"value": {
"interpretedValue": "dozen roses",
"originalValue": "dozen roses",
"resolvedValues": []
}
},
"PickupDate": {
"value": {
"interpretedValue": "2022-12-28",
"originalValue": "next monday",
"resolvedValues": [
"2021-01-04"
]
}
},
"PickupTime": null
},
"state": "InProgress"
},
"nluConfidence": {
"score": 1.0
}
},
{
"intent": {
"name": "FallbackIntent",
"slots": {}
}
}
],
"messages": [
{
"content": "At what time do you want the 1 dozen roses to be picked up?",
"contentType": "PlainText"
}
],
"sessionId": "bf445a49-7165-4fcd-9a9c-a782493fba5c",
"sessionState": {
"dialogAction": {
"slotToElicit": "PickupTime",
"type": "ElicitSlot"
},
"intent": {
"confirmationState": "None",
"name": "OrderFlowers",
"slots": {
"FlowerType": {
"value": {
"interpretedValue": "dozen roses",
"originalValue": "dozen roses",
"resolvedValues": []
}
},
"PickupDate": {
"value": {
"interpretedValue": "2021-01-04",
"originalValue": "next monday",
"resolvedValues": [
"2021-01-04"
]
}
},
"PickupTime": null
},
"state": "InProgress"
},
"originatingRequestId": "9e8add70-4106-4a10-93f5-2ce2cb959e5f",
"sessionAttributes": {}
}
}
Turn 4
In turn 4, the user provides the final slot value for the intent, the time that the flowers are picked up.
{
"text": "5 in the evening"
}
In the response, Amazon Lex V2 sends a confirmation prompt to the user to
confirm that the order is correct. The dialogAction
is
set to ConfirmIntent
and the
confirmationState
is None
.
{
"interpretations": [
{
"intent": {
"confirmationState": "None",
"name": "OrderFlowers",
"slots": {
"FlowerType": {
"value": {
"interpretedValue": "dozen roses",
"originalValue": "dozen roses",
"resolvedValues": []
}
},
"PickupDate": {
"value": {
"interpretedValue": "2021-01-04",
"originalValue": "next monday",
"resolvedValues": [
"2021-01-04"
]
}
},
"PickupTime": {
"value": {
"interpretedValue": "17:00",
"originalValue": "5 evening",
"resolvedValues": [
"17:00"
]
}
}
},
"state": "InProgress"
},
"nluConfidence": {
"score": 1.0
}
},
{
"intent": {
"name": "FallbackIntent",
"slots": {}
}
}
],
"messages": [
{
"content": "Okay, your dozen roses will be ready for pickup by 17:00 on 2021-01-04. Does this sound okay?",
"contentType": "PlainText"
}
],
"sessionId": "bf445a49-7165-4fcd-9a9c-a782493fba5c",
"sessionState": {
"dialogAction": {
"type": "ConfirmIntent"
},
"intent": {
"confirmationState": "None",
"name": "OrderFlowers",
"slots": {
"FlowerType": {
"value": {
"interpretedValue": "dozen roses",
"originalValue": "dozen roses",
"resolvedValues": []
}
},
"PickupDate": {
"value": {
"interpretedValue": "2021-01-04",
"originalValue": "next monday",
"resolvedValues": [
"2021-01-04"
]
}
},
"PickupTime": {
"value": {
"interpretedValue": "17:00",
"originalValue": "5 evening",
"resolvedValues": [
"17:00"
]
}
}
},
"state": "InProgress"
},
"originatingRequestId": "9e8add70-4106-4a10-93f5-2ce2cb959e5f"
}
}
Turn 5
In the final turn, the user responds with to the confirmation prompt.
{
"text": "yes"
}
In the response, Amazon Lex V2 sends indicates that the intent has been
fulfilled by setting the confirmationState
to
Confirmed
and the dialogAction
to
close. All of the slot values are available to the client
application.
{
"interpretations": [
{
"intent": {
"confirmationState": "Confirmed",
"name": "OrderFlowers",
"slots": {
"FlowerType": {
"value": {
"interpretedValue": "dozen roses",
"originalValue": "dozen roses",
"resolvedValues": []
}
},
"PickupDate": {
"value": {
"interpretedValue": "2021-01-04",
"originalValue": "next monday",
"resolvedValues": [
"2021-01-04"
]
}
},
"PickupTime": {
"value": {
"interpretedValue": "17:00",
"originalValue": "5 evening",
"resolvedValues": [
"17:00"
]
}
}
},
"state": "Fulfilled"
},
"nluConfidence": {
"score": 1.0
}
},
{
"intent": {
"name": "FallbackIntent",
"slots": {}
}
}
],
"messages": [
{
"content": "Thanks. ",
"contentType": "PlainText"
}
],
"sessionId": "bf445a49-7165-4fcd-9a9c-a782493fba5c",
"sessionState": {
"dialogAction": {
"type": "Close"
},
"intent": {
"confirmationState": "Confirmed",
"name": "OrderFlowers",
"slots": {
"FlowerType": {
"value": {
"interpretedValue": "dozen roses",
"originalValue": "dozen roses",
"resolvedValues": []
}
},
"PickupDate": {
"value": {
"interpretedValue": "2021-01-04",
"originalValue": "next monday",
"resolvedValues": [
"2021-01-04"
]
}
},
"PickupTime": {
"value": {
"interpretedValue": "17:00",
"originalValue": "5 evening",
"resolvedValues": [
"17:00"
]
}
}
},
"state": "Fulfilled"
},
"originatingRequestId": "9e8add70-4106-4a10-93f5-2ce2cb959e5f"
}
}