| 1 | import type * as lexr from "@distilled.cloud/aws/lex-runtime-v2"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { BotAlias } from "./BotAlias.ts"; |
| 5 | |
| 6 | /** |
| 7 | * The `RecognizeUtterance` request with the binding-injected `botId` and |
| 8 | * `botAliasId` removed. `requestContentType` selects the input media type |
| 9 | * (`text/plain; charset=utf-8` or an audio format) and `inputStream` |
| 10 | * carries the user input. `sessionState`/`requestAttributes` must be |
| 11 | * gzip-compressed and base64-encoded per the Lex V2 API contract. |
| 12 | */ |
| 13 | export interface RecognizeUtteranceRequest extends Omit< |
| 14 | lexr.RecognizeUtteranceRequest, |
| 15 | "botId" | "botAliasId" |
| 16 | > {} |
| 17 | |
| 18 | /** |
| 19 | * Runtime binding for `lex:RecognizeUtterance` — send user text or audio to |
| 20 | * an Amazon Lex V2 bot alias. Unlike `RecognizeText`, the response's |
| 21 | * `messages`/`sessionState`/`interpretations` come back gzip-compressed and |
| 22 | * base64-encoded, and an `audioStream` reply is available for voice bots. |
| 23 | * |
| 24 | * ### Conversing with a Bot |
| 25 | * **Example:** Send a Text Utterance |
| 26 | * ```typescript |
| 27 | * // init |
| 28 | * const recognizeUtterance = yield* AWS.LexV2.RecognizeUtterance(alias); |
| 29 | * |
| 30 | * // runtime — response fields are gzip+base64; decode before use |
| 31 | * const reply = yield* recognizeUtterance({ |
| 32 | * localeId: "en_US", |
| 33 | * sessionId: "user-123", |
| 34 | * requestContentType: "text/plain; charset=utf-8", |
| 35 | * inputStream: new TextEncoder().encode("hello"), |
| 36 | * }); |
| 37 | * ``` |
| 38 | * |
| 39 | * @binding |
| 40 | */ |
| 41 | export interface RecognizeUtterance extends Binding.Service< |
| 42 | RecognizeUtterance, |
| 43 | "AWS.LexV2.RecognizeUtterance", |
| 44 | ( |
| 45 | alias: BotAlias, |
| 46 | ) => Effect.Effect< |
| 47 | ( |
| 48 | request: RecognizeUtteranceRequest, |
| 49 | ) => Effect.Effect< |
| 50 | lexr.RecognizeUtteranceResponse, |
| 51 | lexr.RecognizeUtteranceError |
| 52 | > |
| 53 | > |
| 54 | > {} |
| 55 | |
| 56 | export const RecognizeUtterance = Binding.Service<RecognizeUtterance>( |
| 57 | "AWS.LexV2.RecognizeUtterance", |
| 58 | ); |