Created
September 10, 2012 21:55
-
-
Save etsai/3694208 to your computer and use it in GitHub Desktop.
Keyword functionality example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Include twilio-php, the official Twilio PHP Helper Library, which can be found at | |
* http://www.twilio.com/docs/libraries | |
*/ | |
include('Services/Twilio.php'); | |
/* ## Controller ## */ | |
function index(){ | |
$response = new Services_Twilio_Twiml(); | |
$response->sms('Reply with one of the following keywords:'); | |
echo $response; | |
} | |
function stop(){ | |
$response = new Services_Twilio_Twiml(); | |
$response->sms('You have now unsubscribed. Thank you for trying us out.'); | |
echo $response; | |
} | |
function unsubscribe(){ | |
$response = new Services_Twilio_Twiml(); | |
$response->sms('You have now unsubscribed. Thank you for trying us out.'); | |
echo $response; | |
} | |
function start(){ | |
$response = new Services_Twilio_Twiml(); | |
$response->sms('Thank you for subscribing!'); | |
echo $response; | |
} | |
function help(){ | |
$response = new Services_Twilio_Twiml(); | |
$response->sms('To unsubscribe, reply STOP.'); | |
echo $response; | |
} | |
/* Read the contents of the 'Body' field of the Request. */ | |
$body = $_REQUEST['Body']; | |
/* Remove formatting from $body until it is just lowercase characters without punctuation or spaces. */ | |
$result = preg_replace("/[^A-Za-z0-9]/u", " ", $body); | |
$result = trim($result); | |
$result = strtolower($result); | |
/* ##Router## */ | |
switch ($result) { | |
case 'stop': | |
stop(); | |
break; | |
case 'unsubscribe': | |
unsubscribe(); | |
break; | |
case 'start': | |
start(); | |
break; | |
case 'help': | |
help(); | |
break; | |
/* Add new routing logic above this line. */ | |
default: | |
index(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment