Amazon web services AWS Lex未识别由变量引起的响应
lex不接受下面lambda代码的响应,但在return语句中,如果我将jsonslots值更改为声明的slot变量,则将其工作,即lex接受它的响应。由于变量slot和变量d具有相同的值,因此完全令人困惑,请查看随附的“我的云观察日志”屏幕截图,以供参考Amazon web services AWS Lex未识别由变量引起的响应,amazon-web-services,aws-lambda,amazon-lex,Amazon Web Services,Aws Lambda,Amazon Lex,lex不接受下面lambda代码的响应,但在return语句中,如果我将jsonslots值更改为声明的slot变量,则将其工作,即lex接受它的响应。由于变量slot和变量d具有相同的值,因此完全令人困惑,请查看随附的“我的云观察日志”屏幕截图,以供参考 def lambda_handler(event,context): slot=event['currentIntent']['slots'] d="{'Intro': None, 'Start': None, 'Return
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
}
}
如果有人发现了,请帮助我。如果插槽中没有值,那么它应该是
null
而不是None
。看起来Cloudwatch正在为您记录null
为None
。这就是变量之间的差异:slot
和d
这就是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