demmonico/yii2-sms Yii2 extension which allow send sms using multiply providers. Now available Nexmo provider

extensionsmscomponentnexmosend

Yii2 component - Sms Sender

Description

Yii2 component which allow simple send sms using multiply providers. Switching between providers supports using yii config file (better)

Configure

Common params

return [
    //...
    'components' => [
        //...
        'sms' => [
            'class' => 'demmonico\sms\Sender',
            'senderNumber' => 'name' or 'number',
            'provider' => [
                'class' => 'demmonico\sms\Nexmo',
                'apiKey' => '***',
                'apiSecret' => '***',
            ],
        ],
    ],
];

or DI

$component = \Yii::createObject('demmonico\sms\Nexmo', [
    [
        'class' => 'demmonico\sms\Sender',
        'senderNumber' => 'name' or 'number',
        'provider' => [
            'class' => 'demmonico\sms\Nexmo',
            'apiKey' => '***',
            'apiSecret' => '***',
        ],
    ],
]);

or using config component's bootstrap method (see https://github.com/demmonico/yii2-config)

in config file

return [
    //...
    'components' => [
        //...
        'sms' => [
            'class' => 'demmonico\sms\Sender',
            'senderNumber' => 'name' or 'number',
            'provider' => [
                'class' => 'demmonico\sms\Nexmo',
                'apiKey' => [
                    'component' => 'config',
                    'sms.Nexmo.apiKey',
                ],
                'apiSecret' => [
                    'component' => 'config',
                    'sms.Nexmo.apiSecret',
                ],
            ],
        ],
    ],
];

and in local params file

return [
    //...
    'sms.Nexmo.apiKey' => '******',
    'sms.Nexmo.apiSecret' => '******',
];

Now available Nexmo provider only. But you can add any external class with your custom provider. New providers can be added by creating class, which will implements demmonico\sms\SmsProviderInterface and extends (optional) demmonico\sms\BaseProvider.

Debug params

For debug you can use redirect option and dummy option. They can use separately or together. If redirect option redirectNumber is set then all messages will be send to this number. If dummy option dummyNumbers is set and field $to matches to any of dummyNumbers elements then process send will be skip and all sms fields will be logged

return [
    //...
    'components' => [
        //...
        'sms' => [
            //...
            'debug' => [
                'redirectNumber' => 'number',
                'dummyNumbers' => [
                    'number',
                    //...
                ],
            ],
        ],
    ],
];

Usage

Send sms

Yii::$app->sms->sendSms('Hello, world!', 'number');

or

Yii::$app->sms->sendSms('Hello, world!', 'recipientNumber', 'senderNumber');

Numbers must be in E.164 format. Method returns number (integer) of sent sms.

Get account balance

Yii::$app->sms->getBalance();

Method returns balance value (float).

Get account numbers

Yii::$app->sms->getNumbers();

Method returns array of numbers which are associate with account.

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



v1.0.2 is the latest of 3 releases



MIT license
Stats
0 github stars & 0 github forks
0 downloads in the last day
0 downloads in the last 30 days
100 total downloads