StartConversation - Amazon Lex

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 V2 as a stream of events. Amazon Lex V2 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/2 x-amz-lex-conversation-mode: conversationMode Content-type: application/json { "requestEventStream": { "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": { "slotToElicit": "string", "type": "string" }, "intent": { "confirmationState": "string", "name": "string", "slots": { "string" : { "shape": "string", "value": { "interpretedValue": "string", "originalValue": "string", "resolvedValues": [ "string" ] }, "values": [ "Slot" ] } }, "state": "string" }, "originatingRequestId": "string", "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 V2. If the conversation mode is AUDIO you can send both audio and DTMF information. If the mode is TEXT you 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.

requestEventStream

Represents the stream of events to Amazon Lex V2 from your application. The events are encoded as HTTP/2 data frames.

Type: StartConversationRequestEventStream object

Required: Yes

Response Syntax

HTTP/2 200 Content-type: application/json { "responseEventStream": { "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", "value": { "interpretedValue": "string", "originalValue": "string", "resolvedValues": [ "string" ] }, "values": [ "Slot" ] } }, "state": "string" }, "nluConfidence": { "score": number }, "sentimentResponse": { "sentiment": "string", "sentimentScore": { "mixed": number, "negative": number, "neutral": number, "positive": number } } } ], "requestAttributes": { "string" : "string" }, "sessionId": "string", "sessionState": { "activeContexts": [ { "contextAttributes": { "string" : "string" }, "name": "string", "timeToLive": { "timeToLiveInSeconds": number, "turnsToLive": number } } ], "dialogAction": { "slotToElicit": "string", "type": "string" }, "intent": { "confirmationState": "string", "name": "string", "slots": { "string" : { "shape": "string", "value": { "interpretedValue": "string", "originalValue": "string", "resolvedValues": [ "string" ] }, "values": [ "Slot" ] } }, "state": "string" }, "originatingRequestId": "string", "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.

responseEventStream

Represents the stream of events from Amazon Lex V2 to your application. The events are encoded as HTTP/2 data frames.

Type: StartConversationResponseEventStream object

Errors

For information about the errors that are common to all actions, see Common Errors.

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: