GithubHelp home page GithubHelp logo

paulandroshchuk / twilio-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from twilio/twilio-php

0.0 0.0 0.0 10.16 MB

A PHP library for communicating with the Twilio REST API and generating TwiML.

Home Page: https://www.twilio.com/docs/libraries/php

License: MIT License

PHP 99.98% Makefile 0.02% Dockerfile 0.01%

twilio-php's Introduction

twilio-php

Tests Quality Gate Status Packagist Packagist Learn with TwilioQuest

Documentation

The documentation for the Twilio API can be found here.

The PHP library documentation can be found here.

Versions

twilio-php uses a modified version of Semantic Versioning for all changes. See this document for details.

Supported PHP Versions

This library supports the following PHP implementations:

  • PHP 7.2
  • PHP 7.3
  • PHP 7.4
  • PHP 8.0
  • PHP 8.1

Installation

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

Via Composer:

twilio-php is available on Packagist as the twilio/sdk package:

composer require twilio/sdk

Quickstart

Send an SMS

// Send an SMS using Twilio's REST API and PHP
<?php
$sid = "ACXXXXXX"; // Your Account SID from www.twilio.com/console
$token = "YYYYYY"; // Your Auth Token from www.twilio.com/console

$client = new Twilio\Rest\Client($sid, $token);
$message = $client->messages->create(
  '8881231234', // Text this number
  [
    'from' => '9991231234', // From a valid Twilio number
    'body' => 'Hello from Twilio!'
  ]
);

print $message->sid;

Make a Call

<?php
$sid = "ACXXXXXX"; // Your Account SID from www.twilio.com/console
$token = "YYYYYY"; // Your Auth Token from www.twilio.com/console

$client = new Twilio\Rest\Client($sid, $token);

// Read TwiML at this URL when a call connects (hold music)
$call = $client->calls->create(
  '8881231234', // Call this number
  '9991231234', // From a valid Twilio number
  [
      'url' => 'https://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient'
  ]
);

Specify Region and/or Edge

To take advantage of Twilio's Global Infrastructure, specify the target Region and/or Edge for the client:

<?php
$sid = "ACXXXXXX"; // Your Account SID from www.twilio.com/console
$token = "YYYYYY"; // Your Auth Token from www.twilio.com/console

$client = new Twilio\Rest\Client($sid, $token, null, 'au1');
$client->setEdge('sydney');

A Client constructor without these parameters will also look for TWILIO_REGION and TWILIO_EDGE variables inside the current environment.

This will result in the hostname transforming from api.twilio.com to api.sydney.au1.twilio.com.

Enable Debug Logging

There are two ways to enable debug logging in the default HTTP client. You can create an environment variable called TWILIO_LOG_LEVEL and set it to debug or you can set the log level to debug:

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

$client = new Twilio\Rest\Client($sid, $token);
$client->setLogLevel('debug');

Generating TwiML

To control phone calls, your application needs to output TwiML.

Use Twilio\TwiML\(Voice|Messaging|Fax)Response to easily chain said responses.

<?php
$response = new Twilio\TwiML\VoiceResponse();
$response->say('Hello');
$response->play('https://api.twilio.com/cowbell.mp3', ['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>

Handling Exceptions

For an example on how to handle exceptions in this helper library, please see the Twilio documentation.

Using a Custom HTTP Client

To use a custom HTTP client with this helper library, please see the Twilio documentation.

Docker Image

The Dockerfile present in this repository and its respective twilio/twilio-php Docker image are currently used by Twilio for testing purposes only.

Getting help

If you need help installing or using the library, please check the Twilio Support Help Center first, and file a support ticket if you don't find an answer to your question.

If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!

twilio-php's People

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.