问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/39377533/infinite-loop-in-a-webhook