无法使用 botman 为 facebook messenger 应用程序设置 webhook

Unable to setup webhook for facebook messenger app with botman

当我尝试基于 Botman 为我的 Messenger 机器人设置 webhook 时,出现以下错误:"The URL couldn't be validated. Response does not match challenge, expected value=..."。

这个问题似乎与 Botman 有关,因为与其他 PHP bot 设置 webhook 没有问题。

我已经尝试将我的机器人放在本地主机上(按照 Botman 文档中的建议使用 ngrok)和 public 使用 https 和 ssl 托管 - none 这些都有效。我已尝试在此处 https://christoph-rumpel.com/2017/09/botman-quick-tip-how-to-debug-facebook-webhook-errors/ 找到解决方案,但没有成功。

这是我的代码:

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();

任何想法表示赞赏。

一直坚持了一段时间,直到我偶然发现了解决方案。问题是PHP版本不对;因为 BotMan 要求 >= 7.1,所以我从 7.0 更新到 7.2 并确信我已经安装了它 运行。我检查了终端 php -v,它显示 7.2,但检查 phpinfo() 是否存在其他问题我注意到 PHP 版本是 7.0

换句话说,在更新 PHP 的同时,您还需要为您的 Apache 服务器更新它,否则它将继续使用旧版本。

查看以下链接了解如何操作。

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

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

将聊天机器人上传到 public 主机时,记得也检查那里的 PHP 版本 - 在我记得检查我的主机 PHP 版本和相应地更新它。