quince/kavenegar-client

A php client for connecting to kavenegar.com api for sending sms.

1.2.0 2016-04-09 08:56 UTC

This package is not auto-updated.

Last update: 2024-12-21 20:46:43 UTC


README

A php client for connecting to kavenegar.com api for sending sms.

Installation

You must then modify your composer.json file and run composer update to include the latest version of the package in your project.

"require": {
    "quince/kavenegar-client": "~1.0"
}

Or you can run the composer require command from your terminal.

composer require quince/kavenegar-client

Usage

<?php

$apiKey = '{API_KEY}';
$senderNumber = '10004346';

$client = Quince\kavenegar\ClientBuilder::build($apiKey, $senderNumber);

$client->send('09123456789', 'سلام چطوری؟');

Laravel integration

Laravel 5.1 and above is supported in this package.

Add the following line to your laravel config/app.php:

'providers' => [
    //...

    Quince\kavenegar\Providers\ServiceProvider::class,
]

Then run the following in your command line

php artisan vendor:publish --provider="Quince\kavenegar\Providers\ServiceProvider"

A config file named kavenegar.php can be found in config folder. Configure you api key and default sender number if you want.

Laravel usage

By using laravel service provider you can automatically bindthe Client in your classes constructor.

use Quince\kavenegar\Client;

class SmsController extend Controller
{

    protected $client;
    
    public function __construct(Client $client)
    {
        $this->client = $client
    }
    
    public function send()
    {
        $this->client->send('09123456789', 'سلام جطوری؟');
    }
    
}

Methods description

Client::send()

Send a message to specified receptor phone number.

// Send a message to `09123456789` in 4/9/2016, 1:00:43 AM
$client->send('09123456789', 'The text to send', 1460147443, 0, '12', '30004346');

// Send a message to multiple receptors
$client->send(['09123456789', '09356789124', '09213456789'], 'The text to send', 1460147443, 0, '12', '30004346');

more info

Client::bulkSend()

Send bulk messages to multiple receptor phone numbers.

// Send multiple message to multiple receptor
$client->bulkSend(
    ['09123456789', '09356789124', '09213456789'],
    ['Text to send to 09123456789', 'Text to send to 09367891245', 'Text to send to 09213456789'],
    1460147443,
    [0, 1, 2],
    ['12', '13', '14'],
    ['10004346', '20004346', '30004346']
);

more info

Client::getMessageStatus()

Get status of a sent message by its message id.

// Get delivery status of a message
$client->getMessageStatus('8792343');

// Get delivery status of multiple messages
$client->getMessageStatus(['8792343', '8792344', '8792345']);

more info

Client::getMessageStatusByLocalId()

Get status of a sent message by local id set when sending.

// Get delivery status of a message
$client->getMessageStatus('13');

// Get delivery status of multiple messages
$client->getMessageStatus(['13', '14', '15']);

more info

Client::getMessageDetail()

Get details of a message by message id.

// Get details of a message
$client->getMessageDetail('8792343');

// Get details of multiple messages
$client->getMessageDetail(['8792343', '8792344', '8792345']);

more info

Client::getOutbox()

Get all sent message in specified date range (max 3000 message).

// Get outbox messages sent between 4/8/2016, 10:56:40 PM and 4/9/2016, 1:00:43 AM from all sender numbers
$client->getOutbox(1460140000, 1460147443, 0);

more info

Client::getRecentOutbox()

Get list of recent sent messages (max 3000 messages).

// Get 20 latest sent messages from all sender numbers
$client->getRecentOutbox(20, 0);

more info

Client::getOutboxCount()

Get count of sent message in specified range.

// Get outbox messages count between 4/8/2016, 10:56:40 PM and 4/9/2016, 1:00:43 AM from all sender numbers
$client->getOutboxCount(1460140000, 1460147443, 0);

more info

Client::cancelMessage()

Canceling a pending message from sending.

// Cancel sending of message with id of 8792343
$client->cancelMessage('8792343');

more info

Client::getInbox()

Get list of received messages (100 messages per each request).

// Get all unread messages sent to all lines
$client->getInbox(false, 0);

more info

Client::getInboxCount()

Get count of messages in inbox.

// Get inbox messages count between 4/8/2016, 10:56:40 PM and 4/9/2016, 1:00:43 AM from all sender numbers
$client->getInboxCount(1460140000, 1460147443, 0, false);

more info

Client::phoneCountByPostalCode()

Get count of phone numbers in a postal code area, categorized by oprator.

// Get phone count in 11252 postal code area
$client->phoneCountByPostalCode('11252');

more info

Client::sendByPostalCode()

Send message to phone numbers in a postal code area.

// Send a message to all MCI phones and 1000 random MTN phones in 11252 postal code area
// scheduled to send in 4/9/2016, 1:00:43 AM with sender number of 30004346
$client->sendByPostalCode(
    '11252',
    'Testing send by postal code',
    0,
    0,
    -1,
    1000,
    1460147443,
    '30004346'
);

more info

Client::getAccountInfo()

Get information of an account.

// Get info of current account
$client->getAccountInfo();

more info

Client::getAccountConfigs()

Get configuration of an account.

// Get current account configuration
$client->getAccountConfigs();

more info

Client::setAccountConfigs()

Set configuration of an account.

// Enable apilogs and daily reports
// and set default sender to 30004346
// and disable resend when failing to send a message
$client->setAccountConfigs([
    'apilogs'       => 'enabled',
    'dailyreport'   => 'enabled',
    'defaultsender' => '30004346',
    'resendfailed'  => 'disabled'
]);

more info

Client::sendVerificationCode()

Send vrification code, password, authorization code, etc.

// send a code to 09123456789 with licence_template template
$client->sendVerificationCode('09123456789', 'EA-958423', 'licence_template');

more info