infinite loop in a WebHook
Asked Answered
M

1

6

I'm doing a facebook messenger bot. After you start it, it makes a call to WebHook. Unfortunately after the first start will not stop throwing the same call with the same parameters. The settings are:

  • message_deliveries;
  • message_reads;
  • messages;
  • messaging_optins;
  • messaging_postbacks.

The source code is this: https://github.com/Ellusu/nuraghebot-facebookmessenger/blob/master/index.php

Where am I wrong? Why does only one call?

Minnich answered 7/9, 2016 at 19:16 Comment(0)
N
3

By your code I decided that you can't setup your webhook, so from documentation

At your webhook URL, add code for verification. Your code should expect the Verify Token you previously defined, and respond with the challenge sent back in the verification request. Click the "Verify and Save" button in the New Page Subscription to call your webhook with a GET request.

So, for PHP to make a success with webhook setup you must return 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 success setup, you can delete this code from your script.

Or, if your webhook already hooked:

You should skip any read and delivery messages, like this:

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 deselect message_reads & message_deliveries checkboxes in Page Subscription section of your Facebook Page Settings/Webhooks.

Niggle answered 8/9, 2016 at 20:29 Comment(5)
that task has already been made during the creation and has already been canceled . Without this operation it was not possible to make calls.Minnich
Do you have some logs? What exactly message do you receive?Niggle
Also, I tested your code on my bot and it works correctly.Niggle
No error. I sent the message and he infinitely running the code in webhooksMinnich
Ok, I think you get some delivery or read message and this leads to infinitive loop. You should skip this messages as described hereNiggle

© 2022 - 2024 — McMap. All rights reserved.