This section describes the structure of the event data that Amazon Lex provides to a Lambda function.
Use this information to parse the input in your Lambda code. It also explains the format of the response that Amazon Lex expects your Lambda function to return.
Topics
• Input Event Format (p. 139)
• Response Format (p. 144)
Input Event Format
The following shows the general format of an Amazon Lex event that is passed to a Lambda function.
Use this information when you are writing your Lambda function.
NoteThe input format may change without a corresponding change in the messageVersion. Your code should not throw an error if new fields are present.
{ "currentIntent": { "name": "intent-name",
"nluIntentConfidenceScore": score, "slots": {
"slot name": "value", "slot name": "value"
},
"slotDetails": { "slot name": { "resolutions" : [
{ "value": "resolved value" }, { "value": "resolved value" } ],
"originalValue": "original text"
},
"slot name": { "resolutions" : [
{ "value": "resolved value" },
{ "value": "resolved value" } ],
"originalValue": "original text"
} },
"confirmationStatus": "None, Confirmed, or Denied (intent confirmation, if configured)"
}, "alternativeIntents": [ {
"name": "intent-name",
"nluIntentConfidenceScore": score, "slots": {
"confirmationStatus": "None, Confirmed, or Denied (intent confirmation, if configured)"
} ], "bot": {
"name": "bot name", "alias": "bot alias", "version": "bot version"
}, "userId": "User ID specified in the POST request to Amazon Lex.", "inputTranscript": "Text used to process the request",
"invocationSource": "FulfillmentCodeHook or DialogCodeHook",
"outputDialogMode": "Text or Voice, based on ContentType request header in runtime API request",
"confirmationStatus": "None, Confirmed, or Denied (intent confirmation, if configured)",
"dialogActionType": "ElicitIntent, ElicitSlot, ConfirmIntent, Delegate, or Close", "fulfillmentState": "Fulfilled or Failed",
"slotToElicit": "Next slot to elicit"
}
], "sentimentResponse": {
"sentimentLabel": "sentiment", "sentimentScore": "score"
},
Note the following additional information about the event fields:
• currentIntent – Provides the intent name, slots, slotDetails and confirmationStatus fields.
nluIntentConfidenceScore is the confidence that Amazon Lex has that the current intent is the one that best matches the user's current intent.
slots is a map of slot names, configured for the intent, to slot values that Amazon Lex has recognized in the user conversation. A slot value remains null until the user provides a value.
The slot value in the input event may not match one of the values configured for the slot. For example, if the user responds to the prompt "What color car would you like?" with "pizza," Amazon Lex will return "pizza" as the slot value. Your function should validate the values to make sure that they make sense in context.
slotDetails provides additional information about a slot value. The resolutions array contains a list of additional values recognized for the slot. Each slot can have a maximum of five values.
The originalValue field contains the value that was entered by the user for the slot. When the slot type is configured to return the top resolution value as the slot value, the originalValue may be different from the value in the slots field.
confirmationStatus provides the user response to a confirmation prompt, if there is one. For example, if Amazon Lex asks "Do you want to order a large cheese pizza?," depending on the user response, the value of this field can be Confirmed or Denied. Otherwise, this value of this field is
If the user confirms the intent, Amazon Lex sets this field to Confirmed. If the user denies the intent, Amazon Lex sets this value to Denied.
In the confirmation response, a user utterance might provide slot updates. For example, the user might say "yes, change size to medium." In this case, the subsequent Lambda event has the updated slot value, PizzaSize set to medium. Amazon Lex sets the confirmationStatus to None, because the user modified some slot data, requiring the Lambda function to perform user data validation.
• alternativeIntents – If you enable confidence scores, Amazon Lex returns up to four alternative intents. Each intent includes a score that indicates the level of confidence that Amazon Lex has that the intent is the correct intent based on the user's utterance.
The contents of the alternative intents is the same as the contents of the currentIntent field. For more information, see Using Confidence Scores (p. 28).
• bot – Information about the bot that processed the request.
• name – The name of the bot that processed the request.
• alias – The alias of the bot version that processed the request.
• version – The version of the bot that processed the request.
• userId – This value is provided by the client application. Amazon Lex passes it to the Lambda function.
• inputTranscript – The text used to process the request.
If the input was text, the inputTranscript field contains the text that was input by the user.
If the input was an audio stream, the inputTranscript field contains the text extracted from the audio stream. This is the text that is actually processed to recognize intents and slot values.
• invocationSource – To indicate why Amazon Lex is invoking the Lambda function, it sets this to one of the following values:
• DialogCodeHook – Amazon Lex sets this value to direct the Lambda function to initialize the function and to validate the user's data input.
When the intent is configured to invoke a Lambda function as an initialization and validation code hook, Amazon Lex invokes the specified Lambda function on each user input (utterance) after Amazon Lex understands the intent.
NoteIf the intent is not clear, Amazon Lex can't invoke the Lambda function.
• FulfillmentCodeHook – Amazon Lex sets this value to direct the Lambda function to fulfill an intent.
If the intent is configured to invoke a Lambda function as a fulfillment code hook, Amazon Lex sets the invocationSource to this value only after it has all the slot data to fulfill the intent.
In your intent configuration, you can have two separate Lambda functions to initialize and validate user data and to fulfill the intent. You can also use one Lambda function to do both. In that case, your Lambda function can use the invocationSource value to follow the correct code path.
• outputDialogMode – For each user input, the client sends the request to Amazon Lex using one of the runtime API operations, PostContent (p. 434) or PostText (p. 444). Amazon Lex uses the request parameters to determine whether the response to the client is text or voice, and sets this field accordingly.
The Lambda function can use this information to generate an appropriate message. For example, if the client expects a voice response, your Lambda function could return Speech Synthesis Markup Language (SSML) instead of text.
• messageVersion – The version of the message that identifies the format of the event data going into the Lambda function and the expected format of the response from a Lambda function.
NoteYou configure this value when you define an intent. In the current implementation, only message version 1.0 is supported. Therefore, the console assumes the default value of 1.0 and doesn't show the message version.
• sessionAttributes – Application-specific session attributes that the client sends in the request. If you want Amazon Lex to include them in the response to the client, your Lambda function should send these back to Amazon Lex in the response. For more information, see Setting Session Attributes (p. 23)
• requestAttributes – Request-specific attributes that the client sends in the request. Use request attributes to pass information that doesn't need to persist for the entire session. If there are no request attributes, the value will be null. For more information, see Setting Request Attributes (p. 24)
• recentIntentSummaryView – Information about the state of an intent. You can see information about the last three intents used. You can use this information to set values in the intent or to return to a previous intent. For more information, see Managing Sessions With the Amazon Lex API (p. 39).
• sentimentResponse – The result of an Amazon Comprehend sentiment analysis of the last utterance.
You can use this information to manage the conversation flow of your bot depending on the sentiment expressed by the user. For more information, see Sentiment Analysis (p. 63).
• kendraResponse – The result of a query to an Amazon Kendra index. Only present in the input to a
intent. The field contains the entire response from the Amazon Kendra search. For more information, see AMAZON.KendraSearchIntent (p. 46).
• activeContexts – One or more contexts that are active during this turn of a conversation with the user.
• timeToLive – The length of time or number of turns in the conversation with the user that the context remains active.
• name – the name of the context.
• parameters a list of key/value pairs the contains the name and value of the slots from the intent that activated the context.
For more information, see Setting Intent Context (p. 20).