WebHook中的无限循环 [英] infinite loop in a WebHook

查看:124
本文介绍了WebHook中的无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个Facebook Messenger机器人.启动它后,它将调用WebHook.不幸的是,在第一次启动之后,并不会停止抛出具有相同参数的相同调用.设置为:

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;
  • 消息;
  • messaging_optins;
  • messaging_postbacks.

源代码是这样的: https://github.com/Ellusu/nuraghebot-facebookmessenger/blob/master/index.php

我在哪里错了?为什么只打一个电话?

Where am I wrong? Why does only one call?

推荐答案

通过您的代码,我决定您无法设置Webhook,因此从

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

在您的Webhook URL上,添加用于验证的代码.您的代码应期待您之前定义的验证令牌,并使用验证请求中发回的挑战.点击验证并新页面订阅中的保存"按钮,以通过GET请求.

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.

因此,要使PHP成功使用webhook设置,您必须返回 hub_challenge 参数.

So, for PHP to make a success with webhook setup you must return hub_challenge parameter.

使用令牌定义$ verify_token并添加类似内容:

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.

或者,如果您的Webhook已被钩住:

Or, if your webhook already hooked:

您应该跳过任何 read delivery 消息,例如:

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;
        }
    }
}

或者,您可以取消选择 message_reads &"Facebook页面设置/Webhooks"的页面订阅"部分的 message_deliveries 复选框.

Or, you can deselect message_reads & message_deliveries checkboxes in Page Subscription section of your Facebook Page Settings/Webhooks.

这篇关于WebHook中的无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