A Yii2 Application Component to ease the use of twilio SDK
Twilio is an awesome service that allows to include programmable SMS, Voice, Video, and Chat services in your apps. For Server side only Voice and SMS services are available.
This component is a simple wrapper to ease Yii2 framework developers the job to send SMS and start Voice calls with Twilio.
$ composer require 2amigos/yii2-twilio-component
Sending SMS messages requires an SMS capable phone number. You can browse the available phone numbers in the Console. Be sure that the phone number you buy is SMS capable. When you search, you can check the box to filter available numbers to those that are SMS capable.
Once you have the Twilio phone number you are ready to configure your application component.
You have to take the Account SID, the Auth Token and the purchased phone number and configure the component:
// On your application config file // ... 'components' => [ 'twilio' => [ 'class' => '\dosamigos\twilio\TwilioComponent', 'sid' => 'ACCOUNT_SID', 'token' => 'AUTH_TOKEN', 'phoneNumber' => 'PURCHASED_PHONE_NUMBER' ] ]
Now that the application component has been set, you can do the following to send SMS:
$message = Yii::$app->twilio->sms('VALID_PHONE_NUMBER_TO_SEND_SMS', 'Hello World!'); // It returns a \Twilio\Rest\Api\V2010\Account\MessageInstance echo $message->sid;
In case you wish to use another purchased phone number, you can override the one configured as follows:
$message = Yii::$app->twilio->sms('VALID_PHONE_NUMBER_TO_SEND_SMS', 'Hello World!', [ 'from' => 'ANOTHER_PURCHASED_TWILIO_PHONE_NUMBER' ]); // It returns a \Twilio\Rest\Api\V2010\Account\MessageInstance echo $message->sid;
We have added a PHP code fixer to standardize our code. It includes Symfony, PSR2 and some contributors rules.
./vendor/bin/php-cs-fixer fix ./src --config .php_cs
The component is too simple to include tests as its a wrapper to Twilio's client library and the library has already all the required tests to check the functionality.
Please see CONTRIBUTING for details.
The BSD License (BSD). Please see License File for more information.
Custom Software | Web & Mobile Development