Пример #1
0
$config['voice'] = "woman";
/**
 * Below here is where the magic happens.
 * Unless you know what you're doing, don't touch anything below.
 */
require_once "twilio.php";
$twiml = new TwimlResponse();
$parts = explode('/', $_SERVER["PHP_SELF"]);
$config['filename'] = $parts[count($parts) - 1];
switch ($_GET['page']) {
    case "gather":
        // handle routing to a roommate or to the secret code prompt
        $index = $_REQUEST['Digits'] - 1;
        if ($config['secret'] && $_REQUEST['Digits'] == '9') {
            // secret code is enabled and they accessed the secret menu, prompt for the code
            $gather = $twiml->addGather(array("action" => $config['filename'] . "?page=secret", "numDigits" => strlen($config['secret']), "method" => "POST"));
            $gather->addSay("Please enter the secret code now.", array("voice" => $config['voice']));
        } elseif (isset($config['roommates'][$index])) {
            // entered the digit for a valid roommate, forward the call
            $roommate = $config['roommates'][$index];
            $twiml->addSay("Connecting you to " . $roommate['name'], array("voice" => $config['voice']));
            $twiml->addDial($roommate['number']);
        }
        // not a valid input, send back to the menu
        $twiml->addRedirect($config['filename']);
        break;
    case "secret":
        // handle the secret code entry
        if ($config['secret'] && $_REQUEST['Digits'] == $config['secret']) {
            // secret code matches, buzz the caller in
            $twiml->addSay("Buzzing you in now.", array("voice" => $config['voice']));