- How do I integrate this package into a Laravel app that already uses Laravel Notifications?
- This package bridges Symfony Notifier, so you’ll need to wrap it in a Laravel Notification channel. Create a custom `MessageBirdChannel` that extends Laravel’s `Channel` and uses the Symfony Notifier transport under the hood. Configure the DSN in `.env` (e.g., `MESSAGEBIRD_DSN=messagebird://TOKEN@default?from=FROM`) and inject the Symfony Notifier client into your channel.
- What Laravel versions does this package support?
- The package itself is Symfony-focused, but it works with Laravel 8+ or 9+ if you use Symfony Notifier (v6+) as a dependency. Ensure your Laravel app’s Symfony components are version-compatible (e.g., `symfony/notifier:^6.0`). Test thoroughly, as Laravel’s native Notification facade isn’t directly supported—you’ll need a custom channel wrapper.
- Can I schedule SMS messages with this package?
- Yes, use the `MessageBirdOptions` class to set a `scheduledDatetime` (ISO 8601 format) when creating your `SmsMessage`. Example: `$options->scheduledDatetime('2024-12-31T23:59:59Z');`. The package forwards this to MessageBird’s API, which handles the scheduling server-side.
- How do I handle failed SMS deliveries or retries?
- Leverage Symfony’s Messenger component for retries or integrate with Laravel Queues. Configure a dead-letter queue (DLQ) in Symfony Messenger or use Laravel’s queue system to retry failed jobs. For logging, extend the transport to emit events or store failures in a database table. MessageBird’s `reportUrl` option can also notify a webhook on delivery status.
- Will this package work with Laravel’s queue system (database/redis) for async notifications?
- Indirectly, yes. Dispatch notifications as Laravel jobs (e.g., `SendSmsJob`) that use this package’s Symfony Notifier transport. Offload jobs to queues via `dispatch()` or `dispatchSync()`. For advanced retry logic, pair with Symfony Messenger’s transport or Laravel’s `ShouldQueue` interface. Avoid blocking HTTP requests in your queue workers.
- Are there alternatives to this package for sending SMS in Laravel?
- Yes. For MessageBird, consider `spatie/laravel-messagebird` (Laravel-native) or direct Guzzle HTTP calls. For other providers, Laravel’s built-in `Notification` channels (e.g., `NexmoChannel`, `TwilioChannel`) or packages like `laravel-notification-channels/mailgun` may fit better. This package is ideal if you’re already using Symfony Notifier or need MessageBird’s advanced options (e.g., scheduling, URL shortening).
- How do I test SMS notifications locally without hitting MessageBird’s API?
- Mock the Symfony Notifier transport in PHPUnit/Pest using Mockery or VCR (e.g., `vcr/vcr`). Stub the `MessageBirdTransport` to return fake responses. For Laravel, use `NotificationFake` to assert sent messages. Example: `$this->fake(Notification::class)->assertSent(MessageBirdChannel::class)`. Avoid hardcoding credentials in tests—use environment variables or a test-specific DSN.
- What are the security risks of using a DSN for MessageBird credentials?
- The DSN format (`messagebird://TOKEN@default?from=FROM`) embeds sensitive data. Store it in Laravel’s `.env` and restrict file permissions. Avoid committing `.env` to version control. For production, use Laravel Vault or a secrets manager (e.g., AWS Secrets Manager) to inject credentials dynamically. Never log the DSN or expose it in client-side code.
- Can I use this package for WhatsApp or email notifications via MessageBird?
- This package is SMS-focused, but MessageBird supports WhatsApp and email. For WhatsApp, use Symfony Notifier’s `ChatMessage` with MessageBird’s WhatsApp transport (if available). For email, consider Symfony Notifier’s built-in `SmtpTransport` or Laravel’s native `Mailable`. Check MessageBird’s API docs for unsupported channel transports—this package may need extension for non-SMS use cases.
- How do I monitor SMS delivery success/failure in production?
- Use MessageBird’s `reportUrl` option to post delivery status to a Laravel endpoint (e.g., `/api/sms-report`). Log these events to a database or queue for processing. For real-time monitoring, pair with Laravel Horizon to track queue jobs. Symfony Messenger’s stats or Laravel’s `failed_jobs` table can also help audit failures. Set up alerts (e.g., Slack) for repeated failures.