
[英]AWS LEX: Slot update, intent update and then new publishing bot through a Lambda function
[英]AWS Lex bot calling a lambda function in fulfilment section of the lex bot, I don't see a place to call the lambda function
我创建了一个 lex 机器人来从 lambda 调用天气 API。lambda 可以很好地给出城市的温度。
感谢“Reegz”的帮助,我能够从 lex bot 调用 lambdb
现在我收到这条消息“intent findingweather is fulfilled”而不是获取城市的天气。 我测试时的 lambda 工作正常,我提供城市名称和 lambda 带来温度
import json
import boto3
from pprint import pprint
import urllib3
def weatherfunc(city_name):
api_key = '9100010fc2b045080a7exxf42051e547bdxx'
base_url = 'http://api.openweathermap.org/data/2.5/weather?'
finalurl = base_url + 'appid=' + api_key + '&q=' + city_name
httprequest = urllib3.PoolManager()
response = httprequest.request('GET',finalurl)
#pprint(response.data)
weather_status = json.loads(response.data.decode('utf-8'))
return weather_status["main"]["temp"]
def lambda_handler(event, context):
city = event['City']
a = weatherfunc(city)
是的,在向 Lex 机器人添加 Lambda 支持时,Lex V2 的控制台不太直观。
与 Lex V1 不同,在 V2 中,您只能将一个 Lambda function 关联到您的机器人。
要将 Lambda function 与您的机器人相关联,请执行以下操作:-
鉴于问题的更新 state,请参阅下面的答案。
为了有效地使用 Lambda 功能为您的 Lex 机器人提供动力,您需要密切关注Lex V2 开发人员指南。
具体来说,您需要仔细查看您的 Lambda function 从 Lex 接收的输入,并且您的 Lambda 响应与 Lex 期望的格式匹配。
查看此研讨会及其示例代码,了解如何正确使用 Lex 的输入和 output 格式。
尝试将此权限添加到您的 lambda
{
action: "lambda:InvokeFunction",
principal: new iam.AnyPrincipal(),
}
如果有效,您可以稍后限制您的本金
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.