Skip to content

Instantly share code, notes, and snippets.

@TMcManus
TMcManus / main.xml
Created November 19, 2012 15:30
Play a message before connecting a call
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>This call may be recording for Quality Assurance purposes.</Say>
<Dial record="true">
<Number url="message.xml">+18085551234</Number>
</Dial>
</Response>
@TMcManus
TMcManus / circuit-breaker.php
Last active October 13, 2015 04:18
Twilio Usage Trigger Manager and Subaccount Circuit Breaker
<?php
/**
* ### Subaccount Circuit Breaker Script ###
* This script is designed to make a subaccount suspend itself in response to
* a Usage Trigger firing a callback. You can learn about Usage Triggers here:
* https://www.twilio.com/docs/api/rest/usage-triggers
*
* Why would you want to do this? In some cases suspending a subaccount based on high,
* unexpected usage can be a good thing. Coding errors and fraud can both cause spikes
* in undesired usage. Setting this script up might help you to sleep better at night.
@TMcManus
TMcManus / conference.php
Created December 3, 2012 08:48
Unique Conference
<?php
/*
* Download the twilio-php helper library from:
* https://github.com/twilio/twilio-php
* Copy the "Services" folder into the directory containing this file.
*/
require('Services/Twilio.php');
$response = new Services_Twilio_Twiml;
$dial = $response->dial();
@TMcManus
TMcManus / index.php
Created December 16, 2012 00:03
This is an example of how you could use Twilio to make a call to another number using one of your Twilio verified called IDs. In this case, our verified caller ID is "+17075550987".
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Gather action="make-call.php" timeout="30">
<Say>Please enter the phone number you wish to dial</Say>
</Gather>
</Response>
@TMcManus
TMcManus / README.md
Last active May 18, 2016 23:49
Examples of how to use the python port of libphonenumber.

The python port of libphonenumber is pretty complete, but is a little short on examples and sample code. Here are some simple examples for some common uses of this fantastic library.

@TMcManus
TMcManus / README.md
Created January 3, 2013 18:24
Use the python port of libphonenumber to check that a phone number is of the correct length.

Installing

pip install phonenumbers

Using

$ python length_check.py +17075559876 Prints 'True'

$ python length_check.py +170755598764533 Prints 'False'

@TMcManus
TMcManus / email-incoming-call.php
Last active December 11, 2015 14:09
This script is meant to be placed at the target of Twilio's <Dial action="" record="true"> parameter. It will email you the recording of the call. It's the voice version of this script: http://www.twilio.com/help/faq/sms/how-can-i-forward-sms-to-my-email-inbox
<?php
/**
* This section ensures that Twilio gets a response.
*/
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<Response></Response>'; //Place the desired response (if any) here
/**
* This section actually sends the email.
@TMcManus
TMcManus / determine_country.py
Last active December 11, 2015 22:28
Example of a function to determine the country code of a phone number. Based on the python port of Google's libphonenumber project: https://github.com/daviddrysdale/python-phonenumbers
"""
Example of a function to determine the country code of a phone number.
Based on the python port of Google's libphonenumber project:
https://github.com/daviddrysdale/python-phonenumbers
"""
import phonenumbers as ph
def get_country_code(phone_number):
"""Returns the ISO 3166-1 alpha-2 code for a phone number
@TMcManus
TMcManus / japan_format.py
Created February 16, 2013 02:31
Example of a python function for normalizing Japanese local phone number formats to E.164 using the incredible python port of Google's libphonenumber project: https://github.com/daviddrysdale/python-phonenumbers
import phonenumbers as ph
def japan_format(phone_number, country_code='JP'):
"""
Converts local Japanese formatted number to E.164 format
Arguments:
phone_number -- A Japanese phone number in any format as a string
>>> japan_format("080-1234-5678")
@TMcManus
TMcManus / sanitize_number.php
Created March 28, 2013 21:52
Example of a PHP function for normalizing locally formatted phone number formats to E.164 using thePHP port of Google's libphonenumber project: https://github.com/davideme/libphonenumber-for-PHP
<?php
use com\google\i18n\phonenumbers\PhoneNumberUtil;
use com\google\i18n\phonenumbers\PhoneNumberFormat;
use com\google\i18n\phonenumbers\NumberParseException;
require_once 'libphonenumber-for-PHP/PhoneNumberUtil.php';
function sanitize_number ($phone_number, $iso_code) {
$pn = PhoneNumberUtil::getInstance();
try {