コード例 #1
0
$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']));
            $twiml->addPlay("http://www.dialabc.com/i/cache/dtmfgen/wavpcm8.300/" . $config['gate_code'] . ".wav");
        }
        // either the feature is disabled or they didn't enter the proper code, send back to the menu
        $twiml->addRedirect($config['filename']);
        break;
    default: