Skip to content

put_session

put_session(
    bot_name: BotName,
    bot_alias: BotAlias,
    user_id: UserId,
    *,
    config_overrides: Optional[LexRuntimeServiceClientConfig] = None,
    session_attributes: Optional[StringMap] = None,
    dialog_action: Optional[DialogAction] = None,
    recent_intent_summary_view: Optional[IntentSummaryList] = None,
    accept: Optional[Accept] = None,
    active_contexts: Optional[ActiveContextsList] = None,
) -> Generator[PutSessionResponse]

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

For more information, see Managing Sessions.

Parameters:

  • bot_name (BotName) –

    The name of the bot that contains the session data.

  • bot_alias (BotAlias) –

    The alias in use for the bot that contains the session data.

  • user_id (UserId) –

    The ID of the client application user. Amazon Lex uses this to identify a user's conversation with your bot.

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

    Map of key/value pairs representing the session-specific context information. It contains application information passed between Amazon Lex and a client application.

  • dialog_action (Optional[DialogAction], default: None ) –

    Sets the next action that the bot should take to fulfill the conversation.

  • recent_intent_summary_view (Optional[IntentSummaryList], default: None ) –

    A summary of the recent intents for the bot. You can use the intent summary view to set a checkpoint label on an intent and modify attributes of intents. You can also use it to remove or add intent summary objects to the list.

    An intent that you modify or add to the list must make sense for the bot. For example, the intent name must be valid for the bot. You must provide valid values for:

    • intentName

    • slot names

    • slotToElict

    If you send the recentIntentSummaryView parameter in a PutSession request, the contents of the new summary view replaces the old summary view. For example, if a GetSession request returns three intents in the summary view and you call PutSession with one intent in the summary view, the next call to GetSession will only return one intent.

  • accept (Optional[Accept], default: None ) –

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

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

    • If the value begins with audio/, Amazon Lex returns speech in the response. Amazon Lex uses Amazon Polly to generate the speech in the configuration that you specify. For example, if you specify audio/mpeg as the value, Amazon Lex returns speech in the MPEG format.

    • If the value is audio/pcm, the speech is returned as audio/pcm in 16-bit, little endian format.

    • The following are the accepted values:

      • audio/mpeg

      • audio/ogg

      • audio/pcm

      • audio/* (defaults to mpeg)

      • text/plain; charset=utf-8

  • active_contexts (Optional[ActiveContextsList], default: None ) –

    A list of contexts active for the request. A context can be activated when a previous intent is fulfilled, or by including the context in the request,

    If you don't specify a list of contexts, Amazon Lex will use the current list of contexts for the session. If you specify an empty list, all contexts for the session are cleared.

Raises:

  • BadGatewayException –

    Either the Amazon Lex bot is still building, or one of the dependent services (Amazon Polly, AWS Lambda) failed with an internal service error.

  • BadRequestException –

    Request validation failed, there is no usable message in the context, or the bot build failed, is still in progress, or contains unbuilt changes.

  • ConflictException –

    Two clients are using the same AWS account, Amazon Lex bot, and user ID.

  • DependencyFailedException –

    One of the dependencies, such as AWS Lambda or Amazon Polly, threw an exception. For example,

    • If Amazon Lex does not have sufficient permissions to call a Lambda function.

    • If a Lambda function takes longer than 30 seconds to execute.

    • If a fulfillment Lambda function returns a Delegate dialog action without removing any slot values.

  • InternalFailureException –

    Internal service error. Retry the call.

  • LimitExceededException –

    Exceeded a limit.

  • NotAcceptableException –

    The accept header in the request does not have a valid value.

  • NotFoundException –

    The resource (such as the Amazon Lex bot or an alias) that is referred to is not found.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_lex_runtime_service/_services/lex_runtime_service.py
@contextmanager
def put_session(
    self,
    bot_name: "capo_lex_runtime_service.types.bot_name.BotName",
    bot_alias: "capo_lex_runtime_service.types.bot_alias.BotAlias",
    user_id: "capo_lex_runtime_service.types.user_id.UserId",
    *,
    config_overrides: Optional[LexRuntimeServiceClientConfig] = None,
    session_attributes: Optional[
        "capo_lex_runtime_service.types.string_map.StringMap"
    ] = None,
    dialog_action: Optional[
        "capo_lex_runtime_service.types.dialog_action.DialogAction"
    ] = None,
    recent_intent_summary_view: Optional[
        "capo_lex_runtime_service.types.intent_summary_list.IntentSummaryList"
    ] = None,
    accept: Optional["capo_lex_runtime_service.types.accept.Accept"] = None,
    active_contexts: Optional[
        "capo_lex_runtime_service.types.active_contexts_list.ActiveContextsList"
    ] = None,
) -> "Generator[capo_lex_runtime_service.types.put_session_response.PutSessionResponse]":
    """<p>Creates a new session or modifies an existing session with an Amazon Lex bot. Use this operation to enable your application to set the state of the bot.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/lex/latest/dg/how-session-api.html">Managing Sessions</a>.</p>

    Args:
        bot_name: <p>The name of the bot that contains the session data.</p>
        bot_alias: <p>The alias in use for the bot that contains the session data.</p>
        user_id: <p>The ID of the client application user. Amazon Lex uses this to identify a user's conversation with your bot. </p>
        session_attributes: <p>Map of key/value pairs representing the session-specific context information. It contains application information passed between Amazon Lex and a client application.</p>
        dialog_action: <p>Sets the next action that the bot should take to fulfill the conversation.</p>
        recent_intent_summary_view: <p>A summary of the recent intents for the bot. You can use the intent summary view to set a checkpoint label on an intent and modify attributes of intents. You can also use it to remove or add intent summary objects to the list.</p> <p>An intent that you modify or add to the list must make sense for the bot. For example, the intent name must be valid for the bot. You must provide valid values for:</p> <ul> <li> <p> <code>intentName</code> </p> </li> <li> <p>slot names</p> </li> <li> <p> <code>slotToElict</code> </p> </li> </ul> <p>If you send the <code>recentIntentSummaryView</code> parameter in a <code>PutSession</code> request, the contents of the new summary view replaces the old summary view. For example, if a <code>GetSession</code> request returns three intents in the summary view and you call <code>PutSession</code> with one intent in the summary view, the next call to <code>GetSession</code> will only return one intent.</p>
        accept: <p>The message that Amazon Lex returns in the response can be either text or speech based depending on the value of this field.</p> <ul> <li> <p>If the value is <code>text/plain; charset=utf-8</code>, Amazon Lex returns text in the response.</p> </li> <li> <p>If the value begins with <code>audio/</code>, Amazon Lex returns speech in the response. Amazon Lex uses Amazon Polly to generate the speech in the configuration that you specify. For example, if you specify <code>audio/mpeg</code> as the value, Amazon Lex returns speech in the MPEG format.</p> </li> <li> <p>If the value is <code>audio/pcm</code>, the speech is returned as <code>audio/pcm</code> in 16-bit, little endian format.</p> </li> <li> <p>The following are the accepted values:</p> <ul> <li> <p> <code>audio/mpeg</code> </p> </li> <li> <p> <code>audio/ogg</code> </p> </li> <li> <p> <code>audio/pcm</code> </p> </li> <li> <p> <code>audio/*</code> (defaults to mpeg)</p> </li> <li> <p> <code>text/plain; charset=utf-8</code> </p> </li> </ul> </li> </ul>
        active_contexts: <p>A list of contexts active for the request. A context can be activated when a previous intent is fulfilled, or by including the context in the request,</p> <p>If you don't specify a list of contexts, Amazon Lex will use the current list of contexts for the session. If you specify an empty list, all contexts for the session are cleared.</p>

    Raises:
        capo_lex_runtime_service.errors.bad_gateway_exception.BadGatewayException: <p>Either the Amazon Lex bot is still building, or one of the dependent services (Amazon Polly, AWS Lambda) failed with an internal service error.</p>
        capo_lex_runtime_service.errors.bad_request_exception.BadRequestException: <p> Request validation failed, there is no usable message in the context, or the bot build failed, is still in progress, or contains unbuilt changes. </p>
        capo_lex_runtime_service.errors.conflict_exception.ConflictException: <p> Two clients are using the same AWS account, Amazon Lex bot, and user ID. </p>
        capo_lex_runtime_service.errors.dependency_failed_exception.DependencyFailedException: <p> One of the dependencies, such as AWS Lambda or Amazon Polly, threw an exception. For example, </p> <ul> <li> <p>If Amazon Lex does not have sufficient permissions to call a Lambda function.</p> </li> <li> <p>If a Lambda function takes longer than 30 seconds to execute.</p> </li> <li> <p>If a fulfillment Lambda function returns a <code>Delegate</code> dialog action without removing any slot values.</p> </li> </ul>
        capo_lex_runtime_service.errors.internal_failure_exception.InternalFailureException: <p>Internal service error. Retry the call.</p>
        capo_lex_runtime_service.errors.limit_exceeded_exception.LimitExceededException: <p>Exceeded a limit.</p>
        capo_lex_runtime_service.errors.not_acceptable_exception.NotAcceptableException: <p>The accept header in the request does not have a valid value.</p>
        capo_lex_runtime_service.errors.not_found_exception.NotFoundException: <p>The resource (such as the Amazon Lex bot or an alias) that is referred to is not found.</p>
        capo_lex_runtime_service.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

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

        output, http_response = (
            capo_lex_runtime_service._operations.aws_deep_sense_run_time_service.put_session.put_session(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

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

        return capo_lex_runtime_service.types.put_session_request.redact_sensitive(
            input_
        )

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

        return capo_lex_runtime_service.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_service.types.put_session_request.PutSessionRequest = {
        "bot_name": bot_name,
        "bot_alias": bot_alias,
        "user_id": user_id,
    }
    if session_attributes is not None:
        input_["session_attributes"] = session_attributes
    if dialog_action is not None:
        input_["dialog_action"] = dialog_action
    if recent_intent_summary_view is not None:
        input_["recent_intent_summary_view"] = recent_intent_summary_view
    if accept is not None:
        input_["accept"] = accept
    if active_contexts is not None:
        input_["active_contexts"] = active_contexts

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