AWS Lex无法通过变量识别响应

问题描述 投票:1回答:1

下面的lambda代码的响应不是lex接受的,但是如果我将json槽值改为声明的槽变量,则返回语句,然后工作,即它接受lex的响应。它完全令人困惑,因为变量槽和变量d具有相同的值,请找我附带的云观察日志截图。

def lambda_handler(event,context):
    slot=event['currentIntent']['slots']
    d="{'Intro': None, 'Start': None, 'ReturnBooking': None, 'name': None, 'pickup': None, 'conformation': None, 'location': None, 'Count': None, 'comfort': None}"
    print("using dict:",slot,"using variable:",d)
    return {  
       "dialogAction": {
   "type": "Delegate",
   "slots": d
  }
          }

enter image description here

如果有人想通了,请帮帮我。

amazon-web-services aws-lambda amazon-lex
1个回答
3
投票

如果一个槽没有持有一个值,那么它应该是null而不是None。看起来Cloudwatch正在为你记录nullNone。这应该是你的变量之间的差异:slotd

所以这就是d应该是:

d="{'Intro': null, 'Start': null, 'ReturnBooking': null, 'name': null, 'pickup': null, 'conformation': null, 'location': null, 'Count': null, 'comfort': null}"

但是没有理由为你的意图插槽重新创建一个字符串。你应该简单地将slots=event['currentIntent']['slots']变量传递给Lex。如果要更改Lambda中的插槽,请将其视为数组,并将其中一个插槽设置为新值:

slots['slotName'] = "new value";

或者您可以通过将其设置为null来删除插槽的值:

slots['slotName'] = null;

然后将slots送回Lex。

© www.soinside.com 2019 - 2024. All rights reserved.