CodeHookEventSource
Source:
src/AWS/LexV2/CodeHookEventSource.ts
Event source connecting an Amazon Lex V2 bot alias’s Lambda code hook (dialog and fulfillment) to the hosting Lambda function.
At deploy time the implementation (LexV2.LambdaCodeHookEventSource)
injects the function ARN into the alias’s botAliasLocaleSettings
(through the alias’s binding contract) and creates the
lambda:InvokeFunction Permission for lexv2.amazonaws.com; at runtime
it dispatches matching code hook events to the handler and returns the
handler’s response to Lex.
Enable the hook per intent with the dialogCodeHook /
fulfillmentCodeHook props on LexV2.Intent.
Use the onCodeHook helper rather than the service directly, and
provide LexV2.LambdaCodeHookEventSource on the hosting function.
Handling Code Hooks
Section titled “Handling Code Hooks”export default BotFunction.make( { main: import.meta.url }, Effect.gen(function* () { const alias = yield* AWS.LexV2.BotAlias("Live", { botId: version.botId, botVersion: version.botVersion, });
// deploy: wires the alias's en_US code hook + invoke Permission // runtime: dispatches code hook events to this handler yield* AWS.LexV2.onCodeHook(alias, { localeId: "en_US" }, (event) => Effect.succeed( AWS.LexV2.fulfillIntent(event, { message: "Order placed!" }), ), );
return {}; }).pipe(Effect.provide(AWS.LexV2.LambdaCodeHookEventSource)),);