Skip to content

post_text

post_text(
    bot_name: BotName,
    bot_alias: BotAlias,
    user_id: UserId,
    input_text: Text,
    *,
    config_overrides: Optional[LexRuntimeServiceClientConfig] = None,
    session_attributes: Optional[StringMap] = None,
    request_attributes: Optional[StringMap] = None,
    active_contexts: Optional[ActiveContextsList] = None,
) -> PostTextResponse

Sends user input to Amazon Lex. Client applications can use this API to send requests to Amazon Lex at runtime. Amazon Lex then interprets the user input using the machine learning model it built for the bot.

In response, Amazon Lex returns the next message to convey to the user an optional responseCard to display. Consider the following example messages:

  • For a user input "I would like a pizza", Amazon Lex might return a response with a message eliciting slot data (for example, PizzaSize): "What size pizza would you like?"

  • After the user provides all of the pizza order information, Amazon Lex might return a response with a message to obtain user confirmation "Proceed with the pizza order?".

  • After the user replies to a confirmation prompt with a "yes", Amazon Lex might return a conclusion statement: "Thank you, your cheese pizza has been ordered.".

Not all Amazon Lex messages require a user response. For example, a conclusion statement does not require a response. Some messages require only a "yes" or "no" user response. In addition to the message, Amazon Lex provides additional context about the message in the response that you might use to enhance client behavior, for example, to display the appropriate client user interface. These are the slotToElicit, dialogState, intentName, and slots fields in the response. Consider the following examples:

  • If the message is to elicit slot data, Amazon Lex returns the following context information:

    • dialogState set to ElicitSlot

    • intentName set to the intent name in the current context

    • slotToElicit set to the slot name for which the message is eliciting information

    • slots set to a map of slots, configured for the intent, with currently known values

  • If the message is a confirmation prompt, the dialogState is set to ConfirmIntent and SlotToElicit is set to null.

  • If the message is a clarification prompt (configured for the intent) that indicates that user intent is not understood, the dialogState is set to ElicitIntent and slotToElicit is set to null.

In addition, Amazon Lex also returns your application-specific sessionAttributes. For more information, see Managing Conversation Context.

Parameters:

  • bot_name (BotName) –

    The name of the Amazon Lex bot.

  • bot_alias (BotAlias) –

    The alias of the Amazon Lex bot.

  • user_id (UserId) –

    The ID of the client application user. Amazon Lex uses this to identify a user's conversation with your bot. At runtime, each request must contain the userID field.

    To decide the user ID to use for your application, consider the following factors.

    • The userID field must not contain any personally identifiable information of the user, for example, name, personal identification numbers, or other end user personal information.

    • If you want a user to start a conversation on one device and continue on another device, use a user-specific identifier.

    • If you want the same user to be able to have two independent conversations on two different devices, choose a device-specific identifier.

    • A user can't have two independent conversations with two different versions of the same bot. For example, a user can't have a conversation with the PROD and BETA versions of the same bot. If you anticipate that a user will need to have conversation with two different versions, for example, while testing, include the bot alias in the user ID to separate the two conversations.

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

    Application-specific information passed between Amazon Lex and a client application.

    For more information, see Setting Session Attributes.

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

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

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

    For more information, see Setting Request Attributes.

  • input_text (Text) –

    The text that the user entered (Amazon Lex interprets this text).

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

  • LoopDetectedException –

    This exception is not used.

  • 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
