Chapaar offers flexible message sending and verification through multiple SMS providers, with easy integration and no lock-in to any specific provider.
- kavenegar.com (tested)
- sms.ir (tested)
- ghasedak.me (tested)
- Farapayamk (not tested)
- Twillo (coming soon)
You can install the package via Composer:
composer require tookantech/chapaar
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' => '',
],
],
];
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);
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;
}
}
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.