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.
namespaceApp\SlashCommandHandlers;
useApp\SlashCommand\BaseHandler;
useSpatie\SlashCommand\Request;
useSpatie\SlashCommand\Response;
classCatchAllextendsBaseHandler
{
/**
* If this function returns true, the handle method will get called.
*
* @param\Spatie\SlashCommand\Request$request
*
* @returnbool
*/publicfunctioncanHandle(Request $request): bool
{
returntrue;
}
/**
* 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
*/publicfunctionhandle(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.