简体   繁体   English

无法使用Botman为Facebook Messenger应用程序设置Webhook

[英]Unable to setup webhook for facebook messenger app with botman

When I try to setup webhook for my messenger bot based on Botman I get the following error: "The URL couldn't be validated. Response does not match challenge, expected value=...". 当我尝试基于Botman为我的Messenger bot设置webhook时,出现以下错误:“ URL无法验证。响应与质询不匹配,期望值= ...”。

The issue seems to be related to Botman, because there's no problem setting webhook with other PHP bot. 这个问题似乎与Botman有关,因为与其他PHP机器人一起设置webhook没问题。

I've tried with my bot placed both on localhost (with ngrok as suggested in Botman docs) and public hosting with https and ssl - none of these worked. 我已经尝试过将我的机器人放置在localhost(如Botman文档中所建议的使用ngrok)和使用https和ssl的公共托管中,但这些都不起作用。 I have tried solutions found here https://christoph-rumpel.com/2017/09/botman-quick-tip-how-to-debug-facebook-webhook-errors/ with no success. 我尝试了在这里找到的解决方案https://christoph-rumpel.com/2017/09/botman-quick-tip-how-to-debug-facebook-webhook-errors/没有成功。

Here's my code: 这是我的代码:

require __DIR__ . '/vendor/autoload.php';

use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;

$config = [
    'facebook' => [
    'token' => 'my_token',
    'app_secret' => 'my_secret',
        'verification'=>'my_verification',
    ]
];

DriverManager::loadDriver(\BotMan\Drivers\Facebook\FacebookDriver::class);

$botman = BotManFactory::create($config);

$botman->hears('hello', function (BotMan $bot) {
    $bot->reply('Hello yourself.');
});

$botman->listen();

Any thoughts appreciated. 任何想法表示赞赏。

Have been stuck on it for a while until accidentally I stumbled upon solution. 坚持了一段时间,直到我偶然偶然发现了解决方案。 The problem was wrong PHP version; 问题是错误的PHP版本。 since BotMan requires >= 7.1, so I updated from 7.0 to 7.2 and was convinced I had it running. 因为BotMan需要> = 7.1,所以我从7.0更新到7.2,并确信我已经在运行它。 I checked terminal php -v and it showed 7.2, but checking phpinfo() for some other issue I noticed PHP version was 7.0 我检查了终端php -v ,结果显示为7.2,但检查phpinfo()时发现了其他问题,我发现PHP版本是7.0

In other words, while updating PHP you need to update it also for your Apache server, otherwise it will keep using old version. 换句话说,在更新PHP时,您还需要为Apache服务器更新它,否则它将继续使用旧版本。

Check the following links on how to do it. 查看以下链接以了解如何操作。

https://askubuntu.com/questions/902637/how-can-i-upgrade-my-php-version https://askubuntu.com/questions/902637/how-can-i-upgrade-my-php-version

https://tecadmin.net/switch-between-multiple-php-version-on-ubuntu/ https://tecadmin.net/switch-between-multiple-php-version-on-ubuntu/

When uploading chatbot to public hosting remember to check PHP version there too - I spent some time frustrated by that same error before I remembered to check my hosting PHP version and update it accordingly. 将chatbot上传到公共托管服务器时,请记住也要检查PHP版本-我花了一些时间对同样的错误感到沮丧,然后才记得检查托管的PHP版本并进行相应的更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM