symfony/telegram-notifier
Provides Telegram integration for Symfony Notifier. Configure via a TELEGRAM_DSN with token and chat ID, send ChatMessages with TelegramOptions for parse mode, inline keyboards, and other Bot API settings, and optionally target a local API server.
spatie/laravel-symfony-notifier).telegram://TOKEN@default?channel=CHAT_ID), allowing easy configuration via environment variables or Laravel’s .env files.spatie/laravel-symfony-notifier (recommended).telegram://TOKEN@localhost:5001), useful for offline testing or air-gapped environments.| Risk Area | Mitigation Strategy |
|---|---|
| Symfony Dependency | Use spatie/laravel-symfony-notifier to avoid version conflicts. |
| Telegram API Changes | Monitor Telegram’s API updates and Symfony’s Notifier releases. |
| Security Risks | Avoid sslmode=disable in production; use TLS-termination proxies if needed. |
| Rate Limiting | Implement exponential backoff in Laravel’s notification queue (e.g., queue:failed). |
| Media Handling | Pre-process large files (e.g., resize images) to avoid API failures. |
| Callback Handling | Use Laravel’s webhook routes to process Telegram callback queries (requires additional setup). |
queue:failed table or custom logging.)| Component | Laravel Integration Path |
|---|---|
| Symfony Notifier | Use spatie/laravel-symfony-notifier (v1.0+). |
| Telegram Bot Token | Store in .env as TELEGRAM_DSN=telegram://TOKEN@default?channel=CHAT_ID. |
| Message Dispatch | Extend Laravel’s Notifiable trait or use Symfony’s ChatterInterface. |
| Webhooks (Optional) | For callbacks, route to routes/web.php and handle TelegramOptions::answerCallbackQuery(). |
| Queue System | Use Laravel Queues (queue:work) to batch notifications and handle rate limits. |
composer require spatie/laravel-symfony-notifier symfony/notifier-bridge-telegram
.env:
TELEGRAM_DSN=telegram://BOT_TOKEN@default?channel=-123456789
use Spatie\SymfonyNotifier\Notifier;
use Symfony\Component\Notifier\Message\ChatMessage;
$notifier = new Notifier();
$chatter = $notifier->getChatter('telegram');
$chatter->send(new ChatMessage('Hello from Laravel!'));
use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions;
use Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\InlineKeyboardMarkup;
$options = (new TelegramOptions())
->chatId('-123456789')
->parseMode('MarkdownV2')
->replyMarkup((new InlineKeyboardMarkup())->inlineKeyboard([/* buttons */]));
$message = new ChatMessage('Click me!');
$message->options($options);
$chatter->send($message);
// routes/web.php
Route::post('/telegram/callback', function (Request $request) {
$callbackQueryId = $request->input('callback_query.id');
$chatId = $request->input('callback_query.message.chat.id');
$options = (new TelegramOptions())
->chatId($chatId)
->answerCallbackQuery($callbackQueryId, showAlert: true);
$message = new ChatMessage('Callback handled!');
$message->options($options);
$chatter->send($message);
});
spatie/laravel-symfony-notifier and symfony/notifier-bridge-telegram for breaking changes..env and implement secure rotation (e.g., via laravel/envoy or secrets manager).queue:failed table or a custom log.TransportException to catch Telegram API failures.NOTIFIER_DEBUG=1 in .env).dd($message->options()) to inspect message payloads.// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('queue:work --sleep=3 --tries=3')->everyMinute();
}
How can I help you explore Laravel packages today?