Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lakshmaji/twilio

This package enables to send message or OTP to any mobile.This package uses external Twilio api.
https://github.com/lakshmaji/twilio

authtoken composer laravel php sms twilio

Last synced: about 8 hours ago
JSON representation

This package enables to send message or OTP to any mobile.This package uses external Twilio api.

Awesome Lists containing this project

README

        

# Laravel - Twilio
[Wiki on web](http://lakshmaji.github.io/plivo/)

[![Latest Stable Version](https://poser.pugx.org/lakshmajim/twilio/v/stable)](https://packagist.org/packages/lakshmajim/twilio)
[![Total Downloads](https://poser.pugx.org/lakshmajim/twilio/downloads)](https://packagist.org/packages/lakshmajim/twilio)
[![Latest Unstable Version](https://poser.pugx.org/lakshmajim/twilio/v/unstable)](https://packagist.org/packages/lakshmajim/twilio)
[![License](https://poser.pugx.org/lakshmajim/twilio/license)](https://packagist.org/packages/lakshmajim/twilio)
[![Monthly Downloads](https://poser.pugx.org/lakshmajim/twilio/d/monthly)](https://packagist.org/packages/lakshmajim/twilio)
[![Daily Downloads](https://poser.pugx.org/lakshmajim/twilio/d/daily)](https://packagist.org/packages/lakshmajim/twilio)
[![composer.lock](https://poser.pugx.org/lakshmajim/twilio/composerlock)](https://packagist.org/packages/lakshmajim/twilio)

## INDEX

|Index|Description|
|---|:---|
|[What it is](https://github.com/lakshmaji/twilio/blob/master/README.md#what-it-is)|- Introduction|
|[Installation](https://github.com/lakshmaji/twilio/blob/master/README.md#installation) |- Installing Twilio package |
|[Laravel Integration](https://github.com/lakshmaji/twilio/blob/master/README.md#laravel-integration) |- Integrating this package with Laravel application|
|[Docs](https://github.com/lakshmaji/twilio/blob/master/README.md#method-available-parameters-and-responses)|- Description of methods available and parameters etc [Method](https://github.com/lakshmaji/twilio/blob/master/README.md#method) [Responses](https://github.com/lakshmaji/twilio/blob/master/README.md#responses)|
|[Miscellaneous](https://github.com/lakshmaji/twilio/blob/master/README.md#miscellaneous) |- Miscellaneous content regarding method calls
[Invalid method calls](https://github.com/lakshmaji/twilio/blob/master/README.md#invalid-method-calls)|- Invalid arguments (Not supported)|
|[Sending SMS](https://github.com/lakshmaji/twilio/blob/master/README.md#sending-sms) |- A simple Examp to illustarte the using this package|
|[Example with Laravel](https://github.com/lakshmaji/twilio/blob/master/README.md#example-code-for-laravel-along-with-sample-env-file)|- Sample code in Laravel|
|[Exception Handling](https://github.com/lakshmaji/twilio/blob/master/README.md#handling-exceptions) |- An Exception Handling mechanism to catch errors|
|[Twilio](https://github.com/lakshmaji/twilio/blob/master/README.md#twilio-trail-account-usage) |- How to Get registered on Twilio to use free trail account|
|[License](https://github.com/lakshmaji/twilio/blob/master/README.md#licence) |- License|

##WHAT IT IS?

- This package is used to send sms to any mobile number.
- This uses [Twilio](https://www.twilio.com/) API.
- It requires *AccountSID* and *AuthToken*, they can be generated by registrting @at [Twilio](https://www.twilio.com/try-twilio)
- after registration click on Account ,there you will be able to see authsid and authtoken.
- You have assigned a sender mobile number which can be found at [Twilio](https://www.twilio.com/user/account/phone-numbers/incoming),which is used to send Text Messages or MMS and ShortCodes etc.

---

##INSTALLATION

- Download package form https://github.com/lakshmaji/twilio .
- OR YOU CAN RUN FOLLOWING COMMAND FROM TERMINAL
- With composer you can run this line **composer require lakshmaji/twilio**

Run this command from the Terminal:

```bash
composer require lakshmaji/twilio
composer dumpautoload
composer update
```

***

##LARAVEL INTEGRATION

you need to add the service provider. Open `app/config/app.php`, and add a new item to the providers array.
```php
Lakshmaji\Twilio\TwilioServiceProvider::class,
```
Then, add a Facade for more convenient usage. In `app/config/app.php` add the following line to the `aliases` array:
```php
'Twilio' => Lakshmaji\Twilio\Facade\Twilio::class,
```
Again do composer update

***

## METHOD, AVAILABLE PARAMETERS AND RESPONSES

#####Method
```php
message(array, string, boolean, boolean, boolean)
```

```php

$message_array = array(
'sender_id' => 'TWILIO_AUTH_SID',
'sender_secret' => 'TWILIO_AUTH_SECRET',
'reciver_mobile' => 'MOBILE_NUMBER',
'media_url' => 'MEDIA_URL',
'otp' =>'OTP',
'sender' => 'TWILIO_SOURCE_NUMBER'
);

```

##### The message_array parameters

| PARAMETER | DESCRIPTION |
|:-------------- |:----------------------------------------|
|sender_id | This is the key defined in ".env" file for auth_sid |
|sender_secret| This is the key defined in ".env" file for auth_secret |
| sender | This is the key defined in .env file for sender mobile number |
|reciver_mobile| This is the receivers mobile number|
|media_url|This is the "uri" for mutimedia|
|otp|This key values associates with the otp|



##### Responses

| CODE | DESCRIPTION |
|:-------------- |:----------------------------------------|
|16000 | Error due to all flags are set to false or no flag was set|
|16001|Error due to all flags were set to true |
|16002|No sms type was set witin the avialbel list of flag parameters|
|16003|Un handled error|

***

##MISCELLANEOUS

#####To send SMS
```php
Twilio::message($message_array,$op="only msg", true, false, false ); // sms
```

#####To send MMS
```php
Twilio::message($message_array,$op="only MMS", false, false, true ); // media
```
#####To send OTP
```php
Twilio::message($message_array,$op="only verfication code", false, true, false ); // otp
```
#####To send both SMS and MMS
```php
Twilio::message($message_array,$op="This is combaination both SMS and MMS", true, false, true ); // sms , media
```

#####INVALID METHOD CALLS

```php
Twilio::message($message_array,$op="All set to true sms,mms,otp", true, true, true ); // sms , otp , media
Twilio::message($message_array,$op="all set to false", false, false, false ); // none defined
Twilio::message($message_array,$op="all considered to be false"); // none defined
Twilio::message($message_array);

```

***

##SENDING SMS

```php

'TWILIO_AUTH_ID',
'sender_secret' => 'TWILIO_AUTH_SECRET',
'reciver_mobile' => '999999999',
'media_url' => 'http://goo.gl/F9igRq',
'otp' =>'325565',
'sender' => 'TWILIO_SOURCE_NUMBER'
);

// This will send message only
$sms_response = Twilio::message($message_array,$op="only msg", true, false, false );

return response()->json($sms_response,200);
}

}
// end of class TwilioTest
// end of file TwilioTest.php

```


##Example code for Laravel along with sample .env file

**.env file**
```erlang

APP_ENV=local
APP_DEBUG=true
APP_KEY=BPfhzoGJ7RJB8D3qoyP6KZ2MjX2MAzcN

DB_HOST=127.0.0.1
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

TWILIO_SOURCE_MOBILE_NUMBER=+44778338721
TWILIO_USER_ID=ACef0d5a519rwetbf821ea07c2fdbfd8204e
TWILIO_USER_PASSWORD=a0fb23srfdsf4825cbb9501df25b906a74

```

The code to use above ".env" file is given below
```php

'TWILIO_USER_ID',
'sender_secret' => 'TWILIO_USER_PASSWORD',
'reciver_mobile' => '99999999999',
'media_url' => 'http://goo.gl/F9igRq',
'otp' =>'325456',
'sender' => 'TWILIO_SOURCE_MOBILE_NUMBER'
);

// This will send OTP only
$sms_response = Twilio::message($message_array,$op="otp only", false, true, false ); // otp

return response()->json($sms_response,200);
}

}
// end of class TwilioTest
// end of file TwilioTest.php

```

***

## Handling Exceptions

```php
json(array('message'=>$e->getMessage(),'status' =>$e->getStatusCode()),500);
}
return parent::render($request, $e);
}
}

```
In laravel we can easily handle the errors by using Handler.php (You can use custom Exception Handlr too)

***

## TWILIO TRAIL ACCOUNT USAGE:

- If You are trying to implement SMS functionality with Twilio the you need to verify the list of destination mobile numbers at [Twilio](https://www.twilio.com/user/account/phone-numbers/verified)
![VERIFIED NUMBERS](https://raw.githubusercontent.com/lakshmaji/images/master/verified_numbers.png)
- Before sending MESSAGE make sure that you have enabled **GEO-PERMISSIONS** at [Twilio](https://www.twilio.com/user/account/settings/international)
![GEO PERMISSIONS](https://raw.githubusercontent.com/lakshmaji/images/master/geo_permissions.png)

***

##Licence

[*MIT License (MIT)*](https://opensource.org/licenses/MIT)

@ MUTYALA ANANTHA LAKSHMAJI