Skip to content

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.

License

Notifications You must be signed in to change notification settings

tookantech/chapaar

Folders and files

NameName
Last commit message
Last commit date
Aug 21, 2023
Oct 21, 2023
Oct 21, 2023
Oct 31, 2023
Sep 6, 2023
Aug 5, 2023
Aug 5, 2023
Aug 5, 2023
Aug 30, 2023
Aug 15, 2023
Aug 21, 2023
Oct 6, 2023
Aug 23, 2023
Aug 5, 2023
Aug 28, 2023
Aug 21, 2023

Repository files navigation

Chapaar | flexible way to send SMS through various SMS providers

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Chapaar offers flexible message sending and verification through multiple SMS providers, with easy integration and no lock-in to any specific provider.

Available Drivers

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);

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.

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Languages