如何在 AWS Lex 中访问原始输入文本和整个对话

How to access the raw input text and the entire conversation in AWS Lex

  1. 我如何访问原始文本以引导 lex 中的意图
  2. 如何提取整个对话,包括用户输入和 Lex 响应

我想创建一个 lambda 和 API 网关来捕获输入并在将其发送到 Lex 之前记录它,并且在每个意图上 lambda 记录响应,但似乎是一种迂回的方式。

  1. 在您在 Lambda 函数中收到的 event 中,您可以从 inputTranscript
  2. 中获取原始文本

{'messageVersion': '1.0', 'invocationSource': 'DialogCodeHook', 'userId': '', 'sessionAttributes': {}, 'requestAttributes': {}, 'bot': {'name': 'bot_name', 'alias': 'bot_alias', 'version': '$LATEST'}, 'outputDialogMode': 'Text', 'currentIntent': {'name': 'invoked_intent_name', 'slots': {}, 'slotDetails': {}, 'confirmationStatus': 'None'}, 'inputTranscript': 'user message which triggered the intent'}

  1. 为了存储对话,在 Lambda 函数中,就在您向用户提供响应之前,您可以编写一个函数来存储对话,即用户查询和机器人的响应。

希望对您有所帮助。

  1. 符合您意图的原始文本可以参考 event.inputTranscript 完整的事件格式是 documented here
  2. 亚马逊有一个很好的例子来说明如何构建整个对话的抄本。看看RideService example code。注意如何使用 appendTranscript 构建交互的完整记录。