- How do I integrate Symfony Telegram Notifier with Laravel?
- Use the `spatie/laravel-symfony-notifier` package to bridge Symfony Notifier with Laravel. Install it via Composer, configure your `.env` with `TELEGRAM_DSN=telegram://TOKEN@default?channel=CHAT_ID`, then dispatch notifications using Laravel’s `Notifiable` trait or Symfony’s `ChatterInterface`.
- What Laravel versions support Symfony Telegram Notifier?
- The package requires PHP 8.1+ and works with Laravel 10+. For Laravel 9 or older, ensure compatibility with Symfony Notifier v6.0+ via `spatie/laravel-symfony-notifier`. Test thoroughly, as some Laravel features may not align with Symfony’s Notifier architecture.
- Can I send interactive messages with buttons or callbacks?
- Yes, use the `TelegramOptions` class to add inline buttons, URLs, or callback queries. Configure webhooks in Laravel’s `routes/web.php` to handle callback responses. Example: `->replyMarkup((new InlineKeyboardMarkup())->inlineKeyboard([...]))`.
- How do I handle Telegram’s API rate limits in production?
- Leverage Laravel’s queue system (`queue:work`) to batch notifications and implement exponential backoff for retries. Monitor failed jobs via `queue:failed` and log errors. Symfony Notifier abstracts rate limits but doesn’t enforce them—your app must handle throttling.
- What’s the best way to configure the Telegram bot token securely?
- Store the token in Laravel’s `.env` as `TELEGRAM_DSN=telegram://TOKEN@default?channel=CHAT_ID`. Avoid hardcoding. Use Laravel’s `env()` helper or Symfony’s `ParameterBag` to access it dynamically. Never commit `.env` to version control.
- Does this package support sending media like images or documents?
- Yes, but Telegram imposes file size limits (e.g., 50MB for documents). Pre-process large files (resize images, compress logs) before sending. Use `ChatMessage` with file paths or URLs, and handle API errors for oversized media in your Laravel exception handler.
- Can I use a local Telegram API server instead of the official one?
- Yes, modify the DSN to point to your local server: `telegram://TOKEN@localhost:5001?channel=CHAT_ID&sslmode=disable`. Disable SSL only if your local server uses HTTP. For security, use a TLS-termination proxy in production to avoid unencrypted traffic.
- How do I fallback to email/SMS if Telegram fails?
- Symfony Notifier supports multi-channel fallbacks natively. Configure a secondary channel (e.g., email) in your Laravel `Notifiable` trait or Symfony `Notifier` setup. Use `->fallback()` in your notification logic to chain channels.
- What’s the difference between `channel` and `chat_id` in the DSN?
- Both refer to the Telegram chat target, but `channel` is the DSN parameter name. Use a negative `chat_id` (e.g., `-123456789`) for groups or channels. Example: `?channel=-123456789`. Verify the ID via Telegram’s `getUpdates` API or bot commands.
- Are there alternatives to Symfony Telegram Notifier for Laravel?
- Yes, consider `spatie/laravel-telegram-bot` for bot-specific features or `guzzlehttp/guzzle` for direct Telegram API calls. However, Symfony Notifier offers richer integration with Laravel’s ecosystem (e.g., queues, fallbacks) and supports interactive elements out of the box.