PutSession - Amazon Lex API Reference

PutSession

Creates a new session or modifies an existing session with an Amazon Lex V2 bot. Use this operation to enable your application to set the state of the bot.

Request Syntax

POST /bots/botId/botAliases/botAliasId/botLocales/localeId/sessions/sessionId HTTP/1.1 ResponseContentType: responseContentType Content-type: application/json { "messages": [ { "content": "string", "contentType": "string", "imageResponseCard": { "buttons": [ { "text": "string", "value": "string" } ], "imageUrl": "string", "subtitle": "string", "title": "string" } } ], "requestAttributes": { "string" : "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" } } }

URI Request Parameters

The request uses the following URI parameters.

botAliasId

The alias identifier of the bot that receives the session data.

Required: Yes

botId

The identifier of the bot that receives the session data.

Length Constraints: Fixed length of 10.

Pattern: ^[0-9a-zA-Z]+$

Required: Yes

localeId

The locale where the session is in use.

Length Constraints: Minimum length of 1.

Required: Yes

responseContentType

The message that Amazon Lex V2 returns in the response can be either text or speech depending on the value of this parameter.

  • If the value is text/plain; charset=utf-8, Amazon Lex V2 returns text in the response.

Length Constraints: Minimum length of 1.

sessionId

The identifier of the session that receives the session data.

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.

messages

A list of messages to send to the user. Messages are sent in the order that they are defined in the list.

Type: Array of Message objects

Array Members: Maximum number of 10 items.

Required: No

requestAttributes

Request-specific information passed between Amazon Lex V2 and the client application.

The namespace x-amz-lex: is reserved for special attributes. Don't create any request attributes with the prefix x-amz-lex:.

Type: String to string map

Key Length Constraints: Minimum length of 1.

Required: No

sessionState

Sets the state of the session with the user. You can use this to set the current intent, attributes, context, and dialog action. Use the dialog action to determine the next step that Amazon Lex V2 should use in the conversation with the user.

Type: SessionState object

Required: Yes

Response Syntax

HTTP/1.1 200 Content-Type: contentType x-amz-lex-messages: messages x-amz-lex-session-state: sessionState x-amz-lex-request-attributes: requestAttributes x-amz-lex-session-id: sessionId audioStream

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The response returns the following HTTP headers.

contentType

The type of response. Same as the type specified in the responseContentType field in the request.

Length Constraints: Minimum length of 1.

messages

A list of messages that were last sent to the user. The messages are ordered based on how you return the messages from you Lambda function or the order that the messages are defined in the bot.

Length Constraints: Minimum length of 1.

requestAttributes

A base-64-encoded gzipped field that provides request-specific information passed between the client application and Amazon Lex V2. These are the same as the requestAttribute parameter in the call to the PutSession operation.

Length Constraints: Minimum length of 1.

sessionId

The identifier of the session that received the data.

Length Constraints: Minimum length of 2. Maximum length of 100.

Pattern: [0-9a-zA-Z._:-]+

sessionState

A base-64-encoded gzipped field that represents the current state of the dialog between the user and the bot. Use this to determine the progress of the conversation and what the next action may be.

Length Constraints: Minimum length of 1.

The response returns the following as the HTTP body.

audioStream

If the requested content type was audio, the audio version of the message to convey to the user.

Errors

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

AccessDeniedException

HTTP Status Code: 403

BadGatewayException

HTTP Status Code: 502

ConflictException

HTTP Status Code: 409

DependencyFailedException

HTTP Status Code: 424

InternalServerException

HTTP Status Code: 500

ResourceNotFoundException

HTTP Status Code: 404

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: