【问题标题】:Access to intent slots from lambda function从 lambda 函数访问意图槽
【发布时间】:2019-03-07 19:31:05
【问题描述】:

我创建了一个具有简单 lex 意图的简单机器人。此 lex 意图只有一个插槽 slotTwo

然后我将它与 python lambda 函数联系起来。我想从 lambda 函数内部访问该槽的值。

python lambda 函数接收参数contextevent。下面的链接显示了参数event 的结构。 https://docs.aws.amazon.com/lex/latest/dg/lambda-input-response-format.html

I copy it here too:


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

但是,当我打印出这个参数的内容时,我只看到了插槽,我可以直接访问它的值,一级。

START RequestId: 60a541d8-b3c8-48b0-a7a3-6b3f65d96482 Version: $LATEST
{
"slotTwo": "some text here"
}

来自 lambda 控制台的测试工作正常。它能够检索值并继续执行逻辑。 但是,当我从 Lex 测试机器人时,它不起作用。 知道为什么吗? 非常感谢 酯类

【问题讨论】:

  • 您是如何尝试获取槽值的?您尝试了吗:event.currentIntent.slots.slotOne 如果这不是简单的答案,那么我们至少需要查看您的一些 Lambda 代码来提供帮助。

标签: python lambda amazon-lex


【解决方案1】:

我的错。 我错过了 lamdda 测试中指示的值必须对应于整个 JSON 结构。所以现在我将其添加为事件测试:

{
  "currentIntent": {
    "name": "intent-name",
    "slots": {
      "slotTwo": "Hi from the sendmessagetest"
    }
  }
}

我通过这种方式访问​​ lambda 中的插槽:

 messagetext = event['currentIntent'] ['slots'] ['slotTwo']

如果您觉得我的帖子令人困惑,请随时删除。 谢谢大家

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-01
    • 1970-01-01
    • 2018-11-02
    • 1970-01-01
    • 1970-01-01
    • 2019-02-20
    • 1970-01-01
    • 2011-07-08
    相关资源
    最近更新 更多