Skip to content

Instantly share code, notes, and snippets.

$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}.json \
-d "Url=http://example.com/call-agent.php?agent_phone_number=%2b81345678901" \
-d "Method=GET" \
-u '{AccountSid}:{AuthToken}'
@TMcManus
TMcManus / pp_timestamp.py
Created June 29, 2013 18:37
Sometimes you just need to create a timestamp in Python with no dependencies. This function creates timestamps without requiring any imports.
def pure_python_timestamp(year, month, day, hour, minute, seconds):
"""
Sometimes you just need to create a timestamp in Python with no dependencies.
This function creates timestamps without requiring any imports.
Note: This function doesn't fully take into account the century rules for leap years.
>>> pure_python_timestamp('1994','11','19', '22', '01', '22')
785282482
>>> pure_python_timestamp('2013','07','03', '08', '14', '15')
@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 {
@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 / 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 / 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 / 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 / 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 / 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 / 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();