0

I understand that when using the Facebook Messenger API, you MUST respond with a 200 OK header after receiving any webhook event or else the API will keep resending the webhook event every 20 second until a 200 OK is received as stated here https://developers.facebook.com/docs/messenger-platform/webhook/#response

I responded with the 200 OK header with the code below

<?php
header('HTTP/1.0 200 OK');
//.. some define here

//check token at setup
if(isset($_REQUEST['hub_verify_token']) && $_REQUEST['hub_verify_token'] === HUB_VERIFY_TOKEN){
    echo $_REQUEST['hub_challenge'];
    exit;
}
else{
    $input = file_get_contents('php://input');
    //... further process
}

With this, the API is not receiving the 200 OK as it keeps resending the webhook multiple times (like 100 times) and new webhooks are not delivered but when I send a message to the sender_id, it delivers.

Below is just the last 3 of about 100 I kept receiving. What am I doing wrong? {"object":"page","entry":[{"id":"2229337433988598","time":1553082378936,"messaging":[{"sender":{"id":"2328261693885002"},"recipient":{"id":"2229337433988598"},"timestamp":1553080021611,"message":{"mid":"We9JyA5teKm4AjvtFU8Kqbf5aDr8mkTfciEIlko_ULGdUfl-gvMp8dafqKxc0QBVyPDtOsqQZuK_xImKfqm69Q","seq":40930,"text":"calm"}}]}]}

{"object":"page","entry":[{"id":"2229337433988598","time":1553082476255,"messaging":[{"sender":{"id":"2328261693885002"},"recipient":{"id":"2229337433988598"},"timestamp":1553080021611,"message":{"mid":"We9JyA5teKm4AjvtFU8Kqbf5aDr8mkTfciEIlko_ULGdUfl-gvMp8dafqKxc0QBVyPDtOsqQZuK_xImKfqm69Q","seq":40930,"text":"calm"}}]}]}

{"object":"page","entry":[{"id":"2229337433988598","time":1553082569721,"messaging":[{"sender":{"id":"2328261693885002"},"recipient":{"id":"2229337433988598"},"timestamp":1553080021611,"message":{"mid":"We9JyA5teKm4AjvtFU8Kqbf5aDr8mkTfciEIlko_ULGdUfl-gvMp8dafqKxc0QBVyPDtOsqQZuK_xImKfqm69Q","seq":40930,"text":"calm"}}]}]}

{"object":"page","entry":[{"id":"2229337433988598","time":1553082667807,"messaging":[{"sender":{"id":"2328261693885002"},"recipient":{"id":"2229337433988598"},"timestamp":1553080021611,"message":{"mid":"We9JyA5teKm4AjvtFU8Kqbf5aDr8mkTfciEIlko_ULGdUfl-gvMp8dafqKxc0QBVyPDtOsqQZuK_xImKfqm69Q","seq":40930,"text":"calm"}}]}]}

{"object":"page","entry":[{"id":"2229337433988598","time":1553082753466,"messaging":[{"sender":{"id":"2328261693885002"},"recipient":{"id":"2229337433988598"},"timestamp":1553080021611,"message":{"mid":"We9JyA5teKm4AjvtFU8Kqbf5aDr8mkTfciEIlko_ULGdUfl-gvMp8dafqKxc0QBVyPDtOsqQZuK_xImKfqm69Q","seq":40930,"text":"calm"}}]}]}

MOHW
  • 737
  • 1
  • 11
  • 23
  • Is the request Facebook makes really using HTTP/1.0? Might mess stuff up, if you respond to an HTTP/1.1 request with that kind of header … I’d recommend you try one of the ways described here, https://stackoverflow.com/a/12018482/10955263, preferably the one using just `http_response_code` – 04FS Mar 20 '19 at 12:41
  • Tried `http_response_code(200);` `header('HTTP/1.0 200 OK');` `header('HTTP/1.1 200 OK');` nothing works and also discovered `headers_list()` is returning an empty array – MOHW Mar 20 '19 at 13:21
  • Well then you got to do some proper debugging to find out what is going wrong with your script. I’d start by testing what the response is when you send a request to your endpoint yourself using postman or similar. – 04FS Mar 20 '19 at 13:55

0 Answers0