Exemplo n.º 1
0
 /**
  * Validate that an incoming rest request is from Twilio
  *
  * @param string $failure_message
  * @return void
  */
 function validate_rest_request($failure_message = 'Could not validate this request. Goodbye.')
 {
     $ci =& get_instance();
     if ($ci->tenant->type == VBX_Settings::AUTH_TYPE_CONNECT) {
         return;
     }
     if (!OpenVBX::validateRequest()) {
         $response = new TwimlResponse();
         $response->say($failure_message, array('voice' => $ci->vbx_settings->get('voice', $ci->tenant->id), 'language' => $ci->vbx_settings->get('voice_language', $ci->tenant->id)));
         $response->hangup();
         $response->respond();
         exit;
     }
 }
Exemplo n.º 2
0
<?php

$const = array();
$const['STRIPE_ACTION'] = 'stripeAction';
$const['STRIPE_COOKIE'] = 'payment-' . AppletInstance::getInstanceId();
$const['GATHER_CARD'] = 'GatherCard';
$const['GATHER_MONTH'] = 'GatherMonth';
$const['GATHER_YEAR'] = 'GatherYear';
$const['GATHER_CVC'] = 'GatherCvc';
$const['SEND_PAYMENT'] = 'SendPayment';
foreach ($const as $k => $v) {
    define($k, $v);
}
$response = new TwimlResponse();
$state = array(STRIPE_ACTION => GATHER_CARD, 'card' => array());
$ci =& get_instance();
$settings = PluginData::get('settings');
$amount = AppletInstance::getValue('amount');
$description = AppletInstance::getValue('description');
$digits = clean_digits($ci->input->get_post('Digits'));
$finishOnKey = '#';
$timeout = 15;
$card_errors = array('invalid_number' => GATHER_CARD, 'incorrect_number' => GATHER_CARD, 'invalid_expiry_month' => GATHER_MONTH, 'invalid_expiry_year' => GATHER_YEAR, 'expired_card' => GATHER_CARD, 'invalid_cvc' => GATHER_CVC, 'incorrect_cvc' => GATHER_CVC);
if (is_object($settings)) {
    $settings = get_object_vars($settings);
}
if (isset($_COOKIE[STRIPE_COOKIE])) {
    $state = json_decode(str_replace(', $Version=0', '', $_COOKIE[STRIPE_COOKIE]), true);
    if (is_object($state)) {
        $state = get_object_vars($state);
    }
Exemplo n.º 3
0
$config['roommates'] = array(array("name" => 'Ryan', "number" => "415-555-5555"), array("name" => 'Mary', "number" => "415-555-5555"));
/**
 * The secret code you wish to use, you can disable this feature by setting
 * it to NULL.
 */
$config['secret'] = "1234";
/**
 * The voice you want the callbox to use, either "man" or "woman"
 */
$config['voice'] = "woman";
/**
 * Below here is where the magic happens.
 * Unless you know what you're doing, don't touch anything below.
 */
require_once "twilio.php";
$twiml = new TwimlResponse();
$parts = explode('/', $_SERVER["PHP_SELF"]);
$config['filename'] = $parts[count($parts) - 1];
switch ($_GET['page']) {
    case "gather":
        // handle routing to a roommate or to the secret code prompt
        $index = $_REQUEST['Digits'] - 1;
        if ($config['secret'] && $_REQUEST['Digits'] == '9') {
            // secret code is enabled and they accessed the secret menu, prompt for the code
            $gather = $twiml->addGather(array("action" => $config['filename'] . "?page=secret", "numDigits" => strlen($config['secret']), "method" => "POST"));
            $gather->addSay("Please enter the secret code now.", array("voice" => $config['voice']));
        } elseif (isset($config['roommates'][$index])) {
            // entered the digit for a valid roommate, forward the call
            $roommate = $config['roommates'][$index];
            $twiml->addSay("Connecting you to " . $roommate['name'], array("voice" => $config['voice']));
            $twiml->addDial($roommate['number']);
Exemplo n.º 4
0
<?php

$ci =& get_instance();
$flow_type = AppletInstance::getFlowType();
if ($flow_type != 'voice') {
    $orderid = $_REQUEST['Body'];
} else {
    $digits = clean_digits($ci->input->get_post('Digits'));
    if (!empty($digits)) {
        $orderid = $digits;
    }
}
$prefs = array('voice' => $ci->vbx_settings->get('voice', $ci->tenant->id), 'language' => $ci->vbx_settings->get('voice_language', $ci->tenant->id));
$response = new TwimlResponse();
if (!empty($orderid)) {
    $settings = PluginData::get('orders', array('keys' => array(), 'status' => array()));
    $statusArray = array('shipped' => 'Shipped', 'fullfillment' => 'Sent to Fullfillment', 'processing' => 'Processing');
    $s = '';
    $keys = $settings->keys;
    $status = $settings->status;
    foreach ($keys as $i => $key) {
        if ($key == $orderid) {
            $s = $statusArray[$status[$i]];
            break;
        }
    }
    if ($s != '') {
        $response->say("Your order is marked as {$s}.", $prefs);
        if (AppletInstance::getFlowType() == 'voice') {
            $next = AppletInstance::getDropZoneUrl('next');
            if (!empty($next)) {
Exemplo n.º 5
0
<?php

// The response object constructs the TwiML for our applet
$tResponse = new TwimlResponse();
//construct zendesk client object
define("ZDAPIKEY", AppletInstance::getValue('apitoken'));
define("ZDUSER", AppletInstance::getValue('email'));
define("ZDURL", "https://" . AppletInstance::getValue('subdomain') . ".zendesk.com/api/v2");
/* Note: do not put a trailing slash at the end of v2 */
function curlWrap($url, $json, $action)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
    curl_setopt($ch, CURLOPT_USERPWD, ZDUSER . "/token:" . ZDAPIKEY);
    $url = ZDURL . $url;
    switch ($action) {
        case "POST":
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
            break;
        case "GET":
            $url .= '?' . http_build_query($json, '', '&', PHP_QUERY_RFC3986);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
            break;
        case "PUT":
            curl_setopt($ch, CURLOPT_URL, ZDURL . $url);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
            curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
                    }
                }
                break;
            case 'VBX_Group':
                foreach ($dispatcher->users as $user) {
                    $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');
Exemplo n.º 7
0
<?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();
Exemplo n.º 8
0
<?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();
Exemplo n.º 9
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();
Exemplo n.º 10
0
<?php

$response = new TwimlResponse();
$forward = AppletInstance::getUserGroupPickerValue('forward');
$devices = array();
switch (get_class($forward)) {
    case 'VBX_User':
        foreach ($forward->devices as $device) {
            $devices[] = $device;
        }
        $voicemail = $forward->voicemail;
        break;
    case 'VBX_Group':
        foreach ($forward->users as $user) {
            $user = VBX_User::get($user->user_id);
            foreach ($user->devices as $device) {
                $devices[] = $device;
            }
        }
        $voicemail = $groupVoicemail;
        break;
    default:
        break;
}
$required_params = array('SmsSid', 'From', 'To', 'Body');
$sms_found = true;
foreach ($required_params as $param) {
    if (!in_array($param, array_keys($_REQUEST))) {
        $sms_found = false;
    }
}
Exemplo n.º 11
0
<?php

$sms = AppletInstance::getValue('sms');
$next = AppletInstance::getDropZoneUrl('next');
$response = new TwimlResponse();
$response->message($sms);
if (!empty($next)) {
    $response->redirect($next);
}
$response->respond();
Exemplo n.º 12
0
$defaultWaitUrl = 'http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient';
$waitUrl = AppletInstance::getValue('wait-url', $defaultWaitUrl);
$hasModerator = false;
if (!is_null($moderator)) {
    switch (get_class($moderator)) {
        case 'VBX_User':
            foreach ($moderator->devices as $device) {
                if ($device->value == $caller) {
                    $hasModerator = true;
                    $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) {
                        $hasModerator = true;
                        $isModerator = true;
                    }
                }
            }
            break;
    }
}
$confOptions = array('muted' => !$hasModerator || $isModerator ? 'false' : 'true', 'startConferenceOnEnter' => !$hasModerator || $isModerator ? 'true' : 'false', 'endConferenceOnExit' => $hasModerator && $isModerator ? 'true' : 'false', 'waitUrl' => $waitUrl);
$response = new TwimlResponse();
$dial = $response->dial();
$dial->conference($confName, $confOptions);
$response->respond();
Exemplo n.º 13
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();
Exemplo n.º 14
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();
Exemplo n.º 15
0
<?php

$sms = AppletInstance::getValue('sms');
$next = AppletInstance::getDropZoneUrl('next');
$response = new TwimlResponse();
$response->sms($sms);
if (!empty($next)) {
    $response->redirect($next);
}
$response->respond();
Exemplo n.º 16
0
<?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();
Exemplo n.º 17
0
 /**
  * Send the response
  *
  * @return void
  */
 public function respond()
 {
     $this->response->respond();
 }
Exemplo n.º 18
0
$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;
                    }
                }
            }
            break;
    }
}
$confOptions = array('muted' => !$hasModerator || $isModerator ? 'false' : 'true', 'startConferenceOnEnter' => !$hasModerator || $isModerator ? 'true' : 'false', 'endConferenceOnExit' => $hasModerator && $isModerator ? 'true' : 'false', 'waitUrl' => $waitUrl, 'record' => $record);
$response = new TwimlResponse();
$dial = $response->dial(null, array('timeout' => $ci->vbx_settings->get('dial_timeout', $ci->tenant->id), 'timeLimit' => 14400));
$dial->conference($confName, $confOptions);
$response->respond();
Exemplo n.º 19
0
<?php

define('PAYMENT_ACTION', 'paymentAction');
define('PAYMENT_COOKIE', 'payment-' . AppletInstance::getInstanceId());
define('STATE_GATHER_CARD', 'stateGatherCard');
define('STATE_GATHER_MONTH', 'stateGatherMonth');
define('STATE_GATHER_YEAR', 'stateGatherYear');
define('STATE_GATHER_CVC', 'stateGatherCvc');
define('STATE_SEND_PAYMENT', 'stateSendPayment');
$response = new TwimlResponse();
$state = array(PAYMENT_ACTION => STATE_GATHER_CARD, 'card' => array());
$ci =& get_instance();
$settings = PluginData::get('settings');
$amount = AppletInstance::getValue('amount');
$description = AppletInstance::getValue('description');
$digits = clean_digits($ci->input->get_post('Digits'));
$finishOnKey = '#';
$timeout = 15;
$card_errors = array('invalid_number' => STATE_GATHER_CARD, 'incorrect_number' => STATE_GATHER_CARD, 'invalid_expiry_month' => STATE_GATHER_MONTH, 'invalid_expiry_year' => STATE_GATHER_YEAR, 'expired_card' => STATE_GATHER_CARD, 'invalid_cvc' => STATE_GATHER_CVC, 'incorrect_cvc' => STATE_GATHER_CVC);
if (is_object($settings)) {
    $settings = get_object_vars($settings);
}
if (isset($_COOKIE[PAYMENT_COOKIE])) {
    $state = json_decode(str_replace(', $Version=0', '', $_COOKIE[PAYMENT_COOKIE]), true);
    if (is_object($state)) {
        $state = get_object_vars($state);
    }
}
if ($digits !== false) {
    switch ($state[PAYMENT_ACTION]) {
        case STATE_GATHER_CARD:
Exemplo n.º 20
0
 function hangup_on_cancel()
 {
     _deprecated_method(__METHOD__, '1.0.4');
     validate_rest_request();
     $response = new TwimlResponse();
     $response->hangup();
     return $response->respond();
 }
Exemplo n.º 21
0
<?php

$ci =& get_instance();
$response = new TwimlResponse();
$url = AppletInstance::getValue('url');
$numDigits = AppletInstance::getValue('glength');
$next = AppletInstance::getDropZoneUrl('next');
/* Fetch all the data to operate the menu */
$digits = isset($_REQUEST['Digits']) ? $ci->input->get_post('Digits') : false;
$prompt = AppletInstance::getAudioSpeechPickerValue('prompt');
if ($digits !== false) {
    $fields = array('Digits' => $digits);
    foreach ($_REQUEST as $name => $val) {
        $fields[$name] = $val;
    }
    $fields_string = http_build_query($fields);
    //  Initiate curl
    $ch = curl_init();
    // Disable SSL verification
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    // Will return the response, if false it print the response
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // Set the url
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, count($fields));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    // Execute
    $result = curl_exec($ch);
    // Closing
    curl_close($ch);
    $json = json_decode($result, true);
Exemplo n.º 22
0
<?php

$response = new TwimlResponse();
$response->hangup();
$response->respond();
Exemplo n.º 23
0
<?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->message($response_text);
$response->Respond();