public function callHook(Request $request) { try { $phoneNumber = PhoneNumber::findVerifiedByTwilioNumber($request->input("From")); } catch (Exception $e) { return $this->promptToRegister($request); } $response = new TwimlGenerator(); $response->say('Thank you for calling Pulled Over. Your audio is now being recorded.'); $response->record(['maxLength' => 3600, 'action' => '/after-call']); event(new CallWasReceived($phoneNumber, $request->all())); return $response; }
<?php /** * A simple call recorder for iphone based on twilio */ require __DIR__ . '/vendor/autoload.php'; $response = new Services_Twilio_Twiml(); $response->say("This call is being recorded"); //notify both parties //when both parties hang up, twill will post the recording to the action URL $response->record(array('action' => 'save_recording.php', 'method' => 'POST', 'playBeep' => true)); $response->hangup(); print $response;
public function testRecordAddAttribute() { $r = new Services_Twilio_Twiml(); $r->record(array("foo" => "bar")); $expected = '<Response><Record foo="bar"></Record></Response>'; $this->assertXmlStringEqualsXmlString($expected, $r); }
$body .= "Click this link to listen to the message:\n{$_REQUEST['RecordingUrl']}.mp3"; mail($myemail, "New Voicemail Message from " . $from, $body, $headers); die; break; case "failed": $body = "You have a new voicemail from " . $from . "\n\n"; $body .= "Click this link to listen to the message:\n{$_REQUEST['RecordingUrl']}.mp3"; mail($myemail, "New Voicemail Message from " . $from, $body, $headers); die; break; } } else { if (isset($_REQUEST['RecordingUrl'])) { $response->say("Thanks. Good bye."); $response->hangup(); if (isset($transcribe) && strtolower($transcribe) != 'true') { $body = "You have a new voicemail from " . $from . "\n\n"; $body .= "Click this link to listen to the message:\n{$_REQUEST['RecordingUrl']}.mp3"; mail($myemail, "New Voicemail Message from " . $from, $body, $headers); } } else { $response->say($message); if ($transcribe) { $params = array("transcribe" => "true", "transcribeCallback" => "voicemail.php"); } else { $params = array(); } $response->record($params); } } echo $response;
header("Content-type: text/xml"); $fid = $_GET['id']; $from = preg_replace("/[^0-9]/", "", $_POST['From']); $pdo = Db::singleton(); $sql = "SELECT * FROM numbers WHERE ID='{$fid}';"; $res = $pdo->query($sql); $number = $res->fetch(); $fromNumber = $number['number']; if ($user = get_user($number['user_id'])) { $_SESSION['uid'] = $user['ID']; $toNumber = $user['phone_number']; $name = $user['name']; $response = new Services_Twilio_Twiml(); $response->dial($toNumber, array('timeout' => 5)); $response->say("I'm sorry, {$name} is not available at this time. Please leave a message after the tone."); $response->record(array('transcribeCallback' => 'transcribe.php?uid=' . $user['ID'] . '&From=' . $from, 'transcribe' => 'true')); print $response; exit; } }); $app->route('/transcribe', function () use($app) { header("Content-type: text/xml"); $uid = $_GET['uid']; if ($user = get_user($uid)) { $filter = "!@#\$^&%*()+=-[]\\/{}|:<>?,."; $recording = preg_replace("/[{$filter}]/", "", $_POST['RecordingUrl']); $transcript = preg_replace("/[{$filter}]/", "", $_POST['TranscriptionText']); $from = preg_replace("/[^0-9]/", "", $_GET['From']); $subject = "You have a new voicemail transcription from " . $from; $body = "You received voicemail." . "\n\nHere is the recording: {$recording}" . "\n\nAnd here is the transcription:\n {$transcript}"; mail($user['email'], $subject, $body);
<?php require __DIR__ . '/../vendor/autoload.php'; // Set these Heroku config variables $scheduleID = getenv('PAGERDUTY_SCHEDULE_ID'); $APItoken = getenv('PAGERDUTY_API_TOKEN'); $serviceAPItoken = getenv('PAGERDUTY_SERVICE_API_TOKEN'); $domain = getenv('PAGERDUTY_DOMAIN'); session_id($_POST['CallSid']); session_start(); $pagerduty = new \Vend\Phoneduty\Pagerduty($APItoken, $serviceAPItoken, $domain); $twilio = new Services_Twilio_Twiml(); $attributes = array('voice' => 'alice', 'language' => 'en-GB'); if (isset($_POST['RecordingUrl'])) { #create PD incident with link to recording $incident_data = array('service_key' => $serviceAPItoken, 'event_type' => 'trigger', 'description' => 'New voicemail for the on-call engineer', 'contexts' => [array('type' => 'link', 'text' => 'Listen to the message', 'href' => $_POST['RecordingUrl'] . '.mp3')], 'details' => array('duration' => $_POST['RecordingDuration'], 'from' => $_POST['From'])); $pagerduty->triggerIncident($incident_data); $twilio->say("Your message has been sent. Thank you.", $attributes); session_unset(); session_destroy(); } else { $twilio->say("The on-call engineer isn't available. " . "Please leave a message after the beep describing the issue. " . "Press any key or hang up when you are finished. ", $attributes); $twilio->record(array('action' => 'voicemail.php')); } $twilio->hangup(); // send response if (!headers_sent()) { header('Content-type: text/xml'); } echo $twilio;
<?php require_once 'vendor/autoload.php'; require_once 'db.php'; $response = new Services_Twilio_Twiml(); $pollDigits = $_REQUEST['Digits']; $messages = array('1' => '衣料品の配給が近日行われます', '2' => '明日の午後4時から、池袋東口公園で炊き出しがあります', '3' => '池袋東口公園に避難所が設営されています', '4' => '池袋東口公園で明日午前七時より臨時診療所が開かれます。どうぞご利用ください', '5' => '池袋東口公園で、帰宅困難者向けのテントが設営されています'); $data = array('to' => $_REQUEST['To'], 'phone-number' => $_REQUEST['From'], 'digits' => $pollDigits, 'created' => gmdate("Y/m/d H:i:s", time())); $result = json_decode(save($data), true); $url = 'http://' . $_SERVER['SERVER_NAME'] . '/record.php?id=' . urlencode($result['id']); $say_str = $messages[$pollDigits]; $response = new Services_Twilio_Twiml(); $response->say($say_str, array('language' => 'ja-jp')); $response->say('何かありましたら一言お願いします。メッセージが終了したら、シャープを押してください', array('language' => 'ja-jp')); $response->record(array('action' => $url, 'method' => 'POST')); header("Content-type: text/xml"); print $response;
<?php Route::get('/', function () { return view('welcome'); }); Route::post('call', function (Illuminate\Http\Request $request) { // @todo: Check if this is one of our stored numbers. If not, punt to "you need to register first" flow $response = new Services_Twilio_Twiml(); $response->say('Thank you for calling Pulled Over. Your audio is now being recorded.'); $response->record(['maxLength' => 15, 'action' => '/after-call']); event(new App\Events\CallWasReceived($request->all())); print $response; }); Route::post('after-call', function (Illuminate\Http\Request $request, Services_Twilio $twilio) { // Grab recording and text it to someone $message = $twilio->account->messages->sendMessage(env('TWILIO_FROM_NUMBER'), $request->get("From"), sprintf("Number: %s\nFrom: %s %s\nURL: %s\n", $request->get("From"), $request->get("CallerCity"), $request->get("CallerState"), $request->get("RecordingUrl"))); $response = new Services_Twilio_Twiml(); $response->say('Your fifteen seconds of fame are over. Goodbye!'); $response->hangup(); event(new App\Events\CallRecordingWasCompleted($request->all())); print $response; });