AWS Lex Python Codehook参考

时间:2018-09-07 13:26:34

标签: amazon-lex

对于Python(和编码)我还是很陌生,但是我正在尝试使用Lambda函数构建自己的Lex机器人。我一直在遵循这些教程,我可以理解它们的工作原理。问题是,当我尝试为Lex编写自己的Lambda函数时,找不到任何引用来帮助我编写代码,例如查看下面的代码。

def get_slots(intent_request):
    return intent_request['currentIntent']['slots']

什么是“(intent_request)”,在哪里可以找到对此的引用?相同于“ ['currentIntent'],我怎么能知道它是什么以及为什么在那里??

抱歉,这对大多数人来说很愚蠢,但是我无法开始编写代码,并且继续学习是否找不到任何文档来建议这些内容以及为我编写代码所需要的原因。自己的Lex机器人。

提前谢谢!

1 个答案:

答案 0 :(得分:1)

intent_request是从Lex到Lambda函数的传入“请求”或“事件”。它包含有关用户输入和Lex bot对输入的处理的所有必要信息(触发某些意图,填充某些插槽,确认等)。

这应该是您要查找的文档。

Lambda Function Input Event and Response Format

  

本节描述了Amazon Lex提供给Lambda函数的事件数据的结构。使用此信息来解析Lambda代码中的输入。它还说明了Amazon Lex期望Lambda函数返回的响应的格式。

这是事件/请求格式:

{
  "currentIntent": {
    "name": "intent-name",
    "slots": {
      "slot name": "value",
      "slot name": "value"
    },
    "slotDetails": {
      "slot name": {
        "resolutions" : [
          { "value": "resolved value" },
          { "value": "resolved value" }
        ],
        "originalValue": "original text"
      },
      "slot name": {
        "resolutions" : [
          { "value": "resolved value" },
          { "value": "resolved value" }
        ],
        "originalValue": "original text"
      }
    },
    "confirmationStatus": "None, Confirmed, or Denied (intent confirmation, if configured)"
  },
  "bot": {
    "name": "bot name",
    "alias": "bot alias",
    "version": "bot version"
  },
  "userId": "User ID specified in the POST request to Amazon Lex.",
  "inputTranscript": "Text used to process the request",
  "invocationSource": "FulfillmentCodeHook or DialogCodeHook",
  "outputDialogMode": "Text or Voice, based on ContentType request header in runtime API request",
  "messageVersion": "1.0",
  "sessionAttributes": { 
     "key": "value",
     "key": "value"
  },
  "requestAttributes": { 
     "key": "value",
     "key": "value"
  }
}

slots数据位于currentIntent内部,而该数据位于整个intent_request对象的内部。这就是为什么您看到以下代码:intent_request['currentIntent']['slots']

因此,要获取会话属性,可以在以下位置找到它们:intent_request['sessionAttributes']

确切的用户输入文本也非常有用: intent_request['inputTranscript']