Facebook Messenger Webhook continuously sending messages

Usama Noman picture Usama Noman · Apr 19, 2016 · Viewed 7.1k times · Source

I am learning to work with Facebook Messenger API. I have successfully setup a webhook, I have subscribe to the application. But when I send message to my Page I receive multiple instances of the same message like a burst.

I am storing messages which I send from my application when it is receive at the Webhook.

A view of my database look like in the screenshot below.

http://prntscr.com/au3emz

I am guessing it may be because the message is still unread? Just a wild guess may be someone else know for sure. I tried exact example of the Facebook Office (Node) and it is happening there as well.

Thanks.

Answer

ycansener picture ycansener · Sep 8, 2018

When someone send a message to your Facebook Page, Facebook transfer that message to your Webhook address and waits for a http response like OK. And it keeps sending the same message to your webhook until the response arrives.

From Facebook webhook docs (Webhook docs;

Required 200 OK Response When you receive a webhook event, you must always return a 200 OK HTTP response. The Messenger Platform will resend the webhook event every 20 seconds, until a 200 OK response is received. Failing to return a 200 OK may cause your webhook to be unsubscribed by the Messenger Platform.

A delivery receipt will automatically be sent to the user after your webhook has acknowledged the message. You can also use Sender Actions to notify that the message has been seen.

You can see that all of those messages have the same timestamp.

As a solution; you can define a message queue to store those messages, and you add message to the queue if there is no such message in queue with the message sender id and timestamp.

Hope this helps,