tookantech / chapaar
This package provides a flexible way to send and verify messages through various SMS providers. It offers integration with multiple drivers, making it easy to use different SMS service providers without getting locked into a specific one.
Requires
- php: ^8.2|^8.1
- guzzlehttp/guzzle: ^7.5
- illuminate/contracts: ^11.0|^10.0
- laravel/framework: ^7.0|^8.0|^9.0|^10.0|^11.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9 | ^8.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^5.0|^6.0|^7.0|^8.0|^9.0
- pestphp/pest: ^1.22|^2.34
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpdoc-parser: ^1.15
- phpstan/phpstan: ^1.4.7
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
README
Chapaar offers flexible message sending and verification through multiple SMS providers, with easy integration and no lock-in to any specific provider.
Available Drivers
- kavenegar.com (tested)
- sms.ir (tested)
- ghasedak.me (tested)
- Farapayamk (not tested)
- Twillo (coming soon)
Installation
You can install the package via Composer:
composer require tookantech/chapaar
Configuration
You can publish the config file with:
php artisan vendor:publish --tag="chapaar-config"
This will create a chapaar.php configuration file in your config directory, where you can set the default driver and configure driver-specific settings.
This is the contents of the published config file:
return [ 'default' => env('CHAPAAR_DRIVER', 'kavenegar'), 'drivers' => [ 'kavenegar' => [ 'url' => 'https://api.kavenegar.com/v1/', 'api_key' => '', 'line_number' => '' ], 'smsir' => [ 'url' => 'https://api.sms.ir/v1/', 'api_key' => '', 'line_number' => '', ], 'ghasedak' => [ 'url' => 'https://api.ghasedak.me/v2/', 'api_key' => '', 'line_number' => '', ], ], ];
Usage
Using the Chapaar Facade
If you want to use the Chapaar package without Laravel's built-in notification system, you can utilize the Chapaar facade directly. This allows you to send and verify messages using different SMS providers.
Sending a Simple Message
use TookanTech\Chapaar\Facades\Chapaar; use TookanTech\Chapaar\SmsMessage; $message = (new SmsMessage())->driver() ->setFrom('12345678') ->setTo('0912111111') ->setContent('Hello, this is a test message.'); $response = Chapaar::send($message);
Sending With Template Message
use TookanTech\Chapaar\Facades\Chapaar; use TookanTech\Chapaar\SmsMessage; #Kavenegar $message =(new SmsMessage()) ->driver() ->setTemplate("invoice-paid") ->setTo('09121111111') ->setTokens([ '123', // token '456', // token2 '789', // token3 '111', // token10, with 4 space '222', // token20, with 8 space ]); # SmsIr $message =(new SmsMessage()) ->driver() ->setTemplate('invoice-paid') ->setTo('09121111111') ->setTokens([ 'code' => '123' // 'variable_name' => 'value' ]); # Ghasedak $message =(new SmsMessage()) ->driver() ->setTemplate("invoice-paid") ->setTo('09121111111') ->setTokens([ 'test1', // param1 'test2' // param2 ]); $response = Chapaar::verify($message);
Sending Without using default driver
use TookanTech\Chapaar\Facades\Chapaar; use TookanTech\Chapaar\SmsMessage; use TookanTech\Chapaar\Enums\Drivers; $message = (new SmsMessage()) ->driver(Drivers::SMSIR) ->setFrom('12345678') ->setTo('0912111111') ->setContent('Hello, this is a test message.'); $response = Chapaar::send($message);
Get Latest Outbox messages it automatically get the latest sent messages for default driver
$response = Chapaar::outbox(100);
Using In Notifications
Please review laravel notifications on how use notifications in laravel.
use TookanTech\Chapaar\SmsChannel; class InvoicePaid extends KavenegarBaseNotification { public function via($notifiable): array { return [SmsChannel::class]; } public function toSms($notifiable) { return (new SmsMessage)->driver() ->setTemplate('verify') ->setTokens([123],[456]) } } class User extends Authenticatable { use Notifiable; public function routeNotificationForSms($driver, $notification = null) { return $this->mobile; } }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.