Coder Social home page Coder Social logo

seldaek / twilio-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from twilio/twilio-php

1.0 3.0 0.0 496 KB

A PHP library for communicating with the Twilio REST API and generating TwiML. Need help? Post your questions to http://getsatisfaction.com/twilio or email us at [email protected]

Home Page: http://readthedocs.org/docs/twilio-php/en/latest/

License: MIT License

PHP 88.02% Shell 0.20% Python 11.78%

twilio-php's Introduction

Build Status

Installation

You can install twilio-php via PEAR or by downloading the source.

Via PEAR (>= 1.9.3):

PEAR is a package manager for PHP. Open a command line and use these PEAR commands to download the helper library:

$ pear channel-discover twilio.github.com/pear
$ pear install twilio/Services_Twilio

If you get the following message:

$ -bash: pear: command not found

you can install PEAR from their website, or download the source directly.

Download the source code

Click here to download the source (.zip) which includes all dependencies.

Once you download the library, move the twilio-php folder to your project directory and then include the library file:

require 'Services/Twilio.php';

and you're good to go!

A Brief Introduction

With version 3.0 we've simplified interaction with the Twilio REST API. No more manually creating URLS or parsing XML/JSON. You now interact with resources directly. Follow the Quickstart Guide to get up and running right now. The User Guide shows you how to get the most out of twilio-php.

Quickstart

Send an SMS

<?php
// Install the library via PEAR or download the .zip file to your project folder.
// This line loads the library
require('Services/Twilio.php');

$client = new Services_Twilio('AC123', '123');
$message = $client->account->sms_messages->create(
  '9991231234', // From a valid Twilio number
  '8881231234', // Text this number
  "Hello monkey!"
);

print $message->sid;

Make a Call

<?php
// Install the library via PEAR or download the .zip file to your project folder.
// This line loads the library
require('Services/Twilio.php');

$sid = "ACXXXXXX"; // Your Account SID from www.twilio.com/user/account
$token = "YYYYYY"; // Your Auth Token from www.twilio.com/user/account

$client = new Services_Twilio($sid, $token);
$call = $client->account->calls->create(
  '9991231234', // From a valid Twilio number
  '8881231234', // Call this 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.

<?php
require('Services/Twilio.php');

$response = new Services_Twilio_Twiml();
$response->say('Hello');
$response->play('https://api.twilio.com/cowbell.mp3', array("loop" => 5));
print $response;

That will output XML that looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Response>
    <Say>Hello</Say>
    <Play loop="5">https://api.twilio.com/cowbell.mp3</Play>
<Response>

Full Documentation

The documentation for twilio-php is hosted at Read the Docs. Click here to read our full documentation.

Prerequisites

  • PHP >= 5.2.1
  • The PHP JSON extension

Reporting Issues

We would love to hear your feedback. Report issues using the Github Issue Tracker or email [email protected].

twilio-php's People

Contributors

asnyder avatar avalanche123 avatar caseysoftware avatar chrisbarr avatar gipetto avatar johndbritton avatar kavoreo avatar kevinburke avatar kyleconroy avatar luciferous avatar sursh avatar till avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.