public function __construct($settings = array()) { $this->response = new TwimlResponse(); $this->cookie_name = 'state-' . AppletInstance::getInstanceId(); $this->version = AppletInstance::getValue('version', null); $this->callerId = AppletInstance::getValue('callerId', null); if (empty($this->callerId) && !empty($_REQUEST['From'])) { $this->callerId = $_REQUEST['From']; } /* Get current instance */ $this->dial_whom_selector = AppletInstance::getValue('dial-whom-selector'); $this->dial_whom_user_or_group = AppletInstance::getUserGroupPickerValue('dial-whom-user-or-group'); $this->dial_whom_number = AppletInstance::getValue('dial-whom-number'); $this->no_answer_action = AppletInstance::getValue('no-answer-action', 'hangup'); $this->no_answer_group_voicemail = AppletInstance::getAudioSpeechPickerValue('no-answer-group-voicemail'); $this->no_answer_redirect = AppletInstance::getDropZoneUrl('no-answer-redirect'); $this->no_answer_redirect_number = AppletInstance::getDropZoneUrl('no-answer-redirect-number'); $this->dial_whom_instance = get_class($this->dial_whom_user_or_group); if (count($settings)) { foreach ($settings as $setting => $value) { if (isset($this->{$setting})) { $this->{$setting} = $value; } } } }
public static function dropZone($name = 'dropZone', $label = 'Drop applet here') { $link = AppletInstance::getDropZoneValue($name); $applet_id = null; $type = ''; $icon_url = ''; if (!empty($link) && is_string($link)) { $applet_id = explode('/', $link); $applet_id = $applet_id[count($applet_id) - 1]; } if (!empty($applet_id) && isset(Applet::$flow_data[$applet_id])) { $applet = Applet::$flow_data[$applet_id]; $type = $applet->type; $icon_url = ''; $label = $applet->name; $type_parts = explode("---", $type); $plugin_name = $type_parts[0]; $applet_name = $type_parts[1]; $icon_url = real_site_url('plugins/' . $plugin_name . '/applets/' . $applet_name . '/icon.png'); } else { if (!isset(Applet::$flow_data[$applet_id]) && !empty($applet_id)) { /* handling this gracefully in case of bad programmer */ $applet_id = null; $link = null; } } $widget = new DropZoneWidget($name, $label, $type, $icon_url, $link); return $widget->render(); }
function verify_day($key, $today) { $sunday = AppletInstance::getValue('sunday[]'); $monday = AppletInstance::getValue('monday[]'); $tuesday = AppletInstance::getValue('tuesday[]'); $wednesday = AppletInstance::getValue('wednesday[]'); $thursday = AppletInstance::getValue('thursday[]'); $friday = AppletInstance::getValue('friday[]'); $saturday = AppletInstance::getValue('saturday[]'); $days = array(0 => is_array($sunday) && array_key_exists($key, $sunday) ? $sunday[$key] : $sunday, 1 => is_array($monday) && array_key_exists($key, $monday) ? $monday[$key] : $monday, 2 => is_array($tuesday) && array_key_exists($key, $tuesday) ? $tuesday[$key] : $tuesday, 3 => is_array($wednesday) && array_key_exists($key, $wednesday) ? $wednesday[$key] : $wednesday, 4 => is_array($thursday) && array_key_exists($key, $thursday) ? $thursday[$key] : $thursday, 5 => is_array($friday) && array_key_exists($key, $friday) ? $friday[$key] : $friday, 6 => is_array($saturday) && array_key_exists($key, $saturday) ? $saturday[$key] : $saturday); return $days[$today]; }
function day_check($day, $key) { $value = AppletInstance::getValue($day); if (count($value) > 1) { if ($value[$key] == "true") { return "selected"; } } elseif (count($value) == "true") { if ($value == 1) { return "selected"; } } else { return "failed"; } }
public function __construct() { $this->response = new Response(); $this->cookie_name = 'state-' . AppletInstance::getInstanceId(); $this->version = AppletInstance::getValue('version', null); $this->callerId = AppletInstance::getValue('callerId', null); if (empty($this->callerId)) { $this->callerId = $_REQUEST['From']; } /* Get current instance */ $this->dial_whom_selector = AppletInstance::getValue('dial-whom-selector'); $this->dial_whom_user_or_group = AppletInstance::getUserGroupPickerValue('dial-whom-user-or-group'); $this->dial_whom_number = AppletInstance::getValue('dial-whom-number'); $this->no_answer_action = AppletInstance::getValue('no-answer-action', 'hangup'); $this->no_answer_group_voicemail = AppletInstance::getAudioSpeechPickerValue('no-answer-group-voicemail'); $this->no_answer_redirect = AppletInstance::getDropZoneUrl('no-answer-redirect'); $this->no_answer_redirect_number = AppletInstance::getDropZoneUrl('no-answer-redirect-number'); }
<?php $user = OpenVBX::getCurrentUser(); $tenant_id = $user->values['tenant_id']; $ci =& get_instance(); $queries = explode(';', file_get_contents(dirname(dirname(dirname(__FILE__))) . '/db.sql')); foreach ($queries as $query) { if (trim($query)) { $ci->db->query($query); } } $polls = $ci->db->query(sprintf('SELECT id, name FROM polls WHERE tenant=%d', $tenant_id))->result(); $poll = AppletInstance::getValue('poll'); $poll = $poll ? $poll : count($polls) ? $polls[0]->id : null; $options = json_decode($ci->db->query(sprintf('SELECT data FROM polls WHERE tenant=%d AND id=%d', $tenant_id, $poll))->row()->data); $option = AppletInstance::getValue('option'); ?> <div class="vbx-applet vbx-polls"> <?php if (count($polls)) { ?> <div class="vbx-full-pane"> <h3>Poll</h3> <fieldset class="vbx-input-container"> <select class="medium" name="poll"> <?php foreach ($polls as $p) { ?> <option value="<?php echo $p->id; ?>
<?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();
$zendesk_user = $CI->db->get_where('plugin_store', array('key' => 'zendesk_user'))->row(); $zendesk_user = json_decode($zendesk_user->value); define('ZENDESK_URL', $zendesk_user->url); define('ZENDESK_EMAIL', $zendesk_user->email); define('ZENDESK_PASSWORD', $zendesk_user->password); define('ZENDESK_TIMEZONE', (int) $zendesk_user->timezone); // create a ticket to zendesk $xml = '<ticket>' . '<subject>Phone Call from ' . format_phone($_REQUEST['Caller']) . ' on ' . gmdate('M d g:i a', gmmktime() + ZENDESK_TIMEZONE * 60 * 60) . '</subject>' . '<description>' . $_REQUEST['TranscriptionText'] . "\n" . 'Recording: ' . $_REQUEST['RecordingUrl'] . '</description>' . '</ticket>'; $new_ticket = zendesk_client('/tickets.xml', 'POST', $xml); $params = http_build_query($_REQUEST); $redirect_url = site_url('twiml/transcribe') . '?' . $params; header("Location: {$redirect_url}"); } else { $permissions = AppletInstance::getUserGroupPickerValue('permissions'); // get the prompt that the user configured $isUser = $permissions instanceof VBX_User ? TRUE : FALSE; if ($isUser) { $prompt = $permissions->voicemail; } else { $prompt = AppletInstance::getAudioSpeechPickerValue('prompt'); } $verb = AudioSpeechPickerWidget::getVerbForValue($prompt, new Say("Please leave a message.")); $response->append($verb); // add a <Record>, and use VBX's default transcription handle$response->addRecord(array('transcribe'=>'TRUE', 'transcribeCallback' => site_url('/twiml/transcribe') )); $action_url = base_url() . "twiml/applet/voice/{$flow_id}/{$instance_id}?status=save-call"; $transcribe_url = base_url() . "twiml/applet/voice/{$flow_id}/{$instance_id}?status=transcribe-call"; $response->addRecord(array('transcribe' => 'TRUE', 'action' => $action_url, 'transcribeCallback' => $transcribe_url)); } } $response->Respond(); // send response
<div class="vbx-applet"> <h2>Build your own TwiML</h2> <p><a href="http://www.twilio.com/docs/api/2010-04-01/twiml/" target="_blank">Learn more about TwiML</a></p> <fieldset class="vbx-input-container"> <textarea name="twiml" class="large" placeholder="<Say>:)</Say>"><?php echo AppletInstance::getValue('twiml'); ?> </textarea> </fieldset> <h2 class="settings-title">Next</h2> <p>After the message is sent, continue to the next applet</p> <div class="vbx-full-pane"> <?php echo AppletUI::DropZone('next'); ?> </div> </div><!-- .vbx-applet -->
<?php include_once 'TwimlDial.php'; define('DIAL_COOKIE', 'state-' . AppletInstance::getInstanceId()); $CI =& get_instance(); $CI->load->library('DialList'); $dialer = new TwimlDial(); $dialer->set_state(); // Respond based on state switch ($dialer->state) { case 'hangup': $dialer->hangup(); break; case 'new': if ($dialer->dial_whom_selector === 'user-or-group') { // create a dial list from the input state $dial_list = DialList::get($dialer->dial_whom_user_or_group); $dialed = false; do { $to_dial = $dial_list->next(); if ($to_dial instanceof VBX_User || $to_dial instanceof VBX_Device) { $dialed = $dialer->dial($to_dial); if ($dialed) { $dialer->state = $dial_list->get_state(); } } } while (!$dialed && ($to_dial instanceof VBX_User || $to_dial instanceof VBX_Device)); if (!$dialed) { // nobody to call, push directly to voicemail $dialer->noanswer(); }
<?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();
define('DIAL_STATE_RECORDING', 'dialStateRecording'); define('DIAL_STATE_HANGUP', 'dialStateHangup'); $response = new Response(); // Default State $state = array(); $state[DIAL_ACTION] = DIAL_STATE_DIAL; $state[DIAL_NUMBER_INDEX] = 0; $version = AppletInstance::getValue('version', null); /* Get current instance */ $dial_whom_selector = AppletInstance::getValue('dial-whom-selector'); $dial_whom_user_or_group = AppletInstance::getUserGroupPickerValue('dial-whom-user-or-group'); $dial_whom_number = AppletInstance::getValue('dial-whom-number'); $no_answer_action = AppletInstance::getValue('no-answer-action', 'hangup'); $no_answer_group_voicemail = AppletInstance::getAudioSpeechPickerValue('no-answer-group-voicemail'); $no_answer_redirect = AppletInstance::getDropZoneUrl('no-answer-redirect'); $no_answer_redirect_number = AppletInstance::getDropZoneUrl('no-answer-redirect-number'); $numbers = array(); $voicemail = null; if ($dial_whom_selector === 'user-or-group') { $dial_whom_instance = null; if (is_object($dial_whom_user_or_group)) { $dial_whom_instance = get_class($dial_whom_user_or_group); } switch ($dial_whom_instance) { case 'VBX_User': foreach ($dial_whom_user_or_group->devices as $device) { if ($device->is_active == 1) { $numbers[] = $device->value; } } $voicemail = $dial_whom_user_or_group->voicemail;
<?php $user = OpenVBX::getCurrentUser(); $tenant_id = $user->values['tenant_id']; $ci =& get_instance(); $selected = AppletInstance::getValue('list'); $queries = explode(';', file_get_contents(dirname(dirname(dirname(__FILE__))) . '/db.sql')); foreach ($queries as $query) { if (trim($query)) { $ci->db->query($query); } } $lists = $ci->db->query(sprintf('SELECT id, name FROM subscribers_lists WHERE tenant=%d', $tenant_id))->result(); ?> <div class="vbx-applet"> <?php if (count($lists)) { ?> <div class="vbx-full-pane"> <h3>List</h3> <fieldset class="vbx-input-container"> <select class="medium" name="list"> <?php foreach ($lists as $list) { ?> <option value="<?php echo $list->id; ?> "<?php echo $list->id == $selected ? ' selected="selected" ' : ''; ?>
<div class="vbx-applet"> <?php if (AppletInstance::getFlowType() == 'voice') { ?> <h2 class="start-heading">When a call begins, what should we do?</h2> <h3 class="start-instruct">Drag an applet from the right to get started.</h3> <?php } else { ?> <h2 class="start-heading">When an SMS message is received, <br />what should we do?</h2> <h3 class="start-instruct">Drag an applet from the right to get started.</h3> <?php } ?> <?php echo AppletUI::dropZone('next'); ?> </div><!-- .vbx-applet -->
public function addMessage($response, $name, $fallback) { $message = AppletInstance::getAudioSpeechPickerValue($name); $response->append(AudioSpeechPickerWidget::getVerbForValue($message, new Say($fallback))); return $response; }
<?php require_once dirname(__FILE__) . '/../../lib/dopplr.php'; $user = OpenVBX::getCurrentUser(); $dopplr_token = PluginData::get("dopplr_token_{$user->id}", ""); $dopplr = new Dopplr($dopplr_token); $response = new Response(); if ($dopplr->travel_today()) { $response->addRedirect(AppletInstance::GetDropZoneUrl('in_transit')); } else { if ($dopplr->at_home) { $response->addRedirect(AppletInstance::GetDropZoneUrl('at_home')); } else { $response->addRedirect(AppletInstance::GetDropZoneUrl('on_the_road')); } } $response->Respond();
<?php $ci =& get_instance(); $moderator = AppletInstance::getUserGroupPickerValue('moderator'); $confId = AppletInstance::getValue('conf-id'); $confName = AppletInstance::getInstanceId() . $confId; $caller = normalize_phone_to_E164(isset($_REQUEST['From']) ? $ci->input->get_post('From') : ''); $isModerator = false; $defaultWaitUrl = 'http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient'; $waitUrl = AppletInstance::getValue('wait-url', $defaultWaitUrl); $record = AppletInstance::getValue('record', 'do-not-record'); $hasModerator = false; if (!is_null($moderator)) { $hasModerator = true; switch (get_class($moderator)) { case 'VBX_User': foreach ($moderator->devices as $device) { if ($device->value == $caller) { $isModerator = true; } } break; case 'VBX_Group': foreach ($moderator->users as $user) { $user = VBX_User::get($user->user_id); foreach ($user->devices as $device) { if ($device->value == $caller) { $isModerator = true; } } }
<?php require_once dirname(__FILE__) . '/../../lib/dopplr.php'; $user = OpenVBX::getCurrentUser(); $dopplr_token = PluginData::get("dopplr_token_{$user->id}", ""); $dopplr = new Dopplr($dopplr_token); $response = new Response(); $response->addSay($dopplr->timezone()); $response->addRedirect(AppletInstance::getDropZoneUrl('next')); $response->Respond();
<?php $flow_type = AppletInstance::getFlowType(); $vp = AppletInstance::getValue('prompt-text'); ?> <div class="vbx-applet monkey-applet"> <h2>Order Tracking</h2> <p>Enter a custom message that your callers will be greeted by.</p> <textarea class="medium" name="prompt-text"><?php echo !empty($vp) ? AppletInstance::getValue('prompt-text') : 'Please enter your order id'; ?> </textarea> <?php if ($flow_type == 'voice') { ?> <br/> <h2>Next</h2> <p>After retrieving the order id, continue to the next applet</p> <div class="vbx-full-pane"> <?php echo AppletUI::DropZone('next'); ?> </div> <?php } ?> </div>
<?php $ci =& get_instance(); /* Get the body of the SMS message */ $body = isset($_REQUEST['Body']) ? trim($ci->input->get_post('Body')) : null; $body = strtolower($body); $prompt = AppletInstance::getValue('prompt'); $keys = AppletInstance::getValue('keys[]'); $responses = AppletInstance::getValue('responses[]'); $menu_items = AppletInstance::assocKeyValueCombine($keys, $responses, 'strtolower'); $response = new TwimlResponse(); /* Display the menu item if we found a match - case insensitive */ if (array_key_exists($body, $menu_items) && !empty($menu_items[$body])) { $response_text = $menu_items[$body]; } else { /* Display the prompt if incorrect */ $response_text = $prompt; } $response->sms($response_text); $response->Respond();
public function twiml($flow, $baseURI, $instance = null) { $path = $this->applet_dir . '/twiml.php'; if (!is_null($instance)) { AppletInstance::setInstance($instance); AppletInstance::setFlow($flow); AppletInstance::setBaseURI($baseURI); FlowStore::setFlowId($flow->id); // Plugin directory name is the natural key until a proper guid system is developed $plugin = new Plugin($this->plugin_dir_name); PluginData::setPluginId($plugin->getPluginId()); OpenVBX::$currentPlugin = $plugin; $instance = isset($instance->data) && is_array($instance->data) ? $instance->data : array(); } else { $instance = isset($this->data) && is_array($this->data) ? $this->data : array(); } AppletInstance::setFlowType($this->flow_type); if (!file_exists($path)) { return ''; } $output = '<?xml version="1.0" ?><Response />'; ob_start(); require_once APPPATH . 'libraries/twilio.php'; // require once was hampering our ability to run an applet multiple times (ie: in integration tests) require $path; $output = ob_get_contents(); ob_end_clean(); return $output; }
<?php $defaultNumberOfChoices = 4; $keys = AppletInstance::getValue('keys[]', array('1' => '', '2' => '', '3' => '', '4' => '')); $responses = AppletInstance::getValue('responses[]'); ?> <div class="vbx-applet query-applet"> <h2>Menu Prompt</h2> <fieldset class="vbx-input-container"> <p>When the texter reaches this menu, they will read:</p> <textarea class="medium" name="prompt" placeholder="Tell the users your options"><?php echo AppletInstance::getValue('prompt'); ?> </textarea> </fieldset> <h2>Menu Options</h2> <table class="vbx-menu-grid options-table"> <thead> <tr> <td>Keyword</td> <td> </td> <td>Reply</td> <td>Add & Remove</td> </tr> </thead> <tfoot> <tr class="hide"> <td>
?> </em></p> <div class="vbx-full-pane"> <?php foreach ($days as $index => $day) { ?> <div class="timing-timerange-wrap"> <label><?php print $day; ?> </label> <?php $state = AppletInstance::getValue("range_{$index}_from", '') ? 'remove' : 'add'; $default = $index < 5 ? '09:00AM' : ''; echo AppletUI::timeRange("range_{$index}", AppletInstance::getValue("range_{$index}_from", $default), AppletInstance::getValue("range_{$index}_to", '05:00PM'), $day); ?> <a href="#" class="timing-<?php echo $state; ?> "><?php echo $state; ?> </a> <br class="clear"/> </div> <?php } ?> </div>
<div class="vbx-applet"> <h2>Add Call to queue</h2> <p>Put this call into the hold queue uniquely identified by the string below</p> <input name="queue_name" value="<?php echo AppletInstance::getValue("queue_name"); ?> "/> </div>
public static function setBaseURI($baseURI) { self::$baseURI = $baseURI; }
<div class="vbx-applet openvbx-zendesk-applet"> <h2>This applet creates a ticket in ZenDesk for calls</h2> <p>Enter in the URL subdomain you use for Desk</p> <textarea class="small" name="subdomain"><?php echo AppletInstance::getValue('subdomain'); ?> </textarea> <p>Enter in the ZenDesk API Token</p> <textarea class="small" name="apitoken"><?php echo AppletInstance::getValue('apitoken'); ?> </textarea> <p>Enter in the email address</p> <textarea class="small" name="email"><?php echo AppletInstance::getValue('email'); ?> </textarea> <br /> <h2> Select An Action for The Caller</h2> <?php echo AppletUI::DropZone('primary'); ?> </div>
</fieldset> <h3>Message</h3> <?php if (AppletInstance::getFlowType() == 'voice') { ?> <p>Use %caller% to substitute the caller's number or %number% for the number called.</p> <?php } else { ?> <p>Use %sender% to substitute the sender's number, %number% for the number texted or %body% for the message body.</p> <?php } ?> <fieldset class="vbx-input-container"> <textarea name="sms" class="medium"><?php echo AppletInstance::getValue('sms'); ?> </textarea> </fieldset> </div> <h2>Next</h2> <p>After sending the message, continue to the next applet</p> <div class="vbx-full-pane"> <?php echo AppletUI::DropZone('next'); ?> </div> <?php } else { ?> <div class="vbx-full-pane">
$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();
<?php // get the current owner (user or group) to decide if we should show the Prompt area on load $currentlyIsUser = AppletInstance::getUserGroupPickerValue('permissions') instanceof VBX_User; ?> <div class="vbx-applet voicemail-applet"> <div class="prompt-for-group" style="display: <?php echo $currentlyIsUser ? "none" : ""; ?> "> <h2>Prompt</h2> <p>What will the caller hear before leaving their message?</p> <?php echo AppletUI::AudioSpeechPicker('prompt'); ?> </div> <div class="prompt-for-individual" style="display: <?php echo !$currentlyIsUser ? "none" : ""; ?> "> <h2>Prompt</h2> <div class="vbx-full-pane"> <fieldset class="vbx-input-container"> The individual's personal voicemail greeting will be played. </fieldset> </div> </div>
<?php if (!empty($settings) && !empty($settings['api_key'])) { ?> <div class="vbx-full-pane"> <h3>Amount</h3> <p>A positive integer in cents representing much to charge the card.</p> <fieldset class="vbx-input-container"> <input type="text" name="amount" class="medium" value="<?php echo AppletInstance::getValue('amount', 50); ?> " /> </fieldset> <h3>Description</h3> <fieldset class="vbx-input-container"> <input type="text" name="description" class="medium" value="<?php echo AppletInstance::getValue('description'); ?> " /> </fieldset> </div> <h2>After the payment</h2> <div class="vbx-full-pane"> <?php echo AppletUI::DropZone('success'); ?> </div> <h2>If the payment fails</h2> <div class="vbx-full-pane"> <?php echo AppletUI::DropZone('fail'); ?>