Esempio n. 1
0
 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;
             }
         }
     }
 }
Esempio n. 2
0
 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');
 }
                    $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();
Esempio n. 4
0
<?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();
Esempio n. 5
0
<?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();
Esempio n. 6
0
$response = new Response();
$fallback = AppletInstance::getDropZoneUrl('fallback');
$choices = AppletInstance::getValue('choices[]');
$start = AppletInstance::getValue('timestart[]');
$finish = AppletInstance::getValue('timefinish[]');
$ci_timezone = AppletInstance::getValue('timezones');
$ci =& get_instance();
$choice_array = array();
if (count($start) == 1) {
    $new_start = array(0 => $start);
    $start = $new_start;
    $new_finish = array(0 => $finish);
    $finish = $new_finish;
}
foreach ($choices as $a => $q) {
    $choice_array[$a] = AppletInstance::getDropZoneUrl('choices[' . $a . ']');
}
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 verify_time($currentTime, $startTime, $endTime)
{
<?php

$ci =& get_instance();
$list = AppletInstance::getValue('list');
if (!empty($_REQUEST['From'])) {
    $number = normalize_phone_to_E164($_REQUEST['From']);
    $subscriber = $ci->db->query(sprintf('SELECT id FROM subscribers WHERE list = %d AND value = %s', $list, $number))->num_rows() > 0;
    $next = AppletInstance::getDropZoneUrl($subscriber ? 'pass' : 'fail');
}
$response = new TwimlResponse();
if (!empty($next)) {
    $response->redirect($next);
}
$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();
Esempio n. 9
0
        Stripe::setApiKey($settings['api_key']);
        try {
            $charge = Stripe_Charge::create(array('card' => $state['card'], 'amount' => $amount, 'currency' => 'usd', 'description' => $description));
            if ($charge->paid && true === $charge->paid) {
                setcookie(STRIPE_COOKIE);
                $next = AppletInstance::getDropZoneUrl('success');
                if (!empty($next)) {
                    $response->redirect($next);
                }
                $response->respond();
                die;
            }
        } catch (Exception $e) {
            $error = $e->getCode();
            $response->addSay($e->getMessage());
            if (array_key_exists($error, $card_errors)) {
                $state[STRIPE_ACTION] = $card_errors[$error];
                $response->redirect();
            } else {
                setcookie(STRIPE_COOKIE);
                $next = AppletInstance::getDropZoneUrl('fail');
                if (!empty($next)) {
                    $response->redirect($next);
                }
                $response->respond();
                die;
            }
        }
}
setcookie(STRIPE_COOKIE, json_encode($state), time() + 5 * 60);
$response->respond();
Esempio n. 10
0
<?php

$response = new Response();
$url = AppletInstance::getValue('url');
$next = AppletInstance::getDropZoneUrl('next');
$fallback = AppletInstance::getDropZoneUrl('fallback');
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($result)) {
    $response->addSay('that didnt work');
    $response->addRedirect($fallback);
    $response->Respond();
} else {
    $response->addSay($result);
    $response->addRedirect($next);
    $response->Respond();
}
Esempio n. 11
0
<?php

$body = isset($_REQUEST['Body']) ? trim($_REQUEST['Body']) : null;
$keys = (array) AppletInstance::getValue('keys[]');
$responses = (array) AppletInstance::getDropZoneUrl('responses[]');
$menu_items = AppletInstance::assocKeyValueCombine($keys, $responses);
$next = AppletInstance::getDropZoneUrl('invalid-option');
$response = new TwimlResponse();
foreach ($menu_items as $regex => $redirect) {
    if (!empty($regex) && preg_match("/" . $regex . "/i", $body)) {
        $next = $redirect;
        break;
    }
}
if (!empty($next)) {
    $response->redirect($next);
}
$response->respond();
Esempio n. 12
0
<?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();
Esempio n. 13
0
<?php

include "foursquare_api.php";
$user = AppletInstance::getUserGroupPickerValue('4sq-venue-controller');
$user_id = $user->values["id"];
$foursquare_username = PluginStore::get("foursquare_username_{$user_id}", "");
$foursquare_password = PluginStore::get("foursquare_password_{$user_id}", "");
$default = AppletInstance::getDropZoneUrl('no-venue-default-action');
$response = new Response();
if (!empty($foursquare_username)) {
    $lastVenue = getLastVenue($foursquare_username, $foursquare_password);
    $venues = AppletInstance::getValue('venues[]');
    $venue_options = AppletInstance::getDropZoneUrl('venue-options[]');
    $found = false;
    if (is_array($keys)) {
        foreach ($venues as $id => $value) {
            if ($value == $lastVenue) {
                $response->addRedirect($venue_options[$id]);
                $found = true;
            }
        }
    }
    if (!$found) {
        $response->addRedirect($default);
    }
} else {
    $response->addRedirect($default);
}
$response->Respond();
Esempio n. 14
0
<?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();
Esempio n. 15
0
<?php

$response = new Response();
/* Fetch all the data to operate the menu */
$digits = isset($_REQUEST['Digits']) ? $_REQUEST['Digits'] : false;
$prompt = AppletInstance::getAudioSpeechPickerValue('prompt');
$invalid_option = AppletInstance::getAudioSpeechPickerValue('invalid-option');
$repeat_count = AppletInstance::getValue('repeat-count', 3);
$next = AppletInstance::getDropZoneUrl('next');
$selected_item = false;
/* Build Menu Items */
$choices = (array) AppletInstance::getDropZoneUrl('choices[]');
$keys = (array) AppletInstance::getDropZoneValue('keys[]');
$menu_items = AppletInstance::assocKeyValueCombine($keys, $choices);
$numDigits = 1;
foreach ($keys as $key) {
    if (strlen($key) > $numDigits) {
        $numDigits = strlen($key);
    }
}
if ($digits !== false) {
    if (!empty($menu_items[$digits])) {
        $selected_item = $menu_items[$digits];
    } else {
        if ($invalid_option) {
            $verb = AudioSpeechPickerWidget::getVerbForValue($invalid_option, null);
            $response->append($verb);
            $response->addRedirect();
        } else {
            $response->addSay('You selected an incorrect option.');
            $response->addRedirect();
Esempio n. 16
0
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;
Esempio n. 17
0
<?php

include "foursquare_api.php";
$user = AppletInstance::getUserGroupPickerValue('4sq-cat-controller');
$user_id = $user->values["id"];
$foursquare_username = PluginStore::get("foursquare_username_{$user_id}", "");
$foursquare_password = PluginStore::get("foursquare_password_{$user_id}", "");
$default = AppletInstance::getDropZoneUrl('4sq-cat-default-action');
$response = new Response();
if (!empty($foursquare_username)) {
    $lastVenue = getLastVenue($foursquare_username, $foursquare_password);
    $category = getCategory($lastVenue);
    $categories = AppletInstance::getValue('categories[]');
    $category_options = AppletInstance::getDropZoneUrl('category_options[]');
    $found = false;
    if (is_array($categories)) {
        foreach ($categories as $id => $value) {
            if ($value == $category) {
                $response->addRedirect($category_options[$id]);
                $found = true;
            }
        }
    }
    if (!$found) {
        $response->addRedirect($default);
    }
} else {
    $response->addRedirect($default);
}
$response->Respond();