https://github.com/cubiclesoft/php-twilio-sdk
An ultra-lightweight PHP SDK for accessing Twilio APIs and emitting valid TwiML verbs in response to webhook calls. Also works with SignalWire!
https://github.com/cubiclesoft/php-twilio-sdk
Last synced: 11 months ago
JSON representation
An ultra-lightweight PHP SDK for accessing Twilio APIs and emitting valid TwiML verbs in response to webhook calls. Also works with SignalWire!
- Host: GitHub
- URL: https://github.com/cubiclesoft/php-twilio-sdk
- Owner: cubiclesoft
- Created: 2019-10-01T21:44:45.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-02-04T18:00:27.000Z (over 3 years ago)
- Last Synced: 2025-04-04T11:22:45.074Z (about 1 year ago)
- Language: PHP
- Size: 210 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Support: support/cacert.pem
Awesome Lists containing this project
README
Twilio SDK for PHP
==================
An ultra-lightweight PHP SDK for accessing Twilio APIs and emitting valid TwiML verbs in response to webhook calls. Also works with [SignalWire](https://signalwire.com/).
[](https://cubiclesoft.com/donate/) [](https://cubiclesoft.com/product-support/github/)
Features
--------
* Does what it says on the tin in a mere 7KB of code.
* Works with [Twilio](https://www.twilio.com/) and [SignalWire](https://signalwire.com/).
* Has a liberal open source license. MIT or LGPL, your choice.
* Designed for relatively painless integration into your project.
* Sits on GitHub for all of that pull request and issue tracker goodness to easily submit changes and ideas respectively.
Getting Started
---------------
Send a SMS message:
```php
SetAccessInfo($twilio_sid, $twilio_token);
// For SignalWire, use:
// $twilio->SetAccessInfo($twilio_sid, $twilio_token, "https://YOUR_SPACE.signalwire.com/api/laml/2010-04-01");
$postvars = array(
"From" => "+13145557878", // Twilio phone number
"To" => "+13145551212", // Destination phone number
"Body" => "SMS message to send."
);
$result = $twilio->RunAPI("POST", "Messages", $postvars);
if (!$result["success"])
{
var_dump($result);
exit();
}
?>
```
Handle an incoming webhook call:
```php
SetAccessInfo($twilio_sid, $twilio_token);
// Secure the request.
$twilio->ValidateWebhookRequest();
$twilio->StartXMLResponse();
if (isset($_REQUEST["CallSid"]))
{
if (isset($_REQUEST["Digits"]) && $_REQUEST["Digits"] == "1")
{
$twilio->OutputXMLTag("Say", array(), "It's sunny and warm outside.");
}
else if (isset($_REQUEST["Digits"]) && $_REQUEST["Digits"] == "2")
{
$twilio->OutputXMLTag("Say", array(), "It's going to be a balmy 72 degrees outside today with a very slight chance of delicious pie falling from the sky.");
}
$options = array();
$options[] = "Press 1 to get the weather.";
$options[] = "Press 2 to get the forecast.";
$twilio->OpenXMLTag("Gather", array("numDigits" => "1"));
$twilio->OutputXMLTag("Say", array(), implode(" ", $options));
$twilio->CloseXMLTag("Gather");
$twilio->OutputXMLTag("Redirect", array(), Request::GetFullURLBase());
}
$twilio->EndXMLResponse();
?>
```
More Information
----------------
* [SDK documentation](https://github.com/cubiclesoft/php-twilio-sdk/blob/master/docs/sdk_twilio.md) - The TwilioSDK class documentation.