def post_text(
    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",
    input_text: "capo_lex_runtime_service.types.text.Text",
    *,
    config_overrides: Optional[LexRuntimeServiceClientConfig] = None,
    session_attributes: Optional[
        "capo_lex_runtime_service.types.string_map.StringMap"
    ] = None,
    request_attributes: Optional[
        "capo_lex_runtime_service.types.string_map.StringMap"
    ] = None,
    active_contexts: Optional[
        "capo_lex_runtime_service.types.active_contexts_list.ActiveContextsList"
    ] = None,
) -> "capo_lex_runtime_service.types.post_text_response.PostTextResponse":
    """<p>Sends user input to Amazon Lex. Client applications can use this API to send requests to Amazon Lex at runtime. Amazon Lex then interprets the user input using the machine learning model it built for the bot. </p> <p> In response, Amazon Lex returns the next <code>message</code> to convey to the user an optional <code>responseCard</code> to display. Consider the following example messages: </p> <ul> <li> <p> For a user input "I would like a pizza", Amazon Lex might return a response with a message eliciting slot data (for example, PizzaSize): "What size pizza would you like?" </p> </li> <li> <p> After the user provides all of the pizza order information, Amazon Lex might return a response with a message to obtain user confirmation "Proceed with the pizza order?". </p> </li> <li> <p> After the user replies to a confirmation prompt with a "yes", Amazon Lex might return a conclusion statement: "Thank you, your cheese pizza has been ordered.". </p> </li> </ul> <p> Not all Amazon Lex messages require a user response. For example, a conclusion statement does not require a response. Some messages require only a "yes" or "no" user response. In addition to the <code>message</code>, Amazon Lex provides additional context about the message in the response that you might use to enhance client behavior, for example, to display the appropriate client user interface. These are the <code>slotToElicit</code>, <code>dialogState</code>, <code>intentName</code>, and <code>slots</code> fields in the response. Consider the following examples: </p> <ul> <li> <p>If the message is to elicit slot data, Amazon Lex returns the following context information:</p> <ul> <li> <p> <code>dialogState</code> set to ElicitSlot </p> </li> <li> <p> <code>intentName</code> set to the intent name in the current context </p> </li> <li> <p> <code>slotToElicit</code> set to the slot name for which the <code>message</code> is eliciting information </p> </li> <li> <p> <code>slots</code> set to a map of slots, configured for the intent, with currently known values </p> </li> </ul> </li> <li> <p> If the message is a confirmation prompt, the <code>dialogState</code> is set to ConfirmIntent and <code>SlotToElicit</code> is set to null. </p> </li> <li> <p>If the message is a clarification prompt (configured for the intent) that indicates that user intent is not understood, the <code>dialogState</code> is set to ElicitIntent and <code>slotToElicit</code> is set to null. </p> </li> </ul> <p> In addition, Amazon Lex also returns your application-specific <code>sessionAttributes</code>. For more information, see <a href="https://docs.aws.amazon.com/lex/latest/dg/context-mgmt.html">Managing Conversation Context</a>. </p>

    Args:
        bot_name: <p>The name of the Amazon Lex bot.</p>
        bot_alias: <p>The alias of the Amazon Lex bot.</p>
        user_id: <p>The ID of the client application user. Amazon Lex uses this to identify a user's conversation with your bot. At runtime, each request must contain the <code>userID</code> field.</p> <p>To decide the user ID to use for your application, consider the following factors.</p> <ul> <li> <p>The <code>userID</code> field must not contain any personally identifiable information of the user, for example, name, personal identification numbers, or other end user personal information.</p> </li> <li> <p>If you want a user to start a conversation on one device and continue on another device, use a user-specific identifier.</p> </li> <li> <p>If you want the same user to be able to have two independent conversations on two different devices, choose a device-specific identifier.</p> </li> <li> <p>A user can't have two independent conversations with two different versions of the same bot. For example, a user can't have a conversation with the PROD and BETA versions of the same bot. If you anticipate that a user will need to have conversation with two different versions, for example, while testing, include the bot alias in the user ID to separate the two conversations.</p> </li> </ul>
        session_attributes: <p>Application-specific information passed between Amazon Lex and a client application.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/lex/latest/dg/context-mgmt.html#context-mgmt-session-attribs">Setting Session Attributes</a>.</p>
        request_attributes: <p>Request-specific information passed between Amazon Lex and a 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> <p>For more information, see <a href="https://docs.aws.amazon.com/lex/latest/dg/context-mgmt.html#context-mgmt-request-attribs">Setting Request Attributes</a>.</p>
        input_text: <p>The text that the user entered (Amazon Lex interprets this text).</p>
        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.loop_detected_exception.LoopDetectedException: <p>This exception is not used.</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.post_text_request.PostTextRequest]",
    ) -> OperationResponse[
        "capo_lex_runtime_service.types.post_text_response.PostTextResponse"
    ]:
        import capo_lex_runtime_service._operations.aws_deep_sense_run_time_service.post_text

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

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

        return capo_lex_runtime_service.types.post_text_request.redact_sensitive(
            input_
        )

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

        return capo_lex_runtime_service.types.post_text_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "PostText", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_lex_runtime_service.types.post_text_request.PostTextRequest = {
        "bot_name": bot_name,
        "bot_alias": bot_alias,
        "user_id": user_id,
        "input_text": input_text,
    }
    if session_attributes is not None:
        input_["session_attributes"] = session_attributes
    if request_attributes is not None:
        input_["request_attributes"] = request_attributes
    if active_contexts is not None:
        input_["active_contexts"] = active_contexts

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output