【发布时间】:2019-07-16 03:15:31
【问题描述】:
我编写了这个函数,当它只是作为字符串返回时,它会返回正常。我非常严格地遵循响应卡的语法,它通过了我在 lambda 中的测试用例。然而,当它通过 Lex 调用时,它会抛出一个错误,我将在下面发布。它说fulfillmentState 不能为null,但在它抛出的错误中表明它不是null。
我试过切换对话状态和响应卡的顺序,我试过切换“type”和“fulfillmentState”的顺序。功能:
def backup_phone(intent_request):
back_up_location = get_slots(intent_request)["BackupLocation"]
phone_os = get_slots(intent_request)["PhoneType"]
try:
from googlesearch import search
except ImportError:
print("No module named 'google' found")
# to search
query = "How to back up {} to {}".format(phone_os, back_up_location)
result_list = []
for j in search(query, tld="com", num=5, stop=5, pause=2):
result_list.append(j)
return {
"dialogAction": {
"fulfilmentState": "Fulfilled",
"type": "Close",
"contentType": "Plain Text",
'content': "Here you go",
},
'responseCard': {
'contentType': 'application/vnd.amazonaws.card.generic',
'version': 1,
'genericAttachments': [{
'title': "Please select one of the options",
'subTitle': "{}".format(query),
'buttons': [
{
"text": "{}".format(result_list[0]),
"value": "test"
},
]
}]
}
}
通过 lambda 的测试用例截图:https://ibb.co/sgjC2WK Lex 中错误抛出的屏幕截图:https://ibb.co/yqwN42m
Lex 中的错误文本:
“发生错误:无效的 Lambda 响应:收到来自 Lambda 的无效响应:无法构造 CloseDialogAction 的实例,问题:在 [Source: {"dialogAction": {"fulfilmentState" :“已完成”,“类型”:“关闭”,“contentType”:“纯文本”,“内容”:“Here you go”},“responseCard”:{“contentType”:“application/vnd.amazonaws.card” .generic", "version": 1, "genericAttachments": [{"title": "请选择其中一个选项", "subTitle": "如何将 Iphone 备份到 windows", "buttons": [{" text": "https://www.easeus.com/iphone-data-transfer/how-to-backup-your-iphone-with-windows-10.html", "value": "test"}]}]}};行:1,列:121]"
【问题讨论】:
-
您的问题似乎是由于您的响应消息中的拼写错误造成的。
fulfillmentState有两个 L,而您的密钥只有一个。另外,Plain Text 之间应该没有空格。
标签: amazon-web-services aws-lambda aws-lex