API オペレーションを使用して Amazon Lex V2 ボットに AWS Lambda関数をアタッチする - Amazon Lex

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

API オペレーションを使用して Amazon Lex V2 ボットに AWS Lambda関数をアタッチする

呼び出す前に、まず Lambda 関数を Amazon Lex V2 ボットエイリアスにアタッチする必要があります。1 つのボットエイリアスに関連付けることができる Lambda 関数 は 1 つだけです。以下の手順を実行して、API オペレーションを使用して Lambda 関数をアタッチします。

新しいボットエイリアスを作成する場合は、CreateBotAlias オペレーションを使用して Lambda 関数をアタッチします。Lambda 関数を既存のボットエイリアスにアタッチするには、UpdateBotAlias オペレーションを使用します。正しい設定を含むように botAliasLocaleSettings フィールドを変更します。

{ "botAliasLocaleSettings" : { locale: { "codeHookSpecification": { "lambdaCodeHook": { "codeHookInterfaceVersion": "1.0", "lambdaARN": "arn:aws:lambda:region:account-id:function:function-name" } }, "enabled": true }, ... } }
  1. botAliasLocaleSettings フィールドは、Lambda 関数をアタッチするロケールをキーとするオブジェクトにマップされます。サポートされているロケールと有効なキーとなるコードのリストについては、「サポートされている言語とロケール」を参照してください。

  2. Lambda 関数lambdaARNの を検索するには、https://console.aws.amazon.com/lambda/home でAWS Lambdaコンソールを開き、左側のサイドバーで関数を選択し、ボットエイリアスに関連付ける関数を選択します。[関数概要] の右側にある [関数 ARN] の下の lambdaARN を確認します。リージョン、アカウント ID、関数名が含まれている必要があります。

  3. Amazon Lex V2 がエイリアスの Lambda 関数を呼び出せるようにするには、enabled フィールドを true に設定します。

API オペレーションを使用して Lambda 関数を呼び出すための Amazon Lex V2 インテントの設定

インテント中に Lambda 関数の呼び出しを設定するには、新しいインテントを作成する場合は CreateIntent オペレーションを使用し、既存のインテントで関数を呼び出す場合は UpdateIntent オペレーションを使用します。インテントオペレーションでの Lambda 関数の呼び出しを制御するフィールドは、dialogCodeHookinitialResponseSettingintentConfirmationSetting、および fulfillmentCodeHook です。

スロットの誘発中に関数を呼び出す場合、新しいスロットを作成する場合は CreateSlot オペレーションを使用し、既存のスロットで関数を呼び出すには UpdateSlot オペレーションを使用します。スロットオペレーションでの Lambda 関数の呼び出しを制御するフィールドは valueElicitationSetting オブジェクトの slotCaptureSetting フィールドです。

  1. 会話が終わるたびに Lambda ダイアログコードフックが実行されるように設定するには、enabled フィールド内の次の DialogCodeHookSettings オブジェクトの dialogCodeHook フィールドを true に設定します。

    "dialogCodeHook": { "enabled": boolean }
  2. または、関数を呼び出す会話ステージに対応する構造内の codeHook および/または elicitationCodeHook フィールドを変更して、会話の特定の時点でのみ実行されるように Lambda ダイアログコードフックを設定することもできます。Lambda ダイアログのコードフックをインテントフルフィルメントに使用するには、CreateIntent オペレーションまたは UpdateIntent オペレーションの fulfillmentCodeHook フィールドを使用します。これら 3 種類のコードフックの構造と用途は次のとおりです。

codeHook フィールドは、会話の特定の段階で実行されるコードフックの設定を定義します。このオブジェクトは DialogCodeHookInvocationSetting オブジェクトで、次のような構造になっています。

"codeHook": { "active": boolean, "enableCodeHookInvocation": boolean, "invocationLabel": string, "postCodeHookSpecification": PostDialogCodeHookInvocationSpecification object, }
  • Amazon Lex V2 の active フィールドを trueに変更して、会話のその時点でコードフックを呼び出します。

  • Amazon Lex V2 の enableCodeHookInvocation フィールドを true に変更して、コードフックが正常に動作するようにします。false をマークすると、Amazon Lex V2 はコードフックが正常に返されたかのように動作します。

  • invocationLabel は、コードフックが呼び出されるダイアログステップを示します。

  • postCodeHookSpecification フィールドを使用して、コードフックの成功、失敗、またはタイムアウトの後で発生するアクションとメッセージを指定します。

elicitationCodeHook フィールドは、1 つまたは複数のスロットを再利用する必要がある場合に実行するコードフックの設定を定義します。このシナリオは、スロットの誘発に失敗したり、インテントの確認が拒否されたりした場合に発生する可能性があります。elicitationCodeHook フィールドは、次の構造を持つ ElicitationCodeHookInvocationSetting オブジェクトです。

"elicitationCodeHook": { "enableCodeHookInvocation": boolean, "invocationLabel": string }
  • Amazon Lex V2 の enableCodeHookInvocation フィールドを true に変更して、コードフックが正常に動作するようにします。false をマークすると、Amazon Lex V2 はコードフックが正常に返されたかのように動作します。

  • invocationLabel は、コードフックが呼び出されるダイアログステップを示します。

fulfillmentCodeHook フィールドは、インテントを達成するために実行するコードフックの設定を定義します。このフィールドは次の FulfillmentCodeHookSettings オブジェクトにマップされます。

"fulfillmentCodeHook": { "active": boolean, "enabled": boolean, "fulfillmentUpdatesSpecification": FulfillmentUpdatesSpecification object, "postFulfillmentStatusSpecification": PostFulfillmentStatusSpecification object }
  • Amazon Lex V2 の active フィールドを trueに変更して、会話のその時点でコードフックを呼び出します。

  • Amazon Lex V2 の enabled フィールドを true に変更して、コードフックが正常に動作するようにします。false をマークすると、Amazon Lex V2 はコードフックが正常に返されたかのように動作します。

  • fulfillmentUpdatesSpecification フィールドを使用して、インテントのフルフィルメント中にユーザーに最新情報が表示されるメッセージと、それに関連するタイミングを指定します。

  • postFulfillmentStatusSpecification フィールドを使用して、コードフックの成功、失敗、またはタイムアウトの後で発生するメッセージとアクションを指定します。

active および enableCodeHookInvocation/enabled フィールドを true に設定することで、会話の次の時点で Lambda コードフックを呼び出すことができます。

インテントが認識された後の初期応答で Lambda 関数を呼び出すには、CreateIntent または UpdateIntent オペレーションの initialResponse フィールドにある codeHook 構造を使用します。initialResponse フィールドは次の InitialResponseSetting オブジェクトにマップされます。

"initialResponse": { "codeHook": { "active": boolean, "enableCodeHookInvocation": boolean, "invocationLabel": string, "postCodeHookSpecification": PostDialogCodeHookInvocationSpecification object, }, "initialResponse": FulfillmentUpdatesSpecification object, "nextStep": PostFulfillmentStatusSpecification object, "conditional": ConditionalSpecification object }

スロット値を取得した後に Lambda 関数を呼び出すには、CreateSlot または UpdateSlot オペレーションの valueElicitation フィールド内の slotCaptureSetting フィールドを使用します。slotCaptureSetting フィールドは次の SlotCaptureSetting オブジェクトにマップされます。

"slotCaptureSetting": { "captureConditional": ConditionalSpecification object, "captureNextStep": DialogState object, "captureResponse": ResponseSpecification object, "codeHook": { "active": true, "enableCodeHookInvocation": true, "invocationLabel": string, "postCodeHookSpecification": PostDialogCodeHookInvocationSpecification object, }, "elicitationCodeHook": { "enableCodeHookInvocation": boolean, "invocationLabel": string }, "failureConditional": ConditionalSpecification object, "failureNextStep": DialogState object, "failureResponse": ResponseSpecification object }
  • スロットの誘発が成功した後に Lambda 関数を呼び出すには、codeHook フィールドを使用します。

  • スロットの引き出が失敗し、Amazon Lex V2 がスロットの誘発を再試行した後に Lambda 関数を呼び出すには、elicitationCodeHook フィールドを使用します。

インテントを確認するときに Lambda 関数を呼び出すには、CreateIntent オペレーションまたは UpdateIntent オペレーションの intentConfirmationSetting フィールドを使用します。intentConfirmation フィールドは次の IntentConfirmationSetting オブジェクトにマップされます。

"intentConfirmationSetting": { "active": boolean, "codeHook": { "active": boolean, "enableCodeHookInvocation": boolean, "invocationLabel": string, "postCodeHookSpecification": PostDialogCodeHookInvocationSpecification object, }, "confirmationConditional": ConditionalSpecification object, "confirmationNextStep": DialogState object, "confirmationResponse": ResponseSpecification object, "declinationConditional": ConditionalSpecification object, "declinationNextStep": FulfillmentUpdatesSpecification object, "declinationResponse": PostFulfillmentStatusSpecification object, "elicitationCodeHook": { "enableCodeHookInvocation": boolean, "invocationLabel": string, }, "failureConditional": ConditionalSpecification object, "failureNextStep": DialogState object, "failureResponse": ResponseSpecification object, "promptSpecification": PromptSpecification object }
  • ユーザーがインテントとそのスロットを確認した後に Lambda 関数を呼び出すには、codeHook フィールドを使用します。

  • ユーザーがインテント確認を拒否し、Amazon Lex V2 がスロット誘発を再試行した後に Lambda 関数を呼び出すには、elicitationCodeHook フィールドを使用します。

インテントを確認するために Lambda 関数を呼び出すには、CreateIntent オペレーションまたは UpdateIntent オペレーションの fulfillmentCodeHook フィールドを使用します。fulfillmentCodeHook フィールドは次の FulfillmentCodeHookSettings オブジェクトにマップされます。

{ "active": boolean, "enabled": boolean, "fulfillmentUpdatesSpecification": FulfillmentUpdatesSpecification object, "postFulfillmentStatusSpecification": PostFulfillmentStatusSpecification object }

3. Lambda 関数を呼び出す会話ステージを設定したら、BuildBotLocale オペレーションを使用して関数をテストするためにボットを再構築します。