

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

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

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

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

![\[コールセンターボットと エージェントアシスタント間の会話の例。\]](http://docs.aws.amazon.com/ja_jp/lexv2/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 V2 ランタイム API はそれを Amazon Lex V2 に送信します。 V2

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

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