- How do I install and configure this package in Laravel?
- Run `composer require symfony/rocket-chat-notifier`, then configure it via a DSN string in your `.env` (e.g., `ROCKETCHAT_DSN=rocketchat://TOKEN%2FCHANNEL@your-rocketchat-host`). Laravel’s config system can map this to a `rocket_chat.php` file for easier access. Ensure your RocketChat webhook is set up first.
- Does this package work with Laravel’s default Guzzle HTTP client?
- Yes, but it primarily relies on Symfony’s HTTP client. If you prefer Guzzle, wrap the package’s HTTP client in a Guzzle-compatible adapter or use Laravel’s HTTP client facade to bridge the gap. The package’s core functionality remains the same.
- What Laravel versions are officially supported?
- The package targets Symfony 7+, which aligns best with Laravel 10+. Laravel 9.x may work but could require polyfills for Symfony 7 dependencies. For Laravel 8 or older, integration may need significant refactoring due to Symfony component version mismatches.
- Can I send custom payloads or attachments with messages?
- Yes, use the `RocketChatOptions` class to override defaults like bot alias, avatar, or channel. Attachments support rich formatting (e.g., colors, titles, text) and multiple attachments. The payload is processed by a Rocket.Chat Incoming Webhook Script, giving you full control over message structure.
- How do I handle API errors or rate limits in production?
- The package lacks built-in retry logic, so wrap calls in Laravel’s queue system or use middleware to handle retries and errors. For rate limits, implement exponential backoff in your queue jobs or use Laravel’s `retry-after` logic.
- Is there support for real-time updates or WebSocket interactions?
- No, this package focuses on HTTP-based notifications via webhooks. For real-time features (e.g., live chat), you’ll need to integrate RocketChat’s WebSocket API separately, likely using a custom Laravel service or a dedicated package.
- Can I trigger RocketChat messages from Laravel events or queues?
- Absolutely. Inject the notifier into Laravel’s service container and bind it to events (e.g., `OrderShipped`). For queues, dispatch a job that uses the notifier to send messages asynchronously, improving performance for high-volume notifications.
- What authentication methods does this package support?
- The package defaults to webhook tokens (via DSN) but can be extended for API keys or OAuth. Store credentials securely in Laravel’s `.env` or a secrets manager. Ensure your RocketChat instance is configured to accept the chosen authentication method.
- Are there PHPUnit tests for this package? How can I test it in Laravel?
- The package includes tests for core functionality, but you’ll need to write integration tests in Laravel to verify DSN parsing, payload formatting, and error handling. Mock the HTTP client or use Laravel’s HTTP tests to simulate RocketChat responses.
- What alternatives exist if I don’t want to use this package?
- For lightweight needs, use Guzzle directly to call RocketChat’s API. For other platforms, Laravel’s native Slack or Teams notifiers are simpler. If RocketChat isn’t critical, consider Pusher for real-time features or Laravel’s built-in notifications for email/SMS.