我想将在python中制作的聊天机器人连接到aws lambda上并部署到facebook页面。
这是我验证与facebook连接的代码
def webhook(event, context):
# #debug
print("event:" )
print(event)
# print("context")
# print(context)
#handle webhook challenge
if keys_exist(event, ["queryStringParameters"]):
print("Veriflying stuff")
v_token = str(find_item(event, 'hub.verify_token'))
print("token :")
print (v_token)
challenge = int(find_item(event, 'hub.challenge'))
print ("challenge")
print(challenge)
if (os.environ['verify_token'] == v_token):
print ("returning stuff")
return (challenge)
但facebook说The URL couldn't be validated. Callback verification failed with the following errors: HTTP Status Code = 502; HTTP Message = Bad Gateway
我用无服务器创建了网址。当我从浏览器收到请求时,它运行良好。
我在facebook Webhook页面中给出了相同的URL。并确保验证和验证令牌是正确的。
我尝试了一些我在网上看到的东西。但我不明白他们中的一些人喜欢这个 Facebook Messenger API "URL COULD NOT BE VALIDATED" 我不明白我是否为此修改了一个证书文件?
AND "The URL could not be validated", facebook api error说要给php提供路径。哪个我甚至不用?
答案 0 :(得分:0)
我发现了这个问题。 Facebook现在还需要请求的状态代码。
if keys_exist(event, ["queryStringParameters","hub.verify_token","hub.challenge"]):
print("subscribe to webhook invoked")
v_token = str(find_item(event, 'hub.verify_token'))
challenge = find_item(event, 'hub.challenge')
if ("strongtoken" == v_token):
response = {
"statusCode": 200,
"body": str(challenge)
}
print(challenge)
return response