Infinite loop in webhook

I am doing a botman on facebook. After you launch it, it will call WebHook. Unfortunately, after the first launch it will not stop throwing the same call with the same parameters. Settings:

  • message_deliveries;
  • message_reads;
  • Messages
  • messaging_optins;
  • messaging_postbacks.

Source code: https://github.com/Ellusu/nuraghebot-facebookmessenger/blob/master/index.php

Where am I mistaken? Why only one call?

+5
source share
1 answer

According to your code, I decided that you cannot configure your website, so from the documentation

Add the verification code to the URL of your web host. Your code should expect that you previously determined the confirmation token and answered the call sent back to the verification request. Click "Check & Save" in your new page subscription to call your website using GET.

So, in order for PHP to work successfully with the webhook setting, you must return the hub_challenge parameter.

Define $ verify_token with your token and add something like:

if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] == 'subscribe' && $_REQUEST['hub_verify_token'] == $verify_token) { // Webhook setup request echo $_REQUEST['hub_challenge']; exit; } 

After setting up success, you can remove this code from your script.

Or if your webhook is already connected:

You should skip any messages for reading and delivery, for example:

 if (!empty($input['entry'][0]['messaging'])) { foreach ($input['entry'][0]['messaging'] as $message) { // Skipping delivery messages if (!empty($message['delivery'])) { continue; } // Skipping read messages if (!empty($message['read'])) { continue; } } } 

Or you can uncheck the boxes for message_reads and message_deliveries in the "Subscribe to pages" section of your Facebook page / website settings.

+2
source

All Articles