amazon-web-services - 如果通过变量,AWS Lex 不会识别响应
问题描述
下面的 lambda 代码的响应不被 lex 接受,但是在return语句中,如果我将 json插槽值更改为声明的插槽变量,然后工作,即 lex 接受它的响应。它完全令人困惑,因为变量slot和变量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
}
}
如果有人知道,请帮助我。
解决方案
如果一个插槽没有保存一个值,那么它应该是null
not 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。
推荐阅读
- listview - ListView 小部件未在我的屏幕上显示并且无法正常工作(在 Flutter 中)
- javascript - 无法理解 requireJS 的 require() 函数
- python - AttributeError:模块“tensorflow_docs”没有属性“plots”
- xml - 如何使用 Powershell 使用 INI 文件自动创建 XML 文件?
- design-patterns - 分布式原子计数器
- ios - 在框架内使用 xcframework
- javascript - 显示隐藏字段取决于在线选择值共享点
- webforms - asp.net web 表单中的 SAML SSO
- xml - 文档末尾的额外内容 - XML
- javascript - HTTP2:是否可以在流上发送后续或额外的 HEADER 块?