putSession method

Future<PutSessionResponse> putSession({
  1. required String botAliasId,
  2. required String botId,
  3. required String localeId,
  4. required String sessionId,
  5. required SessionState sessionState,
  6. List<Message>? messages,
  7. Map<String, String>? requestAttributes,
  8. String? responseContentType,
})

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.

May throw AccessDeniedException. May throw BadGatewayException. May throw ConflictException. May throw DependencyFailedException. May throw InternalServerException. May throw ResourceNotFoundException. May throw ThrottlingException. May throw ValidationException.

Parameter botAliasId : The alias identifier of the bot that receives the session data.

Parameter botId : The identifier of the bot that receives the session data.

Parameter localeId : The locale where the session is in use.

Parameter sessionId : The identifier of the session that receives the session data.

Parameter 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.

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

Parameter 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:.

Parameter 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.

Implementation

Future<PutSessionResponse> putSession({
  required String botAliasId,
  required String botId,
  required String localeId,
  required String sessionId,
  required SessionState sessionState,
  List<Message>? messages,
  Map<String, String>? requestAttributes,
  String? responseContentType,
}) async {
  final headers = <String, String>{
    if (responseContentType != null)
      'ResponseContentType': responseContentType.toString(),
  };
  final $payload = <String, dynamic>{
    'sessionState': sessionState,
    if (messages != null) 'messages': messages,
    if (requestAttributes != null) 'requestAttributes': requestAttributes,
  };
  final response = await _protocol.sendRaw(
    payload: $payload,
    method: 'POST',
    requestUri:
        '/bots/${Uri.encodeComponent(botId)}/botAliases/${Uri.encodeComponent(botAliasId)}/botLocales/${Uri.encodeComponent(localeId)}/sessions/${Uri.encodeComponent(sessionId)}',
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
  return PutSessionResponse(
    audioStream: await response.stream.toBytes(),
    contentType:
        _s.extractHeaderStringValue(response.headers, 'Content-Type'),
    messages:
        _s.extractHeaderStringValue(response.headers, 'x-amz-lex-messages'),
    requestAttributes: _s.extractHeaderStringValue(
        response.headers, 'x-amz-lex-request-attributes'),
    sessionId:
        _s.extractHeaderStringValue(response.headers, 'x-amz-lex-session-id'),
    sessionState: _s.extractHeaderStringValue(
        response.headers, 'x-amz-lex-session-state'),
  );
}