post_content
¶
post_content(
bot_name: BotName,
bot_alias: BotAlias,
user_id: UserId,
content_type: HttpContentType,
input_stream: Body[Iterator[bytes]] | Iterator[bytes] | bytes,
*,
config_overrides: Optional[LexRuntimeServiceClientConfig] = None,
session_attributes: Optional[SynthesizedJsonAttributesString] = None,
request_attributes: Optional[SynthesizedJsonAttributesString] = None,
accept: Optional[Accept] = None,
active_contexts: Optional[SynthesizedJsonActiveContextsString] = None,
) -> Generator[PostContentResponse]
Sends user input (text or speech) to Amazon Lex. Clients use this API to send text and audio requests to Amazon Lex at runtime. Amazon Lex interprets the user input using the machine learning model that it built for the bot.
The PostContent operation supports audio input at 8kHz and 16kHz. You can use 8kHz audio to achieve higher speech recognition accuracy in telephone audio applications.
In response, Amazon Lex returns the next message to convey to the user. 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 get user confirmation: "Order the pizza?".
-
After the user replies "Yes" to the confirmation prompt, Amazon Lex might return a conclusion statement: "Thank you, your cheese pizza has been ordered.".
Not all Amazon Lex messages require a response from the user. For example, conclusion statements do not require a response. Some messages require only a yes or no response. In addition to the message, Amazon Lex provides additional context about the message in the response that you can use to enhance client behavior, such as displaying the appropriate client user interface. Consider the following examples:
-
If the message is to elicit slot data, Amazon Lex returns the following context information:
-
x-amz-lex-dialog-stateheader set toElicitSlot -
x-amz-lex-intent-nameheader set to the intent name in the current context -
x-amz-lex-slot-to-elicitheader set to the slot name for which themessageis eliciting information -
x-amz-lex-slotsheader set to a map of slots configured for the intent with their current values
-
-
If the message is a confirmation prompt, the
x-amz-lex-dialog-stateheader is set toConfirmationand thex-amz-lex-slot-to-elicitheader is omitted. -
If the message is a clarification prompt configured for the intent, indicating that the user intent is not understood, the
x-amz-dialog-stateheader is set toElicitIntentand thex-amz-slot-to-elicitheader is omitted.
In addition, Amazon Lex also returns your application-specific sessionAttributes. For more information, see Managing Conversation Context.
Parameters:
-
bot_name(BotName) –Name of the Amazon Lex bot.
-
bot_alias(BotAlias) –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
userIDfield.To decide the user ID to use for your application, consider the following factors.
-
The
userIDfield 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[SynthesizedJsonAttributesString], default:None) –You pass this value as the
x-amz-lex-session-attributesHTTP header.Application-specific information passed between Amazon Lex and a client application. The value must be a JSON serialized and base64 encoded map with string keys and values. The total size of the
sessionAttributesandrequestAttributesheaders is limited to 12 KB.For more information, see Setting Session Attributes.
-
request_attributes(Optional[SynthesizedJsonAttributesString], default:None) –You pass this value as the
x-amz-lex-request-attributesHTTP header.Request-specific information passed between Amazon Lex and a client application. The value must be a JSON serialized and base64 encoded map with string keys and values. The total size of the
requestAttributesandsessionAttributesheaders is limited to 12 KB.The namespace
x-amz-lex:is reserved for special attributes. Don't create any request attributes with the prefixx-amz-lex:.For more information, see Setting Request Attributes.
-
content_type(HttpContentType) –You pass this value as the
Content-TypeHTTP header.Indicates the audio format or text. The header value must start with one of the following prefixes:
-
PCM format, audio data must be in little-endian byte order.
-
audio/l16; rate=16000; channels=1
-
audio/x-l16; sample-rate=16000; channel-count=1
-
audio/lpcm; sample-rate=8000; sample-size-bits=16; channel-count=1; is-big-endian=false
-
-
Opus format
-
audio/x-cbr-opus-with-preamble; preamble-size=0; bit-rate=256000; frame-size-milliseconds=4
-
-
Text format
-
text/plain; charset=utf-8
-
-
-
accept(Optional[Accept], default:None) –You pass this value as the
AcceptHTTP header.The message Amazon Lex returns in the response can be either text or speech based on the
AcceptHTTP header value in the request.-
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 (using the configuration you specified in theAcceptheader). For example, if you specifyaudio/mpegas the value, Amazon Lex returns speech in the MPEG format. -
If the value is
audio/pcm, the speech returned isaudio/pcmin 16-bit, little endian format. -
The following are the accepted values:
-
audio/mpeg
-
audio/ogg
-
audio/pcm
-
text/plain; charset=utf-8
-
audio/* (defaults to mpeg)
-
-
-
input_stream(Body[Iterator[bytes]] | Iterator[bytes] | bytes) –User input in PCM or Opus audio format or text format as described in the
Content-TypeHTTP header.You can stream audio data to Amazon Lex or you can create a local buffer that captures all of the audio data before sending. In general, you get better performance if you stream audio data rather than buffering the data locally.
-
active_contexts(Optional[SynthesizedJsonActiveContextsString], 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
Delegatedialog action without removing any slot values.
-
-
InternalFailureException–Internal service error. Retry the call.
-
LimitExceededException–Exceeded a limit.
-
LoopDetectedException–This exception is not used.
-
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.
-
RequestTimeoutException–The input speech is too long.
-
UnsupportedMediaTypeException–The Content-Type header (
PostContentAPI) has an invalid value. -
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
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |