symfony/discord-notifier
Symfony Notifier bridge for Discord. Configure via DISCORD_DSN for webhooks or a bot token, then send ChatMessage notifications. Supports rich embeds and options (username, title, fields, thumbnails, footers) to build interactive Discord messages.
spatie/laravel-notification-channels-discord acts as a bridge). For a Laravel-based stack, this requires either:
DISCORD_DSN=discord://TOKEN@default). Bot support is newer (added in Symfony 8.0) and may require additional testing.spatie/laravel-notification-channels-discord (10–30 mins to integrate) if you only need basic notifications.symfony/notifier (already in use).DISCORD_DSN or bot tokens in .env (use Laravel’s Vault or Symfony’s ParameterBag for secrets).| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Laravel Integration | Non-native Symfony package may require workarounds or additional layers (e.g., Notification Channels). | Pilot with spatie/laravel-notification-channels-discord first; fall back to custom transport if needed. |
| Bot vs. Webhook | Bot transport (discord+bot://) is newer (Symfony 8.0+) and may have edge cases. |
Test both transports in staging; prefer webhooks for simplicity unless bot features (e.g., message editing) are critical. |
| Rate Limits | Discord API enforces rate limits. Long messages or high-volume alerts may trigger throttling. | Implement exponential backoff in the transport layer (Symfony Notifier supports retry strategies). Monitor Discord’s API status page. |
| Embed Complexity | Overly complex embeds (e.g., nested fields, large media) may fail silently or truncate. | Validate embeds against Discord’s specs in tests; use try-catch for API errors. |
| Deprecation Risk | Symfony Notifier is stable, but Discord’s API may change (e.g., webhook format, embed limits). | Subscribe to Symfony’s RFCs and Discord’s API changelog; plan for backward-compatible updates. |
| Error Handling | Limited native support for failure modes (e.g., retries, dead-letter queues). | Extend Symfony’s Transport to include custom failure handlers (e.g., log to Sentry, store failed messages in DB). |
| Testing | Mocking Discord API responses requires HTTP clients (e.g., Guzzle). | Use symfony/panther or pest for browser-based testing; mock HTTP calls in unit tests. |
discordphp or Laravel Discord.spatie/laravel-notification-channels-discord or build a custom channel.DISCORD_DSN/bot tokens be stored?
Vault or Symfony’s ParameterBag with encryption.Transport to emit events (e.g., discord.notification.sent).| Component | Fit Level | Notes |
|---|---|---|
| Laravel | Medium | Not native; requires spatie/laravel-notification-channels-discord or custom transport. |
| Symfony | High | Designed for Symfony Notifier; minimal integration effort. |
| PHP 8.4+ | High | Required for Symfony 8.x (bot transport). Laravel 10+ supports this. |
| Composer | High | Standard PHP package management. |
| Discord API | High | Uses official webhook/bot endpoints; no custom API needed. |
| Database | Low | No schema changes, but may need a table for failed notifications (if implementing retries). |
| Queue Systems | Medium | Symfony Notifier supports queues (e.g., Symfony Messenger, Laravel Queues); useful for high-volume alerts. |
| Monitoring | Medium | Requires custom instrumentation (e.g., Prometheus metrics for delivery rates). |
composer require spatie/laravel-notification-channels-discord
.env:
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/ID/TOKEN
use App\Notifications\DiscordAlert;
use Illuminate\Notifications\Notification;
class DiscordAlert extends Notification {
public function via($notifiable) {
return ['DiscordChannel'];
}
public function toDiscord($notifiable) {
return (new ChatMessage())
->content('New alert!')
->discordOptions(function ($options) {
$options->username('App Bot')
->addEmbed(...);
});
}
}
$user->notify(new DiscordAlert());
composer require symfony/notifier discord-notifier
config/packages/notifier.yaml:
notifier:
chat:
discord:
dsn: '%env(DISCORD_DSN)%'
options:
username: 'App Bot'
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\NotifierInterface;
$message = (new ChatMessage('Hello Discord!'))
->options((new DiscordOptions())
->addEmbed((new DiscordEmbed())
->title('Test')
->description('This is a rich embed.')
)
);
$notifier->send($message);
How can I help you explore Laravel packages today?