练习 2:查看对话流程 - Amazon Lex

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

练习 2:查看对话流程

在本练习中,您可以查看在您的客户端应用程序和您在 练习 1:根据示例创建机器人 中创建的 Amazon Lex V2 机器人之间发送的 JSON 结构。该对话通过 RecognizeText 操作生成 JSON 结构。RecognizeUtterance 返回的信息与响应中的 HTTP 标头相同。

JSON 结构按对话的每个回合划分。一个回合是指来自客户端应用程序的请求和来自机器人的响应。

第 1 回合

在对话的第 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 回合中,用户响应第 1 回合中 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 回合中,用户响应第 2 回合中 Amazon Lex V2 机器人的提示,为 PickupDate 插槽填充一个值。

{ "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 向用户发送确认提示以确认订单是否正确。设置 dialogActionConfirmIntentconfirmationStateNone

{ "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 设置为 close 来表示该意图已完成。所有插槽值均可供客户端应用程序使用。

{ "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" } }