简体   繁体   English

在本地主机上的 Laravel 中将 slack 连接到 botman

[英]connecting slack to botman in laravel on localhost

This is my routes file in laravel.这是我在 laravel 中的路由文件。 Am matching any url with /botman that calls a closure which, registers a slack driver for botman and listens to the message hello.我将任何 url 与调用闭包的 /botman 匹配,该闭包为 botman 注册一个 slack 驱动程序并收听消息 hello。 In slack am trying to set the Request URL under event subscriptions using this http://127.0.0.1:8000/botman .在 slack 中,我尝试使用http://127.0.0.1:8000/botman在事件订阅下设置Request URL I get "Your URL didn't respond with the value of the challenge parameter."我收到"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();
});

You could try creating a tunnel to your local host using ngrok.您可以尝试使用 ngrok 创建到本地主机的隧道。 It is likely that the connection fails because it requires an external endpoint.连接失败很可能是因为它需要一个外部端点。 It will also have an error 500 because of this.因此,它也会出现错误 500。

Sometimes, these services send a test request to the endpoint (expecting an OK response) before sending the payload.有时,这些服务会在发送有效负载之前向端点发送测试请求(期待 OK 响应)。 You could also check whether that is a requirement from the Slack side.您还可以检查这是否是 Slack 方面的要求。

You can not use localhost in your request URLs.您不能在请求 URL 中使用localhost Slack needs to open a request to your Slack app and this only works if your request URL can be reached from the Internet. Slack 需要向您的 Slack 应用程序打开一个请求,这仅在可以从 Internet 访问您的请求 URL 时才有效。

The recommended way to develop and run Slack apps locally is to use a secure VPN tunnel, like ngrok .在本地开发和运行 Slack 应用程序的推荐方法是使用安全的 VPN 隧道,如ngrok This tool will create a virtual URL and internally handle the communication to your local machine in a secure way.此工具将创建一个虚拟 URL,并以安全的方式在内部处理与本地计算机的通信。 Its a commercial tool, but there also is a free plan.它是一个商业工具,但也有一个免费计划。

You also want to make sure that you have a webserver running on your local machine.您还需要确保在本地计算机上运行网络服务器。

For more details on how to use ngrok with Slack check out the official tutorial: Using ngrok to develop locally for Slack .有关如何在 Slack 中使用 ngrok 的更多详细信息,请查看官方教程:使用 ngrok 为 Slack 进行本地开发

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

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