An example project.
Command handlers can be found in App\Providers\AppServiceProvider
:
<?php
namespace App\Providers;
use App\TestCommandHandler;
use Illuminate\Support\ServiceProvider;
use Nwilging\LaravelSlackBot\Contracts\Services\SlackCommandHandlerFactoryServiceContract;
class AppServiceProvider extends ServiceProvider
{
protected const SLACK_COMMAND_HANDLERS = [
'laravel' => TestCommandHandler::class,
];
public function register()
{
/** @var SlackCommandHandlerFactoryServiceContract $slackCommandFactory */
$slackCommandFactory = $this->app->make(SlackCommandHandlerFactoryServiceContract::class);
foreach (static::SLACK_COMMAND_HANDLERS as $command => $handler) {
$slackCommandFactory->register($handler, $command);
}
}
}
An example command handler can be found at App\WeatherCommandHandler
:
<?php
declare(strict_types=1);
namespace App;
use Nwilging\LaravelSlackBot\Contracts\SlackCommandHandlerContract;
use Nwilging\LaravelSlackBot\Support\SlackCommandRequest;
use Symfony\Component\HttpFoundation\Response;
class WeatherCommandHandler implements SlackCommandHandlerContract
{
public function handle(SlackCommandRequest $commandRequest): Response
{
// Do something with the command request
return response(':construction_worker: Got it!');
}
}
For more information on this project, check out the blog post here.