步驟 6:使用機器人集區 - Amazon Lex V1

如果您使用的是 Amazon Lex V2,請參閱 Amazon Lex V2 指南

 

如果您使用的是 Amazon Lex V1,我們建議您將機器人升級到 Amazon Lex V2。我們不再向 V1 添加新功能,強烈建議所有新的機器人使用 V2。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

步驟 6:使用機器人集區

為了展示目的,您以客戶和代理的身份向 Bot 提供輸入。為了區分這兩者,客戶提出的問題以「客戶:」開頭,代理提供的答案以「Agent:」開頭。您可以從建議的輸入選單中進行選擇。

透過開啟index.html來執行 Web 應用程式,以與您的機器人進行類似下列影像的對話:

與呼叫中心機器人的兩個示例對話。在第一個,客戶詢問亞馬遜 SageMaker 是什麼,什麼時候使用 Amazon Polly,而不是 Amazon Lex。在第二個問題中,Amazon Kendra 會找到這兩個問題的常見問題解答。

在 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 索引時刪除。