spatie/laravel-slack-slash-command

让Laravel应用响应来自Slack的斜杠命令

1.12.0 2024-03-20 07:31 UTC

README

Latest Version on Packagist MIT Licensed Build Status Quality Score Total Downloads

此包使您的Laravel应用轻松响应Slack的斜杠命令

一旦您在Slack上设置好斜杠命令并将此包安装到Laravel应用中,您就可以创建处理斜杠命令的处理程序。以下是一个示例处理程序,它将向Slack发送响应。

namespace App\SlashCommandHandlers;

use App\SlashCommand\BaseHandler;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;

class CatchAll extends BaseHandler
{
    /**
     * If this function returns true, the handle method will get called.
     *
     * @param \Spatie\SlashCommand\Request $request
     *
     * @return bool
     */
    public function canHandle(Request $request): bool
    {
        return true;
    }

    /**
     * Handle the given request. Remember that Slack expects a response
     * within three seconds after the slash command was issued. If
     * there is more time needed, dispatch a job.
     * 
     * @param \Spatie\SlashCommand\Request $request
     * 
     * @return \Spatie\SlashCommand\Response
     */
    public function handle(Request $request): Response
    {
        return $this->respondToSlack("You have typed this text: `{$request->text}`");
    }
}

Spatie是一家位于比利时安特卫普的网页设计公司。您可以在我们的网站上找到所有开源项目的概述在这里

支持我们

我们在创建最佳开源包方面投入了大量资源。您可以通过购买我们的付费产品之一来支持我们。

我们非常感谢您从您家乡寄给我们明信片,并说明您正在使用我们的哪些包。您可以在我们的联系页面上找到我们的地址。我们将发布所有收到的明信片在我们的虚拟明信片墙上

安装

您可以通过composer安装此包

composer require spatie/laravel-slack-slash-command

必须安装此服务提供程序

// config/app.php
'providers' => [
    ...
    Spatie\SlashCommand\SlashCommandServiceProvider::class,
];

您可以使用以下命令发布配置文件

php artisan vendor:publish --provider="Spatie\SlashCommand\SlashCommandServiceProvider"

这是已发布文件的正文

return [

    /*
     * At the integration settings over at Slack you can configure the url to which the 
     * slack commands are posted. Specify the path component of that url here. 
     * 
     * For `http://example.com/slack` you would put `slack` here.
     */
    'url' => 'slack',

    /*
     * The token generated by Slack with which to verify if a incoming slash command request is valid.
     */
    'token' => env('SLACK_SLASH_COMMAND_VERIFICATION_TOKEN'),
    
    /*
     * The signing_secret generated by Slack with which to verify if a incoming slash command request is valid.
     */
    'signing_secret' => env('SLACK_SIGNING_SECRET'),

    /*
     * Verify requests from slack with signing_secret signature
     */
    'verify_with_signing' => false,

    /*
     * The handlers that will process the slash command. We'll call handlers from top to bottom
     * until the first one whose `canHandle` method returns true.
     */
    'handlers' => [
        //add your own handlers here


        //this handler will display instructions on how to use the various commands.
        Spatie\SlashCommand\Handlers\Help::class,

        //this handler will respond with a `Could not handle command` message.
        Spatie\SlashCommand\Handlers\CatchAll::class,
    ],
];

verify_with_signing参数更改为使用signing_secret验证来自Slack的请求

// config/laravel-slack-slash-command.php
'verify_with_signing' => true

文档

您可以在https://docs.spatie.be/laravel-slack-slash-command上找到文档。

如果您在使用此包时遇到困难、发现错误或对改进媒体库有一般性问题或建议,请随时在GitHub上创建问题,我们将尽快解决。

更新日志

请参阅CHANGELOG以获取有关最近更改的更多信息。

测试

$ composer test

贡献

请参阅CONTRIBUTING以获取详细信息。

安全性

如果您发现了关于安全性的错误,请通过security@spatie.be发送邮件,而不是使用问题跟踪器。

明信片软件

您可以使用此包,但如果它进入您的生产环境,我们非常感谢您从您家乡寄给我们明信片,并说明您正在使用我们的哪些包。

我们的地址是:Spatie,Kruikstraat 22,2018 安特卫普,比利时。

我们将所有收到的明信片发布在我们的公司网站上

鸣谢

消息和附件功能在很大程度上受到Regan McEntyre的Slack包的启发。

许可证

麻省理工学院许可证(MIT)。请参阅许可证文件获取更多信息。