Giter VIP home page Giter VIP logo

yii2-twilio-component's Introduction

Twilio Application Component for Yii2

Latest Version Software License Total Downloads

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.

Install

Via Composer

$ composer require 2amigos/yii2-twilio-component

Usage

Sign up for a Twilio Account

To use the Twilio REST API, you need an account. Signing up for a free Twilio account is easy. Once you've signed up, head over to your Console and grab your Account SID and your Auth Token.

Purchase an SMS Capable Phone Number

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.

Configuring the 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'
    ]
]

Sending an SMS

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;

Using code fixer

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

Why there are no tests?

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.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The BSD License (BSD). Please see License File for more information.


Custom Software | Web & Mobile Development
www.2amigos.us

yii2-twilio-component's People

Contributors

tonydspaniard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

wa1kb0y

yii2-twilio-component's Issues

parseFrom(NULL) error

Exception 'TypeError' with message 'Argument 1 passed to dosamigos\twilio\TwilioComponent::parseFrom() must be of the type string, null given, called in E:\wamp64\www\GigsHero\vendor\2amigos\yii2-twilio-component\src\TwilioComponent.php on line 69' 

in E:\wamp64\www\GigsHero\vendor\2amigos\yii2-twilio-component\src\TwilioComponent.php:114

Stack trace:
#0 E:\wamp64\www\GigsHero\vendor\2amigos\yii2-twilio-component\src\TwilioComponent.php(69): dosamigos\twilio\TwilioComponent->parseFrom(NULL)
#1 E:\wamp64\www\GigsHero\controllers\RegistrationController.php(108): dosamigos\twilio\TwilioComponent->sms('9501045616', 'Hello World!')
#2 [internal function]: app\controllers\RegistrationController->actionCustomer()
#3 E:\wamp64\www\GigsHero\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#4 E:\wamp64\www\GigsHero\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#5 E:\wamp64\www\GigsHero\vendor\yiisoft\yii2\base\Module.php(528): yii\base\Controller->runAction('customer', Array)
#6 E:\wamp64\www\GigsHero\vendor\yiisoft\yii2\web\Application.php(103): yii\base\Module->runAction('registration/cu...', Array)
#7 E:\wamp64\www\GigsHero\vendor\yiisoft\yii2\base\Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#8 E:\wamp64\www\GigsHero\web\index.php(17): yii\base\Application->run()
#9 {main}

Syntax error?

Hi, Perhaps this is a stupid question needing a curt reply, but I am getting a syntax error ... from the colon.... before the MessageInstance from Netbeans:

public function sms(string $to, string $text, array $options = []) : MessageInstance

I must be missing something really obvious here? Can you provide me please with some advanced knowledge on how to read this syntax.

Also there are two question marks after the ['from']. Educate me please!

{

# ### $from = $options['from']?? null;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.