| Install | |
|---|---|
composer require ihabrouk/messenger |
|
| Latest Version: | v2.0.2 |
| PHP: | ^8.2|^8.3|^8.4 |
A comprehensive Laravel package for multi-provider messaging (SMS, WhatsApp) with FilamentPHP integration.
| Version | Laravel | Filament | PHP | Status |
|---|---|---|---|---|
| 2.x | 11.0+ | 4.0+ | 8.2+ | ✅ Active Development |
| 1.x | 10.0-11.x | 3.0+ | 8.1+ | 🔧 Maintenance |
# For new projects (recommended)
composer require "ihabrouk/messenger:^2.0"
# For projects using Filament v3
composer require "ihabrouk/messenger:^1.0"
You can install the package via composer:
composer require ihabrouk/messenger
# Publish and run migrations (REQUIRED)
php artisan vendor:publish --provider="Ihabrouk\Messenger\Providers\MessengerServiceProvider" --tag="messenger-migrations"
php artisan migrate
# Publish configuration
php artisan vendor:publish --provider="Ihabrouk\Messenger\Providers\MessengerServiceProvider" --tag="messenger-config"
If you encounter "Class not found" errors:
# Run diagnostic command
php artisan messenger:diagnose
# See emergency fix guide
# Check EMERGENCY_FIX.md for detailed troubleshooting
Publish the configuration file:
php artisan vendor:publish --tag="messenger-config"
Publish and run the migrations:
php artisan vendor:publish --tag="messenger-migrations"
php artisan migrate
Optionally, publish the views and language files:
php artisan vendor:publish --tag="messenger-views"
php artisan vendor:publish --tag="messenger-lang"
Add these variables to your .env file:
# Default Provider
MESSENGER_DEFAULT_PROVIDER=smsmisr
# SMS Misr Configuration
SMS_MISR_API_USERNAME=your_username
SMS_MISR_API_PASSWORD=your_password
SMS_MISR_SENDER_ID=your_sender_id
SMS_MISR_ENVIRONMENT=2 # 1 for Live, 2 for Test
# Twilio Configuration
TWILIO_ACCOUNT_SID=your_account_sid
TWILIO_AUTH_TOKEN=your_auth_token
TWILIO_FROM=your_phone_number
# Queue Configuration
MESSENGER_QUEUE_CONNECTION=redis
MESSENGER_QUEUE_NAME=messenger
# Analytics
MESSENGER_ANALYTICS_ENABLED=true
use Ihabrouk\Messenger\Facades\Messenger;
// Send a simple SMS
Messenger::send([
'recipient_phone' => '+1234567890',
'content' => 'Hello, this is a test message!',
'provider' => 'smsmisr', // optional
'channel' => 'sms' // optional
]);
// Send using templates
Messenger::sendFromTemplate('welcome_user', [
'recipient_phone' => '+1234567890',
'variables' => [
'user_name' => 'John Doe',
'company' => 'Acme Corp'
]
]);
use Ihabrouk\Messenger\Models\Batch;
$batch = Batch::create([
'name' => 'Newsletter Campaign',
'template_id' => $template->id,
'provider' => 'smsmisr',
'channel' => 'sms'
]);
$recipients = [
['phone' => '+1234567890', 'variables' => ['name' => 'John']],
['phone' => '+0987654321', 'variables' => ['name' => 'Jane']],
];
Messenger::bulkSend($batch, $recipients);
Add to your Filament resources:
use Ihabrouk\Messenger\Actions\SendMessageAction;
// In your table actions
SendMessageAction::make()
->phoneField('phone_number')
->nameField('full_name')
// config/messenger.php
'providers' => [
'smsmisr' => [
'driver' => 'smsmisr',
'username' => env('SMS_MISR_API_USERNAME'),
'password' => env('SMS_MISR_API_PASSWORD'),
'sender_id' => env('SMS_MISR_SENDER_ID'),
// ... other options
]
]
// config/messenger.php
'providers' => [
'twilio' => [
'driver' => 'twilio',
'account_sid' => env('TWILIO_ACCOUNT_SID'),
'auth_token' => env('TWILIO_AUTH_TOKEN'),
'from' => env('TWILIO_FROM'),
// ... other options
]
]
Create your own messaging provider:
php artisan messenger:make-driver CustomProvider
Manage templates through Filament admin or programmatically:
use Ihabrouk\Messenger\Models\Template;
Template::create([
'name' => 'welcome_sms',
'content' => [
'en' => 'Welcome {{name}}! Your account is ready.',
'ar' => 'مرحباً {{name}}! حسابك جاهز الآن.'
],
'channels' => ['sms'],
'category' => 'welcome'
]);
Access delivery analytics:
use Ihabrouk\Messenger\Services\AnalyticsService;
$analytics = app(AnalyticsService::class);
$stats = $analytics->getDeliveryStats('last_30_days');
Listen to messaging events:
use Ihabrouk\Messenger\Events\MessageSent;
Event::listen(MessageSent::class, function ($event) {
// Handle successful message sending
Log::info('Message sent', ['message_id' => $event->message->id]);
});
# Run this to diagnose installation issues
php artisan messenger:diagnose
php artisan messenger:diagnose # Diagnose installation issues
php artisan messenger:list-providers # List available providers
php artisan messenger:test-provider # Test provider configuration
php artisan messenger:send # Send a test message
composer test
If you discover any security-related issues, please email security@example.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
For support, email support@example.com or join our Discord channel.