WebHook 中的无限循环
infinite loop in a WebHook
我正在做一个 facebook 聊天机器人。启动它后,它会调用 WebHook。
不幸的是,在第一次启动后不会停止使用相同的参数抛出相同的调用。
设置为:
- message_deliveries;
- 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,您必须 return hub_challenge 参数。
使用您的令牌定义 $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 已经挂钩:
您应该跳过任何 read 和 delivery 消息,如下所示:
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 主页的主页订阅部分中的 message_reads & message_deliveries 复选框Settings/Webhooks.
我正在做一个 facebook 聊天机器人。启动它后,它会调用 WebHook。 不幸的是,在第一次启动后不会停止使用相同的参数抛出相同的调用。 设置为:
- message_deliveries;
- 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,您必须 return hub_challenge 参数。
使用您的令牌定义 $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 已经挂钩:
您应该跳过任何 read 和 delivery 消息,如下所示:
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 主页的主页订阅部分中的 message_reads & message_deliveries 复选框Settings/Webhooks.