3

I have been building a Facebook Messenger bot and am having trouble receiving messages from Messenger at the webhook on my server. I've been working with the Send API & Webhooks for several weeks and have had no trouble sending messages back and forth to a user until today. I am able to validate the webhook from the Facebook Developer Console, and I can see the validation coming through on a GET call to my /webhook route. However, when I message my bot (which should POST to /webhook) from my personal account, I don't see any of the message data being forwarded to my server. The route never gets hit. The page I'm sending to is subscribed to the app in the Facebook Developer Console. What's strange is that I can manually hit /webhook with a message using curl:

curl -i -X POST -H 'Content-Type: application/json' -d 
'{"object":"page","entry":
[{"id":43674671559,"time":1460620433256,"messaging":[{"sender":
{"id":MY_ACTUAL_FACEBOOK_USER_ID},"recipient":
{"id":MY_PAGE_ID},"timestamp":1460620433123,"message":{"mid":"mid.1460620432888:f8e3412003d2d1cd93","seq":12604,"text":"Testing 
Chat Bot .."}}]}]}' "https://XXXXX.ngrok.io/webhook"

I'm using ngrok to forward calls to my localhost. The above curl command works fine, meaning I can see the message delivered on my server at /webhook. To me this suggests the problem is coming from Facebook, which would mean it's out of my control. Is there anything I've missed? What else could I check, and why would this be failing silently?

tom-g
  • 115
  • 2
  • 10

1 Answers1

3

The problem as described above is most likely in Messenger -> settings -> webhooks window where in the bottom you have to select a Page to subscribe to the application (webhook).

Also, sometimes if you send messages and the webhook is offline, it takes couple of minutes for all the messages to come through.

Jan Sila
  • 1,554
  • 3
  • 17
  • 36
  • 1
    Just wanted to add this for whoever get this case like me, it took me waiting about 20 minutes for `all the messages to come through` .. my case was when I send `500` HTTP error in respond to `POST /webhook` route .. the Facebook just wait for this amount of time. – Ahmed Shendy Nov 08 '19 at 02:52
  • 1
    @AhmedShendy you should always send 200 status to facebook that you received the message. Then, jf you have a problem internally, deal with it yourself. At least that’s how I do it. – Jan Sila Nov 09 '19 at 07:46
  • 1
    exactly that worked for me perfectly yesterday ... I kept using logging with all 200 status, and learn from my mistakes through logging and expected output rather than HTTP status code. – Ahmed Shendy Nov 09 '19 at 13:55