Skip to content

put_session

put_session(
    bot_id: BotIdentifier,
    bot_alias_id: BotAliasIdentifier,
    locale_id: LocaleId,
    session_id: SessionId,
    session_state: SessionState,
    *,
    config_overrides: Optional[LexRuntimeV2ClientConfig] = None,
    messages: Optional[Messages] = None,
    request_attributes: Optional[StringMap] = None,
    response_content_type: Optional[NonEmptyString] = None,
) -> Generator[PutSessionResponse]

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.

Parameters:

  • bot_id (BotIdentifier) –

    The identifier of the bot that receives the session data.

  • bot_alias_id (BotAliasIdentifier) –

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

  • locale_id (LocaleId) –

    The locale where the session is in use.

  • session_id (SessionId) –

    The identifier of the session that receives the session data.

  • messages (Optional[Messages], default: None ) –

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

  • session_state (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.

  • request_attributes (Optional[StringMap], default: None ) –

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

  • response_content_type (Optional[NonEmptyString], default: None ) –

    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.

Raises:

Source code in docs_src/capo_lex_runtime_v2/_services/lex_runtime_v2.py
@contextmanager
def put_session(
    self,
    bot_id: "capo_lex_runtime_v2.types.bot_identifier.BotIdentifier",
    bot_alias_id: "capo_lex_runtime_v2.types.bot_alias_identifier.BotAliasIdentifier",
    locale_id: "capo_lex_runtime_v2.types.locale_id.LocaleId",
    session_id: "capo_lex_runtime_v2.types.session_id.SessionId",
    session_state: "capo_lex_runtime_v2.types.session_state.SessionState",
    *,
    config_overrides: Optional[LexRuntimeV2ClientConfig] = None,
    messages: Optional["capo_lex_runtime_v2.types.messages.Messages"] = None,
    request_attributes: Optional[
        "capo_lex_runtime_v2.types.string_map.StringMap"
    ] = None,
    response_content_type: Optional[
        "capo_lex_runtime_v2.types.non_empty_string.NonEmptyString"
    ] = None,
) -> "Generator[capo_lex_runtime_v2.types.put_session_response.PutSessionResponse]":
    """<p>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.</p>

    Args:
        bot_id: <p>The identifier of the bot that receives the session data.</p>
        bot_alias_id: <p>The alias identifier of the bot that receives the session data.</p>
        locale_id: <p>The locale where the session is in use.</p>
        session_id: <p>The identifier of the session that receives the session data.</p>
        messages: <p>A list of messages to send to the user. Messages are sent in the order that they are defined in the list.</p>
        session_state: <p>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.</p>
        request_attributes: <p>Request-specific information passed between Amazon Lex V2 and the client application.</p> <p>The namespace <code>x-amz-lex:</code> is reserved for special attributes. Don't create any request attributes with the prefix <code>x-amz-lex:</code>.</p>
        response_content_type: <p>The message that Amazon Lex V2 returns in the response can be either text or speech depending on the value of this parameter. </p> <ul> <li> <p>If the value is <code>text/plain; charset=utf-8</code>, Amazon Lex V2 returns text in the response.</p> </li> </ul>

    Raises:
        capo_lex_runtime_v2.errors.access_denied_exception.AccessDeniedException: <p></p>
        capo_lex_runtime_v2.errors.bad_gateway_exception.BadGatewayException: <p></p>
        capo_lex_runtime_v2.errors.conflict_exception.ConflictException: <p></p>
        capo_lex_runtime_v2.errors.dependency_failed_exception.DependencyFailedException: <p></p>
        capo_lex_runtime_v2.errors.internal_server_exception.InternalServerException: <p></p>
        capo_lex_runtime_v2.errors.resource_not_found_exception.ResourceNotFoundException: <p></p>
        capo_lex_runtime_v2.errors.throttling_exception.ThrottlingException: <p></p>
        capo_lex_runtime_v2.errors.validation_exception.ValidationException: <p></p>
        capo_lex_runtime_v2.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_lex_runtime_v2.types.put_session_request.PutSessionRequest]",
    ) -> OperationResponse[
        "capo_lex_runtime_v2.types.put_session_response.PutSessionResponse"
    ]:
        import capo_lex_runtime_v2._operations.aws_deep_sense_run_time_service_api2_0.put_session

        output, http_response = (
            capo_lex_runtime_v2._operations.aws_deep_sense_run_time_service_api2_0.put_session.put_session(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_lex_runtime_v2.types.put_session_request.PutSessionRequest",
    ) -> dict[str, Any]:
        import capo_lex_runtime_v2.types.put_session_request

        return capo_lex_runtime_v2.types.put_session_request.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_lex_runtime_v2.types.put_session_response.PutSessionResponse",
    ) -> dict[str, Any]:
        import capo_lex_runtime_v2.types.put_session_response

        return capo_lex_runtime_v2.types.put_session_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "PutSession", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_lex_runtime_v2.types.put_session_request.PutSessionRequest = {
        "bot_id": bot_id,
        "bot_alias_id": bot_alias_id,
        "locale_id": locale_id,
        "session_id": session_id,
        "session_state": session_state,
    }
    if messages is not None:
        input_["messages"] = messages
    if request_attributes is not None:
        input_["request_attributes"] = request_attributes
    if response_content_type is not None:
        input_["response_content_type"] = response_content_type

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    try:
        yield response.output
    finally:
        response.response.close()