spatie/laravel-slack-slash-command
Build Slack slash commands in Laravel. Define handlers to validate and process incoming Slack requests, reply within 3 seconds or dispatch jobs for longer work, and send structured responses back to Slack. Includes request/response helpers and simple routing of commands.
This package makes it easy to make your Laravel app respond to Slack's Slash commands.
Once you've setup your Slash command over at Slack and installed this package into a Laravel app you can create handlers that can handle a slash command. Here's an example of such a handler that will send a response back to 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](https://github.com/param) \Spatie\SlashCommand\Request $request
*
* [@return](https://github.com/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](https://github.com/param) \Spatie\SlashCommand\Request $request
*
* [@return](https://github.com/return) \Spatie\SlashCommand\Response
*/
public function handle(Request $request): Response
{
return $this->respondToSlack("You have typed this text: `{$request->text}`");
}
}
The package also provides many options to format a response. It also can respond to Slack from within a queued job.
How can I help you explore Laravel packages today?