本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
在本練習中,您將檢閱用戶端應用程式與您在 中建立的 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 輪的回應會同時填入 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 會傳送 ,將 設定為 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"
}
}