/** * If the result of a no-answer is to take a voicemail then * we determine if its a user or group voicemail and then prompt for a record * * Also, if the result of no-answer is to redirect then that is handled here too. * An empty redirect value will cause a hangup. * * @throws TwimlDialException * @return void */ protected function no_answer_object() { if ($this->no_answer_action === 'voicemail') { switch ($this->dial_whom_instance) { case 'VBX_User': $voicemail = $this->dial_whom_user_or_group->voicemail; break; case 'VBX_Group': $voicemail = $this->no_answer_group_voicemail; break; default: $voicemail = null; } if (!AudioSpeechPickerWidget::setVerbForValue($voicemail, $this->response)) { // fallback to default voicemail message $this->response->say(self::$default_voicemail_message, array('voice' => $this->voice, 'language' => $this->language)); } $record_params = array('transcribe' => $this->transcribe ? 'true' : 'false'); if ($this->transcribe) { $record_params['transcribeCallback'] = site_url('twiml/transcribe'); } $this->response->record($record_params); $this->state = 'recording'; } else { if ($this->no_answer_action === 'redirect') { if (empty($this->no_answer_redirect)) { $this->hangup(); } $this->response->redirect($this->no_answer_redirect); } else { if ($this->no_answer_action === 'hangup') { $this->hangup(); } else { throw new TwimlDialException("Unexpected no_answer_action"); } } } }
$user = VBX_User::get($user->user_id); foreach ($user->devices as $device) { if ($sender == $device->value) { $dispatch = true; } } } } } } $response = new TwimlResponse(); if ($dispatch) { $subscribers = $ci->db->query(sprintf('SELECT value FROM subscribers WHERE list = %d', $list))->result(); require_once APPPATH . 'libraries/Services/Twilio.php'; $service = new Services_Twilio($ci->twilio_sid, $ci->twilio_token); if ($body && count($subscribers)) { foreach ($subscribers as $subscriber) { $service->account->sms_messages->create($number, $subscriber->value, $body); } } $dispatched = AppletInstance::getDropZoneUrl('dispatched'); if (!empty($dispatched)) { $response->redirect($dispatched); } } else { $next = AppletInstance::getDropZoneUrl('next'); if (!empty($next)) { $response->redirect($next); } } $response->respond();
function accept_or_reject_recording_twiml() { validate_rest_request(); $response = new TwimlResponse(); $digits = clean_digits($this->input->get_post('Digits')); $call_sid = $this->input->get_post('CallSid'); switch ($digits) { case 1: $audioFile = VBX_Audio_File::get(array('recording_call_sid' => $call_sid)); if ($audioFile == null) { trigger_error("That's weird - we can't find the place holder audio file that matches this sid (" . $call_sid . ")"); } else { $audioFile->url = $this->session->userdata('current-recording'); $audioFile->save(); } $response->say('Your recording has been saved.', $this->say_params); $response->hangup(); break; case 2: $response->redirect(site_url('audiofiles/prompt_for_recording_twiml')); default: $response->redirect(site_url('audiofiles/replay_recording_twiml')); break; } return $response->respond(); }
<?php $ci =& get_instance(); $number = AppletInstance::getValue('number'); $id = AppletInstance::getValue('flow'); if (!empty($_REQUEST['From'])) { $recipient = normalize_phone_to_E164(str_replace('%sender%', $_REQUEST['From'], AppletInstance::getValue('recipient'))); require_once APPPATH . 'libraries/Services/Twilio.php'; $service = new Services_Twilio($ci->twilio_sid, $ci->twilio_token); if (($flow = OpenVBX::getFlows(array('id' => $id, 'tenant_id' => $ci->tenant->id))) && $flow[0]->values['data']) { $service->account->calls->create($number, $recipient, site_url('twiml/start/voice/' . $id)); } } $response = new TwimlResponse(); $next = AppletInstance::getDropZoneUrl('next'); if (!empty($next)) { $response->redirect($next); } $response->respond();
<?php $response = new TwimlResponse(); $now = date_create('now'); $today = date_format($now, 'N') - 1; /** * The names of the applet instance variables for "from" and "to" times * are of the form: "range_n_from" and "range_n_to" where "n" * is a value between 0 and 6 (inclusive). 0 represents Monday * and 6 represents Sunday. In PHP, the value of date_format($now, 'w') * for Sunday is 0 - for Monday the value is 1 - and so on. * Here, we need to compensate for this by checking to see if the value * of date_format($now, 'w') - 1 is -1, and, if so, bring Sunday * back into the valid range of values by setting $today to 6. */ if ($today == -1) { $today = 6; } $response->redirect(AppletInstance::getDropZoneUrl(($from = AppletInstance::getValue("range_{$today}_from")) && ($to = AppletInstance::getValue("range_{$today}_to")) && date_create($from) <= $now && $now < date_create($to) ? 'open' : 'closed')); $response->respond();
$response->addHangup(); break; case 'Say': default: $response->Say($json['msg']); $response->Redirect($next); break; } } elseif ($json && $json['status'] != 'success') { switch ($json['type']) { case 'Play': $response->Gather(array('numDigits' => $numDigits, 'timeout' => 60))->Play($json['msg']); break; case 'Hangup': $response->Hangup(); break; case 'Say': default: $response->Gather(array('numDigits' => $numDigits, 'timeout' => 60))->Say($json['msg']); break; } } else { $response->redirect(); } } else { $gather = $response->gather(array('numDigits' => $numDigits, 'timeout' => 60)); // $verb = AudioSpeechPickerWidget::getVerbForValue($prompt, null); AudioSpeechPickerWidget::setVerbForValue($prompt, $gather); // $gather->append($verb); } $response->Respond();
<?php $responses = (array) AppletInstance::getDropZoneUrl('responses[]'); $keys = (array) AppletInstance::getValue('keys[]'); $invalid_option = AppletInstance::getDropZoneUrl('invalid-option'); $menu_items = AppletInstance::assocKeyValueCombine($keys, $responses); $caller_id = null; if (!empty($_REQUEST['Direction'])) { $number = normalize_phone_to_E164(in_array($_REQUEST['Direction'], array('inbound', 'incoming')) ? $_REQUEST['From'] : $_REQUEST['To']); if (preg_match('/([0-9]{10})$/', $number, $matches)) { $caller_id = $matches[1]; } } $response = new TwimlResponse(); if (!empty($caller_id) && array_key_exists($caller_id, $menu_items) && !empty($menu_items[$caller_id])) { $response->redirect($menu_items[$caller_id]); } elseif (!empty($invalid_option)) { $response->redirect($invalid_option); } $response->respond();
<?php require_once __DIR__ . '/functions.php'; $duration = AppletInstance::getValue('duration'); $enabled = AppletInstance::getValue('enabled'); $instance_id = AppletInstance::getInstanceId(); $limit = AppletInstance::getValue('limit'); $blocked_applet = AppletInstance::getDropZoneUrl('blocked'); $unblocked_applet = AppletInstance::getDropZoneUrl('unblocked'); //$flow_type = AppletInstance::getFlowType(); $response = new TwimlResponse(); if (limit_exceeded($duration, $enabled, $instance_id, $limit)) { //number over limit $response->redirect($blocked_applet); } else { //number within limit $response->redirect($unblocked_applet); } $response->respond();
<?php $body = isset($_REQUEST['Body']) ? trim($_REQUEST['Body']) : null; $body = strtolower($body); $invalid_option = AppletInstance::getDropZoneUrl('invalid-option'); $keys = (array) AppletInstance::getValue('keys[]'); $responses = (array) AppletInstance::getDropZoneUrl('responses[]'); $menu_items = AppletInstance::assocKeyValueCombine($keys, $responses, 'strtolower'); $response = new TwimlResponse(); if (array_key_exists($body, $menu_items) && !empty($menu_items[$body])) { $response->redirect($menu_items[$body]); } elseif (!empty($invalid_option)) { $response->redirect($invalid_option); } $response->respond();
$response = curlWrap("/tickets.json", json_encode(array("ticket" => array("subject" => "New Phone Call From " . $phone, "comment" => array("body" => "Call made at " . date('r')), "requester_id" => $response['user']['id']))), "POST"); } else { if ($response['count'] > 0) { function filterAnon($elem) { $bool = strpos($elem['name'], "Unknown") === false && strpos($elem['name'], "Anonymous") === false; return $bool; } //filter out unknown and anonymous users $known = array_values(array_filter($response['results'], 'filterAnon')); if (sizeof($known) > 0) { //new ticket with known user as requestor $knownUser = $known[0]; $response = curlWrap("/tickets.json", json_encode(array("ticket" => array("subject" => "New Phone Call From " . $knownUser['name'] . " | " . $phone, "comment" => array("body" => "Call came in at " . date('r')), "requester_id" => $knownUser['id']))), "POST"); } else { //new ticket with existing unknown user as requestor $response = curlWrap("/tickets.json", json_encode(array("ticket" => array("subject" => "New Phone Call From " . $phone, "comment" => array("body" => "Call came in at " . date('r')), "requester_id" => $response['results'][0]['id']))), "POST"); } } } // openvbx code below // $primary is getting the url created by what ever applet was put // into the primary dropzone $primary = AppletInstance::getDropZoneUrl('primary'); // As long as the primary dropzone is not empty add the redirect // twiml to $response if (!empty($primary)) { $tResponse->redirect($primary); } // This will create the twiml for hellomonkey $tResponse->respond();