選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

練習 2:檢閱對話流程

焦點模式
練習 2:檢閱對話流程 - Amazon Lex

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

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

在本練習中,您將檢閱用戶端應用程式與您在 中建立的 Amazon Lex V2 機器人之間傳送的 JSON 結構練習 1:從範例建立機器人。對話使用 RecognizeText 操作來產生 JSON 結構。RecognizeUtterance 會在回應中傳回與 HTTP 標頭相同的資訊。

JSON 結構會除以對話的每個轉彎。彎是來自用戶端應用程式的請求和來自機器人的回應。

轉 1

在對話的第一回合中,用戶端應用程式會啟動與您的機器人的對話。請求的 URI 和內文都會提供請求的相關資訊。

POST /bots/botId/botAliases/botAliasId/botLocales/localeId/sessions/sessionId/text HTTP/1.1 Content-type: application/json { "text": "I would like to order flowers" }
  • URI 可識別用戶端應用程式正在通訊的機器人。它還包括用戶端應用程式產生的工作階段識別符,用於識別使用者和機器人之間的特定對話。

  • 請求的內文包含使用者輸入用戶端應用程式的文字。在此情況下,只會傳送文字,但您的應用程式可以傳送其他資訊,例如請求屬性或工作階段狀態。如需詳細資訊,請參閱 RecognizeText 操作。

text,Amazon Lex V2 偵測使用者訂購花朵的意圖。Amazon Lex V2 選擇其中一個意圖的插槽 (FlowerType) 和其中一個插槽提示,然後將下列回應傳送至用戶端應用程式。用戶端會顯示對使用者的回應。

{ "interpretations": [ { "intent": { "confirmationState": "None", "name": "OrderFlowers", "slots": { "FlowerType": null, "PickupDate": null, "PickupTime": null }, "state": "InProgress" }, "nluConfidence": { "score": 0.95 } }, { "intent": { "name": "FallbackIntent", "slots": {} } } ], "messages": [ { "content": "What type of flowers would you like to order?", "contentType": "PlainText" } ], "sessionId": "bf445a49-7165-4fcd-9a9c-a782493fba5c", "sessionState": { "dialogAction": { "slotToElicit": "FlowerType", "type": "ElicitSlot" }, "intent": { "confirmationState": "None", "name": "OrderFlowers", "slots": { "FlowerType": null, "PickupDate": null, "PickupTime": null }, "state": "InProgress" }, "originatingRequestId": "9e8add70-4106-4a10-93f5-2ce2cb959e5f" } }

轉 2

第 2 輪,使用者以填滿FlowerType槽的值,依序回應來自 Amazon Lex V2 機器人的提示。

{ "text": "1 dozen roses" }

第 2 回合的回應顯示已填滿的FlowerType槽,並提供提示來引出下一個槽值。

{ "interpretations": [ { "intent": { "confirmationState": "None", "name": "OrderFlowers", "slots": { "FlowerType": { "value": { "interpretedValue": "dozen roses", "originalValue": "dozen roses", "resolvedValues": [] } }, "PickupDate": null, "PickupTime": null }, "state": "InProgress" }, "nluConfidence": { "score": 0.98 } }, { "intent": { "name": "FallbackIntent", "slots": {} } } ], "messages": [ { "content": "What day do you want the dozen roses to be picked up?", "contentType": "PlainText" } ], "sessionId": "bf445a49-7165-4fcd-9a9c-a782493fba5c", "sessionState": { "dialogAction": { "slotToElicit": "PickupDate", "type": "ElicitSlot" }, "intent": { "confirmationState": "None", "name": "OrderFlowers", "slots": { "FlowerType": { "value": { "interpretedValue": "dozen roses", "originalValue": "dozen roses", "resolvedValues": [] } }, "PickupDate": null, "PickupTime": null }, "state": "InProgress" }, "originatingRequestId": "9e8add70-4106-4a10-93f5-2ce2cb959e5f" } }

轉 3

第 3 輪,使用者以填滿PickupDate槽的值,依序回應來自 Amazon Lex V2 機器人的提示。

{ "text": "next monday" }

第 3 輪的回應會同時填入 FlowerTypePickupDate插槽,並提供提示來引出最後一個槽值。

