symfony/slack-notifier
Symfony Slack Notifier lets your app send notifications to Slack via Symfony Notifier. Configure Slack webhook or token-based transport, then deliver messages from your code and notification system with a consistent API alongside other channels.
slack://TOKEN@default?channel=CHANNEL), which is clean and configurable. This can be adapted to Laravel’s .env configuration.ChatMessage to Laravel’s Notification structure (e.g., mapping SlackOptions to Laravel’s array payload)..env can store SLACK_DSN (e.g., SLACK_DSN=slack://xoxb-...@default?channel=alerts).Notification system expects channel-specific configurations (e.g., SlackChannel::class), so the DSN may need parsing in a custom channel driver.symfony/notifier), which is ~20MB (composer dependency).require symfony/notifier.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Laravel Integration | No native Laravel support; requires custom channel driver. | Build a Laravel Notification Channel that bridges Symfony Notifier. |
| DSN Parsing | Laravel’s .env may not directly support DSN syntax. |
Parse DSN in a Service Provider or Channel class (e.g., SlackDsnParser). |
| BlockKit Complexity | Rich formatting (buttons, blocks) adds complexity to message composition. | Use helper methods in the channel driver to simplify Slack message building. |
| Error Handling | Slack API errors (e.g., invalid token, rate limits) need graceful handling. | Implement retry logic (Symfony Notifier supports this) and fallback logging. |
| PHP Version | Requires PHP 8.1+ (Symfony 6.4+) but Laravel 10+ supports this. | Ensure Laravel app is on PHP 8.1+ (LTS). |
| Testing | Mocking Slack API responses in tests may be cumbersome. | Use Slack’s mock API or Pest/Laravel’s HTTP testing for integration tests. |
spatie/laravel-slack-notification)..env use SLACK_DSN or split into SLACK_TOKEN and SLACK_CHANNEL?Notification system may need customization.guzzlehttp/slack) to avoid duplication.// app/Providers/AppServiceProvider.php
use Symfony\Component\Notifier\Notifier;
use Symfony\Component\Notifier\Bridge\Slack\SlackTransport;
use Illuminate\Support\Facades\Notification;
public function boot()
{
// Register Symfony Notifier with Slack transport
$notifier = new Notifier([
new SlackTransport(config('services.slack.dsn'), 'default'),
]);
// Wrap in a Laravel Notification Channel
Notification::extend('slack', function ($app) use ($notifier) {
return new class($notifier) implements NotificationChannel {
public function __construct(private Notifier $notifier) {}
public function send($notifiable, array $data) {
$message = new \Symfony\Component\Notifier\Message\ChatMessage(
$data['message']
);
if (isset($data['options'])) {
$message->options($data['options']);
}
$this->notifier->send($message);
}
};
});
}
.env:
SLACK_DSN=slack://xoxb-...@default?channel=alerts
SLACK_TOKEN=xoxb-...
SLACK_CHANNEL=alerts
(Requires parsing in the channel driver.)SlackChannel that uses Symfony Notifier.| Component | Compatibility Notes |
|---|---|
| Laravel 10+ | ✅ PHP 8.1+ required (Laravel 10+ supports this). |
| Symfony Notifier | ✅ Standalone usage possible (no full Symfony needed). |
| Slack API | ✅ Uses official Slack BlockKit API. |
| Existing Slack Code | ⚠️ May need refactoring if using direct HTTP clients (e.g., Guzzle). |
| Queue Workers | ✅ Symfony Notifier supports queues (e.g., Symfony Messenger). |
composer require symfony/notifier
.env and parse in a Service Provider.NotificationChannel to use Symfony Notifier.composer.json..env.
SlackOptions validator or pre-flightHow can I help you explore Laravel packages today?