Skip to content

Latest commit

 

History

History
194 lines (128 loc) · 4.58 KB

index.rst

File metadata and controls

194 lines (128 loc) · 4.58 KB

twilio-php

Status

This documentation is for version 3.7.0 of twilio-php.

Quickstart

Send a SMS

// Download the library and copy into the folder containing this file.
require('/path/to/twilio-php/Services/Twilio.php');

$account_sid = "ACXXXXXX"; // Your Twilio account sid
$auth_token = "YYYYYY"; // Your Twilio auth token

$client = new Services_Twilio('AC123', '123');
$message = $client->account->sms_messages->create(
  '+14085551234', // From a Twilio number in your account
  '+12125551234', // Text any number
  "Hello monkey!"
);

print $message->sid;

Make a Call

// Download the library and copy into the folder containing this file.
require('/path/to/twilio-php/Services/Twilio.php');

$account_sid = "ACXXXXXX"; // Your Twilio account sid
$auth_token = "YYYYYY"; // Your Twilio auth token

$client = new Services_Twilio($account_sid, $auth_token);
$call = $client->account->calls->create(
  '+14085551234', // From a Twilio number in your account
  '+12125551234', // Text any number

  // Read TwiML at this URL when a call connects (hold music)
  'http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient'
);

Generating TwiML

To control phone calls, your application needs to output TwiML. Use Services_Twilio_Twiml to easily create such responses.

$response = new Services_Twilio_Twiml();
$response->say('Hello');
$response->play('https://api.twilio.com/cowbell.mp3', array("loop" => 5));    
print $response;
<?xml version="1.0" encoding="utf-8"?>
<Response>
    <Say>Hello</Say>
    <Play loop="5">https://api.twilio.com/cowbell.mp3</Play>
<Response>

View more examples of TwiML generation here: usage-twiml

Installation

There are two ways to install twilio-php: via the PEAR installer, or by downloading the source.

Via PEAR

pear channel-discover twilio.github.com/pear
pear install twilio/Services_Twilio    # may need to run sudo pear instead

From Source

If you aren't using PEAR, download the source (.zip), which includes all the dependencies.

User Guide

REST API

usage/rest usage/rest/*

TwiML and other utilities

usage/twiml usage/validation usage/token-generation faq/

API Documentation

api/*

Support and Development

All development occurs on Github. To check out the source, run

git clone git@github.com:twilio/twilio-php.git

Report bugs using the Github issue tracker.

If you’ve got questions that aren’t answered by this documentation, ask the #twilio IRC channel

Running the Tests

The unit tests depend on Mockery and PHPUnit. First, 'discover' all the necessary PEAR channels:

pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear channel-discover pear.survivethedeepend.com
pear channel-discover hamcrest.googlecode.com/svn/pear
pear install --alldeps deepend/Mockery
pear install phpunit/PHPUnit

After installation, run the tests with make

make test

Making the Documentation

Our documentation is written using Sphinx. You'll need to install Sphinx and the Sphinx PHP domain before you can build the docs.

pip install Sphinx sphinxcontrib-phpdomain

Once you have those installed, making the docs is easy.

cd docs
make html