larament / barta
Barta is a Laravel package designed to integrate popular Bangladeshi SMS gateways seamlessly.
Fund package maintenance!
iRaziul
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 39
Watchers: 1
Forks: 5
Open Issues: 0
pkg:composer/larament/barta
Requires
- php: ^8.4
- illuminate/contracts: ^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^10.0.0||^9.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
README
Barta (কথা)
The unified interface for every Bangladeshi SMS gateway.
Barta is a clean, expressive Laravel package designed to integrate popular Bangladeshi SMS gateways seamlessly. Whether you're sending OTPs, marketing alerts, or notifications, Barta makes the process as simple as a conversation.
✨ Features
- Multiple Gateways — Seamlessly switch between SMS providers
- Bulk SMS — Send to multiple recipients in a single call
- Queue Support — Dispatch SMS to background jobs
- Laravel Notifications — Native integration with Laravel's notification system
- BD Phone Formatting — Automatic phone number normalization to
8801XXXXXXXXXformat - Extensible — Create custom drivers for any SMS gateway
📦 Supported Gateways
| Gateway | Driver | Status |
|---|---|---|
| Log (Development) | log |
✅ Built-in |
| eSMS | esms |
✅ Supported |
| MimSMS | mimsms |
✅ Supported |
| SSL Wireless | ssl |
✅ Supported |
| Grameenphone | grameenphone |
✅ Supported |
| Banglalink | banglalink |
✅ Supported |
| Robi | robi |
✅ Supported |
| Infobip | infobip |
✅ Supported |
| ADN SMS | adnsms |
✅ Supported |
| Alpha SMS | alphasms |
✅ Supported |
| GreenWeb | greenweb |
✅ Supported |
| BulkSMS BD | bulksms |
✅ Supported |
| ElitBuzz | elitbuzz |
✅ Supported |
| SMS NOC | smsnoc |
✅ Supported |
Want more gateways? Request a gateway or contribute a driver.
🚀 Installation
Install via Composer:
composer require larament/barta
Run the install command (publishes config + optional setup):
php artisan barta:install
⚙️ Configuration
Set your default driver and add credentials to .env:
BARTA_DRIVER=ssl # Example: SSL Wireless BARTA_SSL_TOKEN=your-api-token BARTA_SSL_SENDER_ID=your-sender-id
Each gateway requires different credentials. See config/barta.php for all available options and environment variable names.
💡 Tip: Use
logdriver during development to avoid sending real SMS.
🛠 Usage
Basic Usage
use Larament\Barta\Facades\Barta; // Send SMS using the default driver Barta::to('01712345678') ->message('Your OTP is 1234') ->send();
Specifying a Driver
// Use a specific gateway Barta::driver('esms') ->to('01712345678') ->message('Hello from eSMS!') ->send();
Bulk SMS
Send to multiple recipients in a single API call:
Barta::to(['01712345678', '01812345678', '01912345678']) ->message('Hello everyone!') ->send();
Getting the Response
$response = Barta::to('01712345678') ->message('Hello!') ->send(); // Check if successful if ($response->success) { // Access raw API response $data = $response->data; } // Convert to array $array = $response->toArray(); // ['success' => true, 'data' => [...], 'errors' => []]
⏱️ Queue Support
Dispatch SMS to your queue for background processing:
// Queue with default settings Barta::to('01712345678') ->message('This will be queued') ->queue(); // Specify queue name Barta::to('01712345678') ->message('Priority message') ->queue('sms'); // Specify connection and queue Barta::to('01712345678') ->message('Redis queue') ->queue('sms', 'redis'); // Bulk queued SMS Barta::to(['01712345678', '01812345678']) ->message('Queued bulk message') ->queue();
🔔 Laravel Notifications
Barta integrates seamlessly with Laravel's notification system.
1. Create a Notification
use Illuminate\Notifications\Notification; use Larament\Barta\Notifications\BartaMessage; class OrderShipped extends Notification { public function via($notifiable): array { return ['barta']; } public function toBarta($notifiable): BartaMessage { return new BartaMessage( "Hi {$notifiable->name}, your order has been shipped!" ); } }
2. Add Route to Your Model
// app/Models/User.php public function routeNotificationForBarta($notification): string { return $this->phone; }
3. Send the Notification
$user->notify(new OrderShipped());
Using a Specific Driver
Override the default driver per notification:
class OrderShipped extends Notification { public function toBarta($notifiable): BartaMessage { return new BartaMessage('Your order shipped!'); } // Optional: specify driver for this notification public function bartaDriver(): string { return 'mimsms'; } }
🔧 Creating Custom Drivers
Extend Barta to support any SMS gateway.
1. Create the Driver Class
namespace App\Sms\Drivers; use Illuminate\Support\Facades\Http; use Larament\Barta\Drivers\AbstractDriver; use Larament\Barta\Data\ResponseData; use Larament\Barta\Exceptions\BartaException; class CustomGatewayDriver extends AbstractDriver { public function send(): ResponseData { $this->validate(); $response = Http::withToken($this->config['api_token']) ->post('https://api.customgateway.com/sms', [ 'to' => implode(',', $this->recipients), 'message' => $this->message, 'sender' => $this->config['sender_id'], ]) ->json(); if ($response['status'] !== 'success') { throw new BartaException($response['error']); } return new ResponseData( success: true, data: $response, ); } }
2. Register the Driver
// app/Providers/AppServiceProvider.php use App\Sms\Drivers\CustomGatewayDriver; use Larament\Barta\Facades\Barta; public function boot(): void { Barta::extend('custom', function ($app) { return new CustomGatewayDriver(config('barta.drivers.custom')); }); }
3. Add Configuration
// config/barta.php 'drivers' => [ // ...existing drivers... 'custom' => [ 'api_token' => env('CUSTOM_SMS_TOKEN'), 'sender_id' => env('CUSTOM_SMS_SENDER_ID'), ], ],
4. Use Your Driver
Barta::driver('custom') ->to('01712345678') ->message('Hello from custom gateway!') ->send();
📞 Phone Number Formatting
Barta automatically normalizes Bangladeshi phone numbers to the 8801XXXXXXXXX format:
| Input | Output |
|---|---|
1712345678 |
8801712345678 |
01712345678 |
8801712345678 |
8801712345678 |
8801712345678 |
+8801712345678 |
8801712345678 |
017-1234-5678 |
8801712345678 |
Invalid numbers will throw a BartaException.
🧪 Testing
# Run tests composer test # Run tests with coverage composer test-coverage # Run static analysis composer analyse
Testing in Your Application
Use the log driver during testing to avoid sending real SMS:
// phpunit.xml or .env.testing BARTA_DEFAULT_DRIVER=log
Changelog
Please see CHANGELOG.md for more information on what has changed recently.
Contributing
Please see CONTRIBUTING.md for details.
Security Vulnerabilities
Please see our security policy for details on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see LICENSE.md for more information.
Made with ❤️ for the Bangladeshi Laravel Community