2017-06-28 126 views
0

我想連接python中製作的chatbot,並將其部署到aws lambda到facebook頁面。facebook messenger weebhok訂閱錯誤

這是我的代碼verifly連接至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

我已經創建了無服務器的URL。當我從瀏覽器獲取請求時,它運行良好。

我在facebook的Webhook頁面給出了相同的URL。並確保驗證和驗證令牌是正確的。

我嘗試了一些我在網上看到的東西。但我不明白他們中的一些像這樣一個 Facebook Messenger API "URL COULD NOT BE VALIDATED" 我不明白我是否認爲這個證書文件?

AND "The URL could not be validated", facebook api error說給路徑的PHP。我什至不使用?

+0

你給Facebook的URL是什麼?該網址是否存在?當您自己訪問該網址時會發生什麼? –

+0

Url確實存在,並且當沒有找到密鑰時它返回一些標準響應。 –

回答

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