我遇到了aws lambda函数无法向aws lex发送预期json格式的巨大障碍。构建一个与lambda python函数通信的简单天气聊天机器人。它只有一个插槽{city}。在python中,我尝试了许多不同的 message
变量,但所有尝试都获得lex error无效lambda响应:从lambda接收到错误响应:未处理
以下是lambda函数:
import requests
def lambda_handler(event, context):
city = event['currentIntent'] ['slots'] ['City']
api = "http://api.openweathermap.org/data/2.5/weather?q="+ city +"TOKEN"
json_data = requests.get(api).json()
temp = int(json_data['main']['temp'] - 273.15)
answer = f"Weather in {city} is {temp}C"
message = {
"dialogAction": {
"type": "ConfirmIntent", #also tried Close
"fulfillmentState": "Fulfilled",
"message": {
"contentType": "PlainText",
"content": answer
}
}
}
return message
# Also tried variant 2 With contentType PlainText or SSML:
message = {
"sessionAttributes": {},
"dialogAction": {
"type": "Close",
"fulfillmentState": "Fulfilled",
"message": {
"contentType": "PlainText",
"content": answer
}
}
}
# Variant 3:
message = {
"sessionState": {
"dialogAction": {
"type": "Close"
},
"intent": {
"name": "FindingWeather"
},
"state": "Fulfilled"
},
"messages": [
{
"contentType": "PlainText",
"content": answer
}
]
}
两者都不起作用,所有尝试都会出现一个错误。。。(帮助)
暂无答案!
目前还没有任何答案,快来回答吧!