Duplicate POST Requests from Facebook Messenger/Bo

2019-07-31 05:16发布

问题:

I keep getting double requests on to my webhook when trying to create a Facebook bot. I don't know why or how to stop this. My code seems standard.

I'm using the request module in Node.js to send responses.

Is this a known issue or is there a Node based way to mitigate this?

回答1:

I've been seeing multiple deliveries on my bots for two reasons:

  • FB seems to have a 15 second timeout on webhook requests. That is, if your webhook does not return a 200 - OK within 15 seconds, FB will retry to request a second time.
  • Like @iownthegame wrote, if you register for the message_deliveries event, FB will send you delivery receipts.

One way to handle duplicate deliveries is to keep track of the last seq value that your bot saw. Obviously if you are load balancing webhooks requests across a pool of servers (eg on Heroku), you will have to share the last seen seq value across all your instances.



回答2:

Did you also register for the message_deliveries event for your webhook? If yes it will send you the message deliveries for confirmation.