symfony/gitter-notifier
Symfony Notifier integration for Gitter. Configure a GITTER_DSN with your Gitter token and room ID (gitter://TOKEN@default?room_id=ROOM_ID) to send notifications to a Gitter room via the Symfony Notifier system.
Installation
composer require symfony/gitter-notifier
Ensure your project uses Symfony HTTP Client (or integrate with Laravel HTTP Client if preferred).
First Use Case: Sending a Notification
use Symfony\Component\Notifier\Notifier;
use Symfony\Component\Notifier\Bridge\Gitter\GitterTransport;
use Symfony\Component\Notifier\Message\ChatMessage;
$notifier = new Notifier();
$transport = new GitterTransport('YOUR_GITTER_WEBHOOK_URL');
$message = (new ChatMessage('Hello from Laravel!'))
->from('Laravel App')
->to('YOUR_ROOM_ID');
$notifier->send($message);
Key Files to Review
vendor/symfony/notifier/src/Bridge/Gitter/GitterTransport.php (Core transport logic)vendor/symfony/notifier/src/Message/ChatMessage.php (Message formatting)Service Provider Setup
// app/Providers/GitterNotifierServiceProvider.php
public function register()
{
$this->app->singleton('gitter.notifier', function ($app) {
return new Notifier([
new GitterTransport(config('services.gitter.webhook')),
]);
});
}
Configurable Webhook
// config/services.php
'gitter' => [
'webhook' => env('GITTER_WEBHOOK_URL'),
'default_room' => env('GITTER_DEFAULT_ROOM'),
],
Usage in Controllers/Jobs
use Illuminate\Support\Facades\Gitter;
public function deploySuccess()
{
Gitter::send(new ChatMessage('Deployment successful!'))
->to(config('services.gitter.default_room'));
}
$message = (new ChatMessage('**Bold** text and [links](https://laravel.com)'))
->mention('@team');
try-catch to log failures silently.queue:work) to avoid hitting Gitter API limits.Webhook URL Validation
curl -X POST -H "Content-Type: application/json" -d '{}' YOUR_WEBHOOK_URL.config('services.gitter.webhook') and validate it in AppServiceProvider boot method.Message Length Limits
Str::limit() to preview content:
$message = Str::limit($longText, 500) . ' (truncated)';
Room/Channel Permissions
403 Forbidden errors.$notifier = new Notifier([$transport], [
'debug' => env('APP_DEBUG', false),
]);
$transport->setLogger($this->app->make('log'));
Custom Message Types
Extend ChatMessage for Laravel-specific payloads:
class LaravelChatMessage extends ChatMessage
{
public function withLaravelData(array $data): self
{
$this->context['laravel'] = $data;
return $this;
}
}
Middleware for Notifications Add pre-send logic (e.g., sanitization):
$transport->setOnSend(function (ChatMessage $message) {
$message->html(Str::markdown($message->html()));
});
Environment-Specific Webhooks
Use Laravel's env() with fallbacks:
$webhook = env('GITTER_PROD_WEBHOOK', env('GITTER_STAGING_WEBHOOK'));
How can I help you explore Laravel packages today?