{ "interpretations": [ { "intent": { "confirmationState": "None", "name": "OrderFlowers", "slots": { "FlowerType": { "value": { "interpretedValue": "dozen roses", "originalValue": "dozen roses", "resolvedValues": [] } }, "PickupDate": { "value": { "interpretedValue": "2022-12-28", "originalValue": "next monday", "resolvedValues": [ "2021-01-04" ] } }, "PickupTime": null }, "state": "InProgress" }, "nluConfidence": { "score": 1.0 } }, { "intent": { "name": "FallbackIntent", "slots": {} } } ], "messages": [ { "content": "At what time do you want the 1 dozen roses to be picked up?", "contentType": "PlainText" } ], "sessionId": "bf445a49-7165-4fcd-9a9c-a782493fba5c", "sessionState": { "dialogAction": { "slotToElicit": "PickupTime", "type": "ElicitSlot" }, "intent": { "confirmationState": "None", "name": "OrderFlowers", "slots": { "FlowerType": { "value": { "interpretedValue": "dozen roses", "originalValue": "dozen roses", "resolvedValues": [] } }, "PickupDate": { "value": { "interpretedValue": "2021-01-04", "originalValue": "next monday", "resolvedValues": [ "2021-01-04" ] } }, "PickupTime": null }, "state": "InProgress" }, "originatingRequestId": "9e8add70-4106-4a10-93f5-2ce2cb959e5f", "sessionAttributes": {} } }

轉 4

第 4 輪,使用者提供意圖的最終槽值,也就是取花的時間。

{ "text": "5 in the evening" }

在回應中,Amazon Lex V2 會傳送確認提示給使用者,以確認訂單是否正確。dialogAction 設定為 ConfirmIntent,而 confirmationStateNone

{ "interpretations": [ { "intent": { "confirmationState": "None", "name": "OrderFlowers", "slots": { "FlowerType": { "value": { "interpretedValue": "dozen roses", "originalValue": "dozen roses", "resolvedValues": [] } }, "PickupDate": { "value": { "interpretedValue": "2021-01-04", "originalValue": "next monday", "resolvedValues": [ "2021-01-04" ] } }, "PickupTime": { "value": { "interpretedValue": "17:00", "originalValue": "5 evening", "resolvedValues": [ "17:00" ] } } }, "state": "InProgress" }, "nluConfidence": { "score": 1.0 } }, { "intent": { "name": "FallbackIntent", "slots": {} } } ], "messages": [ { "content": "Okay, your dozen roses will be ready for pickup by 17:00 on 2021-01-04. Does this sound okay?", "contentType": "PlainText" } ], "sessionId": "bf445a49-7165-4fcd-9a9c-a782493fba5c", "sessionState": { "dialogAction": { "type": "ConfirmIntent" }, "intent": { "confirmationState": "None", "name": "OrderFlowers", "slots": { "FlowerType": { "value": { "interpretedValue": "dozen roses", "originalValue": "dozen roses", "resolvedValues": [] } }, "PickupDate": { "value": { "interpretedValue": "2021-01-04", "originalValue": "next monday", "resolvedValues": [ "2021-01-04" ] } }, "PickupTime": { "value": { "interpretedValue": "17:00", "originalValue": "5 evening", "resolvedValues": [ "17:00" ] } } }, "state": "InProgress" }, "originatingRequestId": "9e8add70-4106-4a10-93f5-2ce2cb959e5f" } }

轉 5

在最後輪換中,使用者會以 回應確認提示。

{ "text": "yes" }

在回應中,Amazon Lex V2 會傳送 ,將 設定為 Confirmed,並將 confirmationState設定為dialogAction關閉,表示意圖已實現。所有槽值都可供用戶端應用程式使用。

{ "interpretations": [ { "intent": { "confirmationState": "Confirmed", "name": "OrderFlowers", "slots": { "FlowerType": { "value": { "interpretedValue": "dozen roses", "originalValue": "dozen roses", "resolvedValues": [] } }, "PickupDate": { "value": { "interpretedValue": "2021-01-04", "originalValue": "next monday", "resolvedValues": [ "2021-01-04" ] } }, "PickupTime": { "value": { "interpretedValue": "17:00", "originalValue": "5 evening", "resolvedValues": [ "17:00" ] } } }, "state": "Fulfilled" }, "nluConfidence": { "score": 1.0 } }, { "intent": { "name": "FallbackIntent", "slots": {} } } ], "messages": [ { "content": "Thanks. ", "contentType": "PlainText" } ], "sessionId": "bf445a49-7165-4fcd-9a9c-a782493fba5c", "sessionState": { "dialogAction": { "type": "Close" }, "intent": { "confirmationState": "Confirmed", "name": "OrderFlowers", "slots": { "FlowerType": { "value": { "interpretedValue": "dozen roses", "originalValue": "dozen roses", "resolvedValues": [] } }, "PickupDate": { "value": { "interpretedValue": "2021-01-04", "originalValue": "next monday", "resolvedValues": [ "2021-01-04" ] } }, "PickupTime": { "value": { "interpretedValue": "17:00", "originalValue": "5 evening", "resolvedValues": [ "17:00" ] } } }, "state": "Fulfilled" }, "originatingRequestId": "9e8add70-4106-4a10-93f5-2ce2cb959e5f" } }

在本頁面

隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。