RecognizeText
Source:
src/AWS/LexV2/RecognizeText.ts
Runtime binding for lex:RecognizeText — send user text to an Amazon Lex
V2 bot alias and receive the interpreted intent and response messages.
The alias must point at a built bot version (see BotVersion).
Conversing with a Bot
Section titled “Conversing with a Bot”Recognize Text
// initconst recognizeText = yield* AWS.LexV2.RecognizeText(alias);
// runtimeconst reply = yield* recognizeText({ localeId: "en_US", sessionId: "user-123", text: "hello",});const intent = reply.sessionState?.intent?.name;Wire into a Lambda Function
// Bind the alias in the init phase, call in the handler, and provide// the RecognizeTextHttp layer on the Function's init Effect.export default ChatFunction.make( { main: import.meta.url, url: true }, Effect.gen(function* () { const alias = yield* AWS.LexV2.BotAlias("Live", { botId: version.botId, botVersion: version.botVersion, }); const recognizeText = yield* AWS.LexV2.RecognizeText(alias); return { fetch: Effect.gen(function* () { const reply = yield* recognizeText({ localeId: "en_US", sessionId: "user-123", text: "hello", }); return HttpServerResponse.json({ intent: reply.sessionState?.intent?.name ?? null, }); }), }; }).pipe(Effect.provide(AWS.LexV2.RecognizeTextHttp)),);