本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
練習 2:檢閱交談流程
在本練習中,您將檢閱用戶端應用程式和您在其中建立的 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,使用者會依次回應 Amazon Lex V2 機器人的提示,並使用填滿FlowerType
插槽的值回應。
{
"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,使用者會依次回應 Amazon Lex V2 機器人的提示,並使用填滿PickupDate
插槽的值回應。
{
"text": "next monday"
}
對於迴轉 3 的回應FlowerType
和PickupDate
槽都已填滿,並提供引出最後一個槽值的提示。
{
"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
且confirmationState
是None
。
{
"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 傳送表示已透過將設定confirmationState
為Confirmed
和關閉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"
}
}