Installation and Setup
In order to use this package you’ll need to setup a slash command. Head over to the create apps page at slack.com to get started. There click “slash commands” and on the next page click “Create new command”.
You should now be on a screen that looks like this.
These are things you’ll need to do:
- In the
url you should type the domain name of your Laravel app followed by one or more segments. In the screenshot we’ve added a
slack segment. You can choose any segment you want. You’ll also need to specify this later on in the config file of the package.
POST in the
If you would like to test your Slash command locally, you can use ngrok (for example with
valet share) to generate an url. Be aware that you should reinstall your app if the ngrok url expires.
After you created your slash command you can head over to “Basic information” and copy the
Verification Token. You need this for the
SLACK_SLASH_COMMAND_VERIFICATION_TOKEN value in your .env
The package can be installed in your Laravel app via composer:
composer require spatie/laravel-slack-slash-command
Next, you must install the service provider:
// config/app.php 'providers' => [ ... Spatie\SlashCommand\SlashCommandServiceProvider::class, ];
You can publish the config file with this command:
php artisan vendor:publish --provider="Spatie\SlashCommand\SlashCommandServiceProvider" --tag="config"
This is the contents of the published config file:
return [ /* * Over at Slack you can configure to which url the slack commands must be send. * url here. You must specify that. Be sure to leave of the domain name. */ '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 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, ], ];