php - WebHook 中的无限循环

标签 php webhooks facebook-messenger

我正在做一个 facebook 信使机器人。启动它后,它会调用 WebHook。 不幸的是,在第一次启动后不会停止使用相同的参数抛出相同的调用。 设置是:

  • 消息传递;
  • message_reads;
  • 消息;
  • messaging_optins;
  • messaging_postbacks。

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

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

最佳答案

根据你的代码,我决定你不能设置你的 webhook,所以来自 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.

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

使用您的 token 定义 $verify_token 并添加如下内容:

if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] == 'subscribe' && $_REQUEST['hub_verify_token'] == $verify_token) {

    // Webhook setup request
    echo $_REQUEST['hub_challenge']; exit;
}

设置成功后,您可以从脚本中删除此代码。

或者,如果您的 webhook 已经 Hook :

您应该跳过任何已读已发送 消息,如下所示:

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

或者,您可以在 Facebook 页面设置/Webhooks 的页面订阅部分中取消选择 message_readsmessage_deliveries 复选框。

关于php - WebHook 中的无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39377533/

相关文章:

php - Ajax 从第二个选择和数据库中提取信息

php - 使用设置 ID 从 MySQLi 获取数据不起作用

azure - 阿尔戈事件: Exposing Webhook Through a K8s Load Balancer on Azure Subnet

javascript - 是否保证在客户端智能支付按钮 .then() *之后触发 webhook?

c# - Bot Framework 无法使用 AddKeyboardCard 或使用 ChannelData 发送 FacebookQuickReply

Facebook 页面通知从聊天机器人到代理的 pass_thread_control

Facebook Messenger Webhook 持续发送消息

php - MySQL:按时间戳分组

php - @_ -1 在 Perl 中是什么意思?

github - 当您 fork 的项目得到更新时,是否有 Github webhook 事件?