在本地主机上的laravel中将松弛连接到botman

时间:2018-10-17 08:36:12

标签: php laravel routes slack slack-api

这是我在laravel中的路线文件。将任何与/ botman匹配的URL匹配,该URL调用一个闭包,该闭包为botman注册一个松弛驱动程序并侦听消息hello。 闲暇时,我尝试使用此Request URL在事件订阅下设置http://127.0.0.1:8000/botman。我得到"Your URL didn't respond with the value of the challenge parameter."。我想念什么?在我的路线文件中吗?还是网址?

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

2 个答案:

答案 0 :(得分:1)

您可以尝试使用ngrok创建到本地主机的隧道。连接很可能因为需要外部端点而失败。因此也会出现错误500。

有时,这些服务在发送有效负载之前会将测试请求发送到端点(期望OK响应)。您还可以从Slack方面检查这是否是必需条件。

答案 1 :(得分:1)

您不能在请求URL中使用localhost。 Slack需要向您的Slack应用程序打开一个请求,只有在可以从Internet到达您的请求URL的情况下,这才起作用。

在本地开发和运行Slack应用程序的推荐方法是使用安全的VPN隧道,例如ngrok。该工具将创建一个虚拟URL,并在内部以安全的方式处理与本地计算机的通信。它是一种商业工具,但也有免费计划。

您还希望确保本地计算机上正在运行Web服务器。

有关如何在Slack中使用ngrok的更多详细信息,请查看官方教程:Using ngrok to develop locally for Slack