

サポート終了通知: 2025 年 9 月 15 日、 AWS は Amazon Lex V1 のサポートを終了します。 V1 2025 年 9 月 15 日を過ぎると、Amazon Lex V1 コンソールまたは Amazon Lex V1 リソースにはアクセスできなくなります。Amazon Lex V2 を使用している場合は、代わりに [Amazon Lex V2 ガイド](https://docs.aws.amazon.com/lexv2/latest/dg/what-is.html)を参照してください。

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

# ステップ 6: ボットを使用する
<a name="agent-step-6"></a>

デモの目的で、顧客およびエージェントとしてボットにインプットを提供します。両者を区別するために、顧客からの質問には「Customer:」で始まり、エージェントから提供された回答は「Agent:」で始まります。提案された入力候補のメニューから選ぶことができます。

`index.html` を開いてウェブアプリケーションを実行すると、次の画像のようにボットとの対話が行われます。

![\[コールセンターのボットとの 2 つの会話例。最初のステップでは、顧客は Amazon SageMaker AI とは何か、Amazon Lex の代わりに Amazon Polly をいつ使用するかを尋ねます。2 つ目の例では、Amazon Kendra がこの 2 つの質問に対するよくある質問の回答を検索しています。\]](http://docs.aws.amazon.com/ja_jp/lex/latest/dg/images/agent-tutorial-ss.png)


「index.html 」ファイル内の `pushChat()` 機能について説明します。

```
            
            var endConversationStatement = "Customer: I have no more questions. Thank you." 
            // If the agent has to send a message, start the message with 'Agent'
            var inputText = document.getElementById('input');
            if (inputText && inputText.value && inputText.value.trim().length > 0 && inputText.value[0]=='Agent') {               
                showMessage(inputText.value, 'agentRequest','conversation');
                inputText.value = "";
            }
            // If the customer has to send a message, start the message with 'Customer'
            if(inputText && inputText.value && inputText.value.trim().length > 0 && inputText.value[0]=='Customer') {  
                // disable input to show we're sending it
                var input = inputText.value.trim();
                inputText.value = '...';
                inputText.locked = true;
                customerInput = input.substring(2);

                // Send it to the Lex runtime
                var params = {
                    botAlias: '$LATEST',
                    botName: 'KendraTestBot',
                    inputText: customerInput,
                    userId: lexUserId,
                    sessionAttributes: sessionAttributes
                };

                showMessage(input, 'customerRequest', 'conversation');
                if(input== endConversationStatement){
                    showMessage('Conversation Ended.','conversationEndRequest','conversation');
                }
                lexruntime.postText(params, function(err, data) {
                    if (err) {
                        console.log(err, err.stack);
                        showMessage('Error:  ' + err.message + ' (see console for details)', 'lexError', 'conversation1')
                    }

                    if (data &&input!=endConversationStatement) {
                        // capture the sessionAttributes for the next cycle
                        sessionAttributes = data.sessionAttributes;
                        
                            showMessage(data, 'lexResponse', 'conversation1');
                    }
                    // re-enable input
                    inputText.value = '';
                    inputText.locked = false;
                });
            }
            // we always cancel form submission
            return false;
```

 顧客として入力すると、Amazon Lex ランタイム API が Amazon Lex に送信します。

`showMessage(daText, senderRequest, displayWindow)` 機能は、エージェントと顧客との会話をチャットウィンドウに表示します。Amazon Kendra によって提案された回答は、隣接するウィンドウに表示されます。顧客が「**“I have no more questions. Thank you.”**」と言った時点で会話は終了します

**注意:** Amazon Kendra のインデックスは、ご使用にならないときは削除してください。