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.
You may choose to set up multiple slack commands. On the integrations settings on slack.com you should let them all point to the url you configured in app/config/laravel-slack-slash-command.
Image you've created two slack commands /jaime and /johnsnow
namespace App\SlashCommandHandlers;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
class Jaime extends BaseHandler
{
public function canHandle(Request $request): bool
{
return $request->command == 'jaime';
}
public function handle(Request $request): Response
{
return $this->respondToSlack("A Lannister always pays his debts");
}
}
namespace App\SlashCommandHandlers;
use Spatie\SlashCommand\Request;
use Spatie\SlashCommand\Response;
class JohnSnow extends BaseHandler
{
public function canHandle(Request $request): bool
{
return $request->command == 'johnsnow';
}
public function handle(Request $request): Response
{
return $this->respondToSlack("I know nothing");
}
}
You'll see a response A Lannister always pays his debts after issueing the /jaime command, and I know nothing after issuing the /johnsnow command.
How can I help you explore Laravel packages today?