private static function parse($file, $data) { // render content into response ob_start(); // extract vars extract($data, EXTR_SKIP); require $file; Response::append(ob_get_contents()); ob_end_clean(); }
/** * Write a string of text to the response body * * @param string $text * @param string $indent * @return Console */ public function write($text, $indent = null) { if ($this->width != 0) { $lines = strlen($text) > $this->width ? explode(PHP_EOL, wordwrap($text, $this->width, PHP_EOL)) : [$text]; } else { $lines = [$text]; } foreach ($lines as $line) { $this->response->append($indent . $line . PHP_EOL); } return $this; }
/** * Append a string of text to the response body * * @param string $text * @param boolean $newline * @return Console */ public function append($text = null, $newline = true) { if ($this->width != 0) { $lines = strlen($text) > $this->width ? explode(PHP_EOL, wordwrap($text, $this->width, PHP_EOL)) : [$text]; } else { $lines = [$text]; } foreach ($lines as $line) { $this->response->append($this->indent . $line . ($newline ? PHP_EOL : null)); } return $this; }
<?php header("Content-type: text/xml\n"); error_reporting(E_NONE); include "chirbit.php"; $user = AppletInstance::getUserGroupPickerValue('chirbit-controller'); $user_id = $user->values["id"]; $chirbit_username = PluginStore::get("chirbit_username_{$user_id}", ""); $chirbit_password = PluginStore::get("chirbit_password_{$user_id}", ""); $prompt = AppletInstance::getAudioSpeechPickerValue('prompt'); $after = AppletInstance::getAudioSpeechPickerValue('after'); $title = AppletInstance::getValue("title", ""); $response = new Response(); if (isset($_REQUEST['RecordingUrl'])) { chirbit_post($chirbit_username, $chirbit_password, $_REQUEST['RecordingUrl'], $title); $verb = AudioSpeechPickerWidget::getVerbForValue($after, null); $response->append($verb); $response->addHangup(); } else { $verb = AudioSpeechPickerWidget::getVerbForValue($prompt, null); $response->append($verb); $response->addRecord(); } $response->Respond();
// Note that we'd like to go through the machine again with our new state $keepLooping = true; } break; case DIAL_STATE_HANGUP: $response->addHangup(); break; case DIAL_STATE_NO_ANSWER: if ($dial_whom_selector == 'number') { if (empty($no_answer_redirect_number)) { $response->addHangup(); } $response->addRedirect($no_answer_redirect_number); } else { if ($no_answer_action === 'voicemail') { $response->append(AudioSpeechPickerWidget::getVerbForValue($voicemail, new Say("Please leave a message."))); $response->addRecord(array('transcribe' => true, 'transcribeCallback' => site_url('twiml/transcribe'))); $state[DIAL_ACTION] = DIAL_STATE_RECORDING; } else { if ($no_answer_action === 'redirect') { if (empty($no_answer_redirect)) { $response->addHangup(); } $response->addRedirect($no_answer_redirect); } else { if ($no_answer_action === 'hangup') { $response->addHangup(); } else { trigger_error("Unexpected no_answer_action"); } }
public function testSmsAddAttribute() { $r = new Response(); $re = new Sms(); $re->set("foo", "bar"); $r->append($re); $expected = '<Response><Sms foo="bar"></Sms></Response>'; $this->assertXmlStringEqualsXmlString($expected, $r->asUrl(False)); }
// http://www.twilio.com/docs/api/twiml/conference $r = new Response(); $dial = new Dial(); $conf = new Conference('MyRoom', array('startConferenceOnEnter' => "true")); $dial->append($conf); $r->append($dial); $r->Respond(); /* <Response> <Dial> <Conference startConferenceOnEnter="True"> MyRoom </Conference> </Dial> </Response> */ // ======================================================================== // Set any attribute / value pair // You may want to add an attribute to a verb that the library does not // support. This can be accomplished by putting __ in front o the // attribute name $r = new Response(); $redirect = new Redirect(); $redirect->set("crazy", "delicious"); $r->append($redirect); //$r-> Respond(); /* <Response> <Redirect crazy="delicious"/> </Response> */
/* Get the menu node, index, and url */ $node = isset($_REQUEST['node']) ? $_REQUEST['node'] : 'default'; $index = isset($_REQUEST['Digits']) ? (int) $_REQUEST['Digits'] : 0; $url = 'http://' . dirname($_SERVER["SERVER_NAME"] . $_SERVER['PHP_SELF']) . '/phonemenu.php'; /* Check to make sure index is valid */ if (isset($web[$node]) || count($web[$node]) >= $index && !is_null($_REQUEST['Digits'])) { $destination = $web[$node][$index]; } else { $destination = NULL; } // @start snippet /* Render TwiML */ $r = new Response(); switch ($destination) { case 'hours': $r->append(new Speak("Initech is open Monday through Friday, 9am to 5pm")); $r->append(new Speak("Saturday, 10am to 3pm and closed on Sundays")); break; case 'location': $r->append(new Speak("Initech is located at 101 4th St in San Francisco California")); $g = $r->append(new GetDigits(array('action' => 'http://' . dirname($_SERVER["SERVER_NAME"] . $_SERVER['PHP_SELF']) . '/phonemenu.php?node=location', 'numDigits' => '1'))); $g->append(new Speak("For directions from the East Bay, press 1")); $g->append(new Speak("For directions from San Jose, press 2")); break; case 'east-bay': $r->append(new Speak("Take BART towards San Francisco / Milbrae. Get off on Powell Street. Walk a block down 4th street")); break; case 'san-jose': $r->append(new Speak("Take Cal Train to the Milbrae BART station. Take any Bart train to Powell Street ")); break; case 'duck':
/** * @param Response $response * @param Response $services * @return Response */ private function appendToResponse(Response $response, Response $services) { foreach ($services as $service) { $response->append($service); } $response->setStatus($services->getStatus()); return $response; }
<?php $response = new Response(); $next = AppletInstance::getDropZoneUrl('next'); $prompt = AppletInstance::getAudioSpeechPickerValue('prompt'); $response->append(AudioSpeechPickerWidget::getVerbForValue($prompt, null)); if (!empty($next)) { $response->addRedirect($next); } $response->Respond();
<?php require "twilio.php"; require "includes/db_info.php"; $r = new Response(); if (empty($_POST["Digits"])) { $g = $r->append(new Gather(array("numDigits" => "6"))); $g->append(new Say("Please enter your verification code.")); } else { // grab db record and check for match $result = db(sprintf("select * from phone_numbers where phone_number='%s'", $_POST["Called"])); if ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($_POST["Digits"] === $line["verification_code"]) { db(sprintf("UPDATE phone_numbers SET verified = 1 WHERE phone_number = '%s'", $_POST["Called"])); $r->append(new Say("Thank you! Your phone number has been verified.")); } else { // if incorrect, prompt again $g = $r->append(new Gather(array("numDigits" => "6"))); $g->append(new Say("Verification code incorrect, please try again.")); } } mysql_close(); } $r->Respond();