StartConversation
Starts an HTTP/2 bidirectional event stream that enables you to send audio, text, or DTMF input in real time. After your application starts a conversation, users send input to Amazon Lex as a stream of events. Amazon Lex processes the incoming events and responds with streaming text or audio events.
Audio input must be in the following format: audio/lpcm
sample-rate=8000 sample-size-bits=16 channel-count=1;
is-big-endian=false.
If the optional post-fulfillment response is specified, the messages are returned as follows. For more information, see PostFulfillmentStatusSpecification.
-
Success message - Returned if the Lambda function completes successfully and the intent state is fulfilled or ready fulfillment if the message is present.
-
Failed message - The failed message is returned if the Lambda function throws an exception or if the Lambda function returns a failed intent state without a message.
-
Timeout message - If you don't configure a timeout message and a timeout, and the Lambda function doesn't return within 30 seconds, the timeout message is returned. If you configure a timeout, the timeout message is returned when the period times out.
For more information, see Completion message.
If the optional update message is configured, it is played at the specified frequency while the Lambda function is running and the update message state is active. If the fulfillment update message is not active, the Lambda function runs with a 30 second timeout.
For more information, see Update message
The StartConversation operation is supported only in
the following SDKs:
Request Syntax
POST /bots/botId/botAliases/botAliasId/botLocales/localeId/sessions/sessionId/conversation HTTP/1.1
x-amz-lex-conversation-mode: conversationMode
Content-type: application/json
{
"AudioInputEvent": {
"audioChunk": blob,
"clientTimestampMillis": number,
"contentType": "string",
"eventId": "string"
},
"ConfigurationEvent": {
"clientTimestampMillis": number,
"disablePlayback": boolean,
"eventId": "string",
"requestAttributes": {
"string" : "string"
},
"responseContentType": "string",
"sessionState": {
"activeContexts": [
{
"contextAttributes": {
"string" : "string"
},
"name": "string",
"timeToLive": {
"timeToLiveInSeconds": number,
"turnsToLive": number
}
}
],
"dialogAction": {
"slotElicitationStyle": "string",
"slotToElicit": "string",
"subSlotToElicit": {
"name": "string",
"subSlotToElicit": "ElicitSubSlot"
},
"type": "string"
},
"intent": {
"confirmationState": "string",
"name": "string",
"slots": {
"string" : {
"shape": "string",
"subSlots": {
"string" : "Slot"
},
"value": {
"interpretedValue": "string",
"originalValue": "string",
"resolvedValues": [ "string" ]
},
"values": [
"Slot"
]
}
},
"state": "string"
},
"originatingRequestId": "string",
"runtimeHints": {
"slotHints": {
"string" : {
"string" : {
"runtimeHintValues": [
{
"phrase": "string"
}
],
"subSlotHints": {
"string" : "RuntimeHintDetails"
}
}
}
}
},
"sessionAttributes": {
"string" : "string"
}
},
"welcomeMessages": [
{
"content": "string",
"contentType": "string",
"imageResponseCard": {
"buttons": [
{
"text": "string",
"value": "string"
}
],
"imageUrl": "string",
"subtitle": "string",
"title": "string"
}
}
]
},
"DisconnectionEvent": {
"clientTimestampMillis": number,
"eventId": "string"
},
"DTMFInputEvent": {
"clientTimestampMillis": number,
"eventId": "string",
"inputCharacter": "string"
},
"PlaybackCompletionEvent": {
"clientTimestampMillis": number,
"eventId": "string"
},
"TextInputEvent": {
"clientTimestampMillis": number,
"eventId": "string",
"text": "string"
}
}
URI Request Parameters
The request uses the following URI parameters.
- botAliasId
-
The alias identifier in use for the bot that processes the request.
Required: Yes
- botId
-
The identifier of the bot to process the request.
Length Constraints: Fixed length of 10.
Pattern:
^[0-9a-zA-Z]+$Required: Yes
- conversationMode
-
The conversation type that you are using the Amazon Lex. If the conversation mode is
AUDIOyou can send both audio and DTMF information. If the mode isTEXTyou can only send text.Valid Values:
AUDIO | TEXT - localeId
-
The locale where the session is in use.
Length Constraints: Minimum length of 1.
Required: Yes
- sessionId
-
The identifier of the user session that is having the conversation.
Length Constraints: Minimum length of 2. Maximum length of 100.
Pattern:
[0-9a-zA-Z._:-]+Required: Yes
Request Body
The request accepts the following data in JSON format.
- AudioInputEvent
-
Speech audio sent from your client application to Amazon Lex. Audio starts accumulating when Amazon Lex identifies a voice and continues until a natural pause in the speech is found before processing.
Type: AudioInputEvent object
Required: No
- ConfigurationEvent
-
Configuration information sent from your client application to Amazon Lex
Type: ConfigurationEvent object
Required: No
- DisconnectionEvent
-
Event sent from the client application to indicate to Amazon Lex that the conversation is over.
Type: DisconnectionEvent object
Required: No
- DTMFInputEvent
-
DTMF information sent to Amazon Lex by your application. Amazon Lex accumulates the DMTF information from when the user sends the first character and ends
-
when there's a pause longer that the value configured for the end timeout.
-
when there's a digit that is the configured end character.
-
when Amazon Lex accumulates characters equal to the maximum DTMF character configuration.
Type: DTMFInputEvent object
Required: No
-
- PlaybackCompletionEvent
-
Event sent from the client application to Amazon Lex to indicate that it has finished playing audio and that Amazon Lex should start listening for user input.
Type: PlaybackCompletionEvent object
Required: No
- TextInputEvent
-
Text sent from your client application to Amazon Lex. Each
TextInputEventis processed individually.Type: TextInputEvent object
Required: No
Response Syntax
HTTP/1.1 200
Content-type: application/json
{
"AccessDeniedException": {
},
"AudioResponseEvent": {
"audioChunk": blob,
"contentType": "string",
"eventId": "string"
},
"BadGatewayException": {
},
"ConflictException": {
},
"DependencyFailedException": {
},
"HeartbeatEvent": {
"eventId": "string"
},
"IntentResultEvent": {
"eventId": "string",
"inputMode": "string",
"interpretations": [
{
"intent": {
"confirmationState": "string",
"name": "string",
"slots": {
"string" : {
"shape": "string",
"subSlots": {
"string" : "Slot"
},
"value": {
"interpretedValue": "string",
"originalValue": "string",
"resolvedValues": [ "string" ]
},
"values": [
"Slot"
]
}
},
"state": "string"
},
"interpretationSource": "string",
"nluConfidence": {
"score": number
},
"sentimentResponse": {
"sentiment": "string",
"sentimentScore": {
"mixed": number,
"negative": number,
"neutral": number,
"positive": number
}
}
}
],
"recognizedBotMember": {
"botId": "string",
"botName": "string"
},
"requestAttributes": {
"string" : "string"
},
"sessionId": "string",
"sessionState": {
"activeContexts": [
{
"contextAttributes": {
"string" : "string"
},
"name": "string",
"timeToLive": {
"timeToLiveInSeconds": number,
"turnsToLive": number
}
}
],
"dialogAction": {
"slotElicitationStyle": "string",
"slotToElicit": "string",
"subSlotToElicit": {
"name": "string",
"subSlotToElicit": "ElicitSubSlot"
},
"type": "string"
},
"intent": {
"confirmationState": "string",
"name": "string",
"slots": {
"string" : {
"shape": "string",
"subSlots": {
"string" : "Slot"
},
"value": {
"interpretedValue": "string",
"originalValue": "string",
"resolvedValues": [ "string" ]
},
"values": [
"Slot"
]
}
},
"state": "string"
},
"originatingRequestId": "string",
"runtimeHints": {
"slotHints": {
"string" : {
"string" : {
"runtimeHintValues": [
{
"phrase": "string"
}
],
"subSlotHints": {
"string" : "RuntimeHintDetails"
}
}
}
}
},
"sessionAttributes": {
"string" : "string"
}
}
},
"InternalServerException": {
},
"PlaybackInterruptionEvent": {
"causedByEventId": "string",
"eventId": "string",
"eventReason": "string"
},
"ResourceNotFoundException": {
},
"TextResponseEvent": {
"eventId": "string",
"messages": [
{
"content": "string",
"contentType": "string",
"imageResponseCard": {
"buttons": [
{
"text": "string",
"value": "string"
}
],
"imageUrl": "string",
"subtitle": "string",
"title": "string"
}
}
]
},
"ThrottlingException": {
},
"TranscriptEvent": {
"eventId": "string",
"transcript": "string"
},
"ValidationException": {
}
}
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
- AccessDeniedException
-
Exception thrown when the credentials passed with the request are invalid or expired. Also thrown when the credentials in the request do not have permission to access the
StartConversationoperation.Type: Exception
HTTP Status Code: 403
- AudioResponseEvent
-
An event sent from Amazon Lex to your client application containing audio to play to the user.
Type: AudioResponseEvent object
- BadGatewayException
-
Type: Exception
HTTP Status Code: 502
- ConflictException
-
Exception thrown when two clients are using the same AWS account, Amazon Lex bot, and session ID.
Type: Exception
HTTP Status Code: 409
- DependencyFailedException
-
Type: Exception
HTTP Status Code: 424
- HeartbeatEvent
-
Event that Amazon Lex sends to indicate that the stream is still open between the client application and Amazon Lex
Type: HeartbeatEvent object
- IntentResultEvent
-
Event sent from Amazon Lex to the client application containing the current state of the conversation between the user and Amazon Lex.
Type: IntentResultEvent object
- InternalServerException
-
An error occurred with Amazon Lex.
Type: Exception
HTTP Status Code: 500
- PlaybackInterruptionEvent
-
Event sent from Amazon Lex to indicate to the client application should stop playback of audio. For example, if the client is playing a prompt that asks for the user's telephone number, the user might start to say the phone number before the prompt is complete. Amazon Lex sends this event to the client application to indicate that the user is responding and that Amazon Lex is processing their input.
Type: PlaybackInterruptionEvent object
- ResourceNotFoundException
-
Exception thrown if one of the input parameters points to a resource that does not exist. For example, if the bot ID specified does not exist.
Type: Exception
HTTP Status Code: 404
- TextResponseEvent
-
The event sent from Amazon Lex to your application with text to present to the user.
Type: TextResponseEvent object
- ThrottlingException
-
Exception thrown when your application exceeds the maximum number of concurrent requests.
Type: Exception
HTTP Status Code: 429
- TranscriptEvent
-
Event sent from Amazon Lex to your client application that contains a transcript of voice audio.
Type: TranscriptEvent object
- ValidationException
-
Exception thrown when one or more parameters could not be validated. The
messagecontains the name of the field that isn't valid.Type: Exception
HTTP Status Code: 400
Errors
For information about the errors that are common to all actions, see Common Error Types.
- AccessDeniedException
-
HTTP Status Code: 403
- InternalServerException
-
HTTP Status Code: 500
- ThrottlingException
-
HTTP Status Code: 429
- ValidationException
-
HTTP Status Code: 400
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: