Search code examples
phplaravelroutesslackslack-api

connecting slack to botman in laravel on localhost


This is my routes file in laravel. Am matching any url with /botman that calls a closure which, registers a slack driver for botman and listens to the message hello. In slack am trying to set the Request URL under event subscriptions using this http://127.0.0.1:8000/botman. I get "Your URL didn't respond with the value of the challenge parameter.". What am I missing? is it on my routes file? or the url?

<?php
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\Drivers\Slack\SlackDriver;
use BotMan\BotMan\Drivers\DriverManager;

Route::match(['get', 'post'],'botman', function () {

    DriverManager::loadDriver(SlackDriver::class);

    // Create BotMan instance
    $config = [
            'slack' => [
                'token' => '***slack Token***' //slack token
                ]
            ];
    $botman = BotManFactory::create($config);

    // give the bot something to listen for.
    $botman->hears('hello', function (BotMan $bot) {
        $bot->reply('Hello yourself.');
    });

    // start listening
    $botman->listen();
});

Solution

  • You could try creating a tunnel to your local host using ngrok. It is likely that the connection fails because it requires an external endpoint. It will also have an error 500 because of this.

    Sometimes, these services send a test request to the endpoint (expecting an OK response) before sending the payload. You could also check whether that is a requirement from the Slack side.