Download the PHP package j42/laravel-twilio without Composer
On this page you can find all versions of the php package j42/laravel-twilio. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-twilio
laravel-twilio
A Twilio port for Laravel (5.1+)
Install
Add the package to your composer.json
and run composer update:
{
"require": {
...
"j42/laravel-twilio": "dev-master"
}
}
Then add the service providers and facades to config/app.php
...
Configure
Generate the package config files by running php artisan config:publish j42/laravel-twilio
, and adjust the relevant fields:
Phone Verification
Since phone verification is such a common use case, I created a simple flow to automate this.
This package automatically installs the following routes (GET
or POST
allowed):
/twilio/verify
Request a Token
Initiate an HTTP GET
or POST
request to /twilio/verify
with the following parameters:
phone
phone number (parsed as string)method
('sms' or 'call')
The numeric token is set in a cookie and has a 2 minute TTL during which it is valid.
Returns:
Verify a Token
Initiate an HTTP GET
or POST
re uest to /twilio/verify/
with the following parameters:
code
numeric code entered by user
If properly verified, the full object will be returned:
Post-Verification (Success)
Once the code has been confirmed, the verified data is available via Cookie
with a 5 minute TTL. An HTTP request to /twilio/verify
(with or without any parameters) will return:
Advanced Usage
Sometimes you may need to handle additional logic in a controller of your own. By including a handy interface, this becomes easy:
Define the route overrides (whichever suits your preference, or, both)
Create your controller, extending J42\LaravelTwilio\TwilioVerify
Define your functionality as needed, making sure to call parent::verify();
to handle the default events. If you need to access the cookie directly you may do so via: Cookie::get('twilio::phone')
.
SMS
How to interact with Twilio's REST-based SMS methods.
Send an SMS
Call
How to interact with Twilio's REST-based call initiation methods.
Initiate a Call (TWIML Endpoint)
Request Local Numbers
You can also request local numbers (to be used in the 'from' field) via any of the attributes available in the SDK client. Currently US only. If you want to adapt this (feel free to fork it) you may do so easily by abstracting the geoList parameters to the configuration file.
numbersNear
accepts 3 arguments:
conditions
Array, of conditions, taken from Twilio docsfeatures
Array, of features required (SmsEnabled, VoiceEnabled, MmsEnabled) or null (use default in config)buy
int, of #s to purchase automatically & provision with account
By Regex
A pattern to match phone numbers on. Valid characters are '' and [0-9a-zA-Z]. The '' character will match any single digit. See Example 2 and Example 3 below.
Purchasing Numbers
Purchasing numbers is easy. Just pass an array of phone #s you would like to buy to the buyNumbers
method.
Associating #s with TWIML (VoiceUrl/SmsUrl)
You can work with number resources by assigning them to TWIML endpoints for various services (voice, sms), as well as integrate and remove other features. This is as simple as calling update
with a number resource (an array of numbers, which include sid
properties -- this includes all responses returned from this library).
You can learn more about the "incoming phone numbers" resource via the Twilio Docs