Skip to content

Instantly share code, notes, and snippets.

@caseysoftware
Last active December 14, 2015 04:59
Show Gist options
  • Select an option

  • Save caseysoftware/5032183 to your computer and use it in GitHub Desktop.

Select an option

Save caseysoftware/5032183 to your computer and use it in GitHub Desktop.
This is only part of functions.php - You can view this file in context here: https://github.com/caseysoftware/upgrading-google-voice-with-Twilio
<?php
// There is not the entire file, download the full package from Github.
function process_command($message)
{
$message = preg_replace('!\s+!', ' ', $message);
$words = explode(' ', $message);
$response = "Unknown command. Use: allow, block, remove, status, or name with a phone number to manage your lists";
if (2 > count($words)) {
return $response;
}
$command = $words[0];
$number = preg_replace("/[^0-9]/", "", $words[1]);
$perms = new Permissions();
switch($command) {
case 'allow': // add to whitelist
$result = $perms->updateList($number, 'white');
$response = ($result) ? "$number has been added to your whitelist" :
"An error has occured adding $number to your whitelist";
break;
case 'block': // add to blacklist
$result = $perms->updateList($number, 'black');
$response = ($result) ? "$number has been added to your blacklist" :
"An error has occured adding $number to your blacklist";
break;
case 'remove': // remove from either list
$result = $perms->removeNumber($number);
$response = ($result) ? "$number has been removed from your lists" :
"An error has occured removing $number from your lists";
break;
case 'status': // check where the number is
$result = find_in_list($number);
$response = ('' == $result) ? "$number was not in your lists" :
"$number is in your {$result}list";
break;
default:
// do nothing, let the "unknown" response from above fall through
}
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment