Search code examples
phpfacebook-apps

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=...".

The issue seems to be related to Botman, because there's no problem setting webhook with other PHP bot.

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. I have tried solutions found here https://christoph-rumpel.com/2017/09/botman-quick-tip-how-to-debug-facebook-webhook-errors/ with no success.

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.


Solution

  • Have been stuck on it for a while until accidentally I stumbled upon solution. The problem was wrong PHP version; since BotMan requires >= 7.1, so I updated from 7.0 to 7.2 and was convinced I had it running. I checked terminal php -v and it showed 7.2, but checking phpinfo() for some other issue I noticed PHP version was 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.

    Check the following links on how to do it.

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

    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.