示例#1
0
 protected function init_browserphone_data($callerid_numbers)
 {
     // defaults
     $browserphone = array('call_using' => 'browser', 'caller_id' => '(000) 000-0000', 'number_options' => array(), 'call_using_options' => array('browser' => array('title' => 'Your Computer', 'data' => array())), 'devices' => array());
     $default_caller_id = false;
     if (is_array($callerid_numbers) && !empty($callerid_numbers)) {
         $numbered = $named = array();
         $default_caller_id = current($callerid_numbers)->phone;
         foreach ($callerid_numbers as $number) {
             if (normalize_phone_to_E164($number->phone) != normalize_phone_to_E164($number->name)) {
                 $named[$number->phone] = $number->name;
             } else {
                 $numbered[$number->phone] = $number->phone;
             }
         }
         ksort($numbered);
         asort($named);
         $browserphone['number_options'] = $named + $numbered;
     }
     $user = VBX_User::get(array('id' => $this->session->userdata('user_id')));
     // User preferences
     $browserphone['caller_id'] = $user->setting('browserphone_caller_id', $default_caller_id);
     $browserphone['call_using'] = $user->setting('browserphone_call_using', 'browser');
     // Wether the user has an active device to use
     if (count($user->devices)) {
         foreach ($user->devices as $device) {
             if (strpos($device->value, 'client:') !== false) {
                 continue;
             }
             $browserphone['call_using_options']['device:' . $device->id] = array('title' => 'Device: ' . $device->name, 'data' => (object) array('number' => format_phone($device->value), 'name' => $device->name));
         }
     }
     return $browserphone;
 }
示例#2
0
 /**
  * Display the popup for making calls with Twilio Client
  *
  * @return void
  */
 public function client()
 {
     $caller_id = $this->input->get('callerid');
     if (empty($caller_id)) {
         // grab user's default device
         $user = VBX_User::get($this->session->userdata['user_id']);
         $devices = $this->vbx_device->get_by_user($this->user_id);
         if (!empty($devices)) {
             $caller_id = $devices[0]->value;
         }
     }
     $client_params = array('callerid' => normalize_phone_to_E164($caller_id), 'application_id' => 'client');
     if ($this->input->get('outgoing')) {
         // functionality for using the "dial" modal to initiate a call
         $to = normalize_phone_to_E164($this->input->get('to'));
         if (empty($to)) {
             $to = htmlspecialchars($this->input->get('to'));
         }
         $client_params = array_merge($client_params, array('to' => $to));
     } elseif ($this->input->get('incoming')) {
         $client_params = array_merge($client_params, array('incoming' => true));
     }
     $client_data = array('client_params' => json_encode($client_params));
     $javascript = $this->load->view('client_js', $client_data, true);
     $this->template->add_js($javascript, 'embed', true);
     $data = array('title' => 'dialer', 'client_params' => $client_params);
     $this->respond('Dialer', 'call', $data, '', 'layout/dialer');
 }
function limit_exceeded($duration, $enabled, $instance_id, $limit)
{
    if (!$enabled) {
        return false;
    }
    //throttling disabled
    $number = normalize_phone_to_E164($_REQUEST['From']);
    $data = PluginData::get($instance_id . "__" . $number);
    $duration = intval($duration) * 60;
    //convert it into seconds
    if (!$data) {
        PluginData::set($instance_id . "__" . $number, array('limit' => 1, 'added' => time()));
        return false;
    }
    //clean expired time
    if (!empty($data->added) && time() - $data->added > $duration) {
        PluginData::set($instance_id . "__" . $number, array('limit' => 0, 'added' => time()));
        $data = PluginData::get($instance_id . "__" . $number);
    }
    if ($data->limit >= $limit && time() - $data->added <= $duration) {
        PluginData::set($instance_id . "__" . $number, array('limit' => $data->limit + 1, 'added' => $data->added));
        return true;
    } else {
        PluginData::set($instance_id . "__" . $number, array('limit' => $data->limit + 1, 'added' => $data->added));
        return false;
    }
}
 public function render($data = array())
 {
     $hasValue = empty($this->mode) ? false : true;
     $this->load =& load_class('Loader');
     $this->load->model('vbx_audio_file');
     $this->load->model('vbx_device');
     // Get a list of all previously recorded items so we can populate the library
     $ci =& get_instance();
     $ci->db->where('url IS NOT NULL');
     $ci->db->where('tag', $this->tag);
     $ci->db->where('tenant_id', $ci->tenant->id);
     $ci->db->from('audio_files');
     $ci->db->order_by('created DESC');
     $results = $ci->db->get()->result();
     foreach ($results as $i => $result) {
         $results[$i] = new VBX_Audio_File($result);
     }
     // Pre-fill the record text field with the the first device phone number we
     // find for the current user that is active.
     $ci =& get_instance();
     $user = VBX_User::get($ci->session->userdata('user_id'));
     $user_phone = '';
     if (count($user->devices)) {
         foreach ($user->devices as $device) {
             if ($device->is_active) {
                 $user_phone = format_phone($device->value);
                 break;
             }
         }
     }
     // set the caller id for recording via the phone
     $caller_id = '';
     $ci->load->model('vbx_incoming_numbers');
     try {
         $numbers = $ci->vbx_incoming_numbers->get_numbers(false);
         foreach ($numbers as $number) {
             // find the first number that has voice enabled
             // yes, this is a rather paranoid check
             if (isset($number->capabilities->voice) && $number->capabilities->voice > 0) {
                 $caller_id = normalize_phone_to_E164($number->phone);
                 break;
             }
         }
     } catch (VBX_IncomingNumberException $e) {
         // fail silently, for better or worse
         error_log($e->getMessage());
     }
     $data = array_merge(array('name' => $this->name, 'hasValue' => $hasValue, 'mode' => $this->mode, 'say' => $this->say_value, 'play' => $this->play_value, 'tag' => $this->tag, 'library' => $results, 'first_device_phone_number' => $user_phone, 'caller_id' => $caller_id), $data);
     return parent::render($data);
 }
示例#5
0
文件: ui.php 项目: JeffaCubed/OpenVBX
						</div>
				</td>
			</tr>
		</table>
	</div>

	<br />
	<h2>Caller ID</h2>
	<div class="vbx-full-pane">
		<fieldset class="vbx-input-container">
			<select class="medium" name="callerId">
				<option value="">Caller's Number</option>
<?php 
if (count($numbers)) {
    foreach ($numbers as $number) {
        $number->phone = normalize_phone_to_E164($number->phone);
        ?>
				<option value="<?php 
        echo $number->phone;
        ?>
"<?php 
        echo $number->phone == $callerId ? ' selected="selected" ' : '';
        ?>
><?php 
        echo $number->name;
        ?>
</option>
<?php 
    }
}
?>
示例#6
0
 function notify_message($message)
 {
     $ci =& get_instance();
     $ci->load->model('vbx_user');
     $ci->load->model('vbx_group');
     $ci->load->model('vbx_incoming_numbers');
     $recording_host = $ci->settings->get('recording_host', VBX_PARENT_TENANT);
     $vm_url = $message->content_url;
     if (!empty($recording_host) && trim($recording_host) != '') {
         $vm_url = str_replace('api.twilio.com', trim($recording_host), $vm_url);
     }
     $message->content_url = $vm_url;
     $users = array();
     $notify = array();
     if ($message->owner_type == 'user') {
         $user = VBX_User::get($message->owner_id);
         if (!empty($user->email)) {
             $notify[] = $user->email;
         }
     }
     $group_users = array();
     if ($message->owner_type == 'group') {
         $user_ids = $ci->vbx_group->get_user_ids($message->owner_id);
         $group = $ci->vbx_group->get_by_id($message->owner_id);
         $owner = $group->name;
     } else {
         if ($message->owner_type == 'user') {
             $user_ids = array($message->owner_id);
             $owner = 'Personal';
         }
     }
     $notification_setting = 'email_notifications_' . $message->type;
     $email_notify = $ci->vbx_settings->get($notification_setting, $ci->tenant->id);
     // check the incoming number's capabilities and don't even try to send
     // an SMS notification if the number is not allowed to send SMS messages
     $incoming_number = VBX_Incoming_numbers::get(array('phone_number' => normalize_phone_to_E164($message->called)));
     if (!empty($incoming_number) && $incoming_number->capabilities->sms == 1) {
         $sms_notify = true;
     }
     if ($email_notify || $sms_notify) {
         foreach ($user_ids as $user_id) {
             $user = VBX_User::get($user_id);
             $ci->load->model('vbx_device');
             $ci->load->model('vbx_sms_message');
             $numbers = VBX_Device::search(array('user_id' => $user_id));
             $message_type = 'Voicemail';
             if ($message->type == 'sms') {
                 $message_type = 'SMS';
                 $owner = '';
             }
             if ($email_notify) {
                 $email_subject = "New {$owner} {$message_type} Notification - {$message->caller}";
                 openvbx_mail($user->email, $email_subject, 'message', compact('message'));
             }
             if ($sms_notify) {
                 foreach ($numbers as $number) {
                     if ($number->value && $number->sms) {
                         try {
                             $ci->vbx_sms_message->send_message($message->called, $number->value, $this->tiny_notification_message($message));
                         } catch (VBX_Sms_messageException $e) {
                             log_message('error', 'unable to send sms alert, reason: ' . $e->getMessage());
                         }
                     }
                 }
             }
             // if ($sms_notify)
         }
     }
     // if ($email_notify || $sms_notify)
 }
示例#7
0
<?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

$ci =& get_instance();
$dispatcher = AppletInstance::getUserGroupPickerValue('dispatcher');
$list = AppletInstance::getValue('list');
$dispatch = false;
if (!empty($_REQUEST['From'])) {
    $sender = normalize_phone_to_E164($_REQUEST['From']);
    $number = normalize_phone_to_E164($_REQUEST['To']);
    $body = $_REQUEST['Body'];
    if (is_null($dispatcher)) {
        $dispatch = true;
    } else {
        switch (get_class($dispatcher)) {
            case 'VBX_User':
                foreach ($dispatcher->devices as $device) {
                    if ($sender == $device->value) {
                        $dispatch = true;
                    }
                }
                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;
                        }
                    }
                }
        }
示例#9
0
<?php

$ci =& get_instance();
$poll = AppletInstance::getValue('poll');
$option = AppletInstance::getValue('option');
$number = 'voice' == AppletInstance::getFlowType() ? normalize_phone_to_E164($_REQUEST['Caller']) : normalize_phone_to_E164($_REQUEST['From']);
$ci->db->delete('polls_responses', array('poll' => $poll, 'value' => $number));
$ci->db->insert('polls_responses', array('poll' => $poll, 'value' => $number, 'response' => $option, 'time' => time()));
$response = new Response();
$next = AppletInstance::getDropZoneUrl('next');
if (!empty($next)) {
    $response->addRedirect($next);
}
$response->Respond();
示例#10
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();
示例#11
0
 public function get_by_number($number, $user_id)
 {
     $number = normalize_phone_to_E164($number);
     $search_opts = array('user_id' => intval($user_id), 'value' => normalize_phone_to_E164($number));
     $device = parent::search(self::$__CLASS__, $this->table, $search_opts, array(), 1);
     return $device;
 }
示例#12
0
 private function add_number()
 {
     $number = array();
     $number = $this->input->post('number');
     $number['value'] = normalize_phone_to_E164($number['value']);
     $number['user_id'] = $this->user_id;
     // sms is always enabled by default
     $number['sms'] = 1;
     try {
         if (empty($number['value']) || empty($number['name'])) {
             $message = 'All fields required';
             throw new VBX_DeviceException($message);
         }
         $number_id = $this->vbx_device->add($number);
         $response = array('error' => false, 'message' => '', 'id' => $number_id, 'name' => htmlspecialchars($number['name']), 'value' => format_phone($number['value']), 'sms' => $number['sms']);
     } catch (VBX_DeviceException $e) {
         $response = array('error' => true, 'message' => $e->getMessage());
     }
     $data['json'] = $response;
     if ($this->response_type == 'html') {
         redirect('account');
     }
     return $this->respond('', 'account', $data);
 }
<?php

$user = OpenVBX::getCurrentUser();
$tenant_id = $user->values['tenant_id'];
$ci =& get_instance();
if (!empty($_POST['recipient'])) {
    $account = OpenVBX::getAccount();
    $id = intval($_POST['flow']);
    if (($flow = OpenVBX::getFlows(array('id' => $id, 'tenant_id' => $tenant_id))) && $flow[0]->values['data']) {
        $account->calls->create($_POST['number'], normalize_phone_to_E164($_POST['recipient']), site_url('twiml/start/voice/' . $id));
    }
}
$flows = OpenVBX::getFlows(array('tenant_id' => $tenant_id));
?>
<style>
	.vbx-outbound form {
		padding: 20px 5%;
	}
</style>
<div class="vbx-content-main">
	<div class="vbx-content-menu vbx-content-menu-top">
		<h2 class="vbx-content-heading">Start Flow</h2>
	</div>
    <div class="vbx-table-section vbx-outbound">
		<form method="post" action="">
			<fieldset class="vbx-input-container">
<?php 
if (count($callerid_numbers)) {
    ?>
				<p>
					<label class="field-label">Number<br/>
示例#14
0
 private function save_user()
 {
     $errors = array();
     $user = false;
     $id = intval($this->input->post('id'));
     $auth_type = $this->input->post('auth_type');
     $error = false;
     $message = "Failed to save user for unknown reason.";
     $shouldGenerateNewPassword = false;
     $device_id_str = trim($this->input->post('device_id'));
     $device_number = trim($this->input->post('device_number'));
     $shouldSendWelcome = false;
     try {
         PhoneNumber::validatePhoneNumber($device_number);
     } catch (PhoneNumberException $e) {
         $data['json'] = array('error' => true, 'message' => $e->getMessage());
         return $this->respond('', 'accounts', $data);
     }
     if (!empty($auth_type)) {
         $auth_type = $this->vbx_user->get_auth_type($auth_type);
     }
     if ($id > 0) {
         $user = VBX_User::get($id);
     } else {
         $user = VBX_User::get(array('email' => $this->input->post('email')));
         if (!empty($user) && $user->is_active == 1) {
             $error = true;
             $message = 'Email address is already in use.';
         } elseif (!empty($user) && $user->is_active == 0) {
             // It's an old account that was made inactive.  By re-adding it, we're
             // assuming the user wants to re-instate the old account.
             $shouldSendWelcome = true;
         } else {
             // It's a new user
             $user = new VBX_User();
             $user->online = 9;
             $shouldSendWelcome = true;
         }
     }
     if (!$error) {
         $fields = array('first_name', 'last_name', 'email', 'is_admin');
         foreach ($fields as $field) {
             $user->{$field} = $this->input->post($field);
         }
         $user->is_active = TRUE;
         $user->auth_type = isset($auth_type->id) ? $auth_type->id : 1;
         try {
             $user->save();
             if ($shouldSendWelcome) {
                 $user->send_new_user_notification();
             }
         } catch (VBX_UserException $e) {
             $error = true;
             $message = $e->getMessage();
             log_message('error', 'Unable to send new user notification: ' . $message);
         }
         if (!$error) {
             if (strlen($device_number) > 0) {
                 // We're adding or modifying an existing device
                 if (strlen($device_id_str) > 0) {
                     // We're updating an existing record
                     $device_id = intval($device_id_str);
                     $device = VBX_Device::get($device_id);
                     $device->value = normalize_phone_to_E164($device_number);
                     try {
                         $device->save();
                     } catch (VBX_DeviceException $e) {
                         $error = true;
                         $message = 'Failed to update device: ' . $e->getMessage();
                     }
                 } else {
                     // We're creating a new device record
                     $number = array("name" => "Primary Device", "value" => normalize_phone_to_E164($device_number), "user_id" => $user->id, "sms" => 1);
                     try {
                         $new_device_id = $this->vbx_device->add($number);
                     } catch (VBX_DeviceException $e) {
                         $error = true;
                         $message = "Failed to add device: " . $e->getMessage();
                     }
                 }
             } else {
                 if (strlen($device_number) == 0 && strlen($device_id_str) > 0) {
                     // We're deleting a device
                     try {
                         $this->vbx_device->delete(intval($device_id_str), $user->id);
                     } catch (VBX_DeviceException $e) {
                         $error = true;
                         $message = "Unable to delete device entry: " . $e->getMessage();
                     }
                 }
             }
         }
     }
     if ($error) {
         $json = array('error' => $error, 'message' => $message);
     } else {
         $json = array('id' => $user->id, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'is_active' => $user->is_active, 'is_admin' => $user->is_admin, 'notification' => $user->notification, 'auth_type' => isset($auth_type->description) ? $auth_type->description : 'openvbx', 'email' => $user->email, 'error' => false, 'message' => '', 'online' => $user->online);
     }
     $data['json'] = $json;
     $this->respond('', 'accounts', $data);
 }
示例#15
0
<?php

$ci =& get_instance();
$ci->load->helper('format');
$flow_type = AppletInstance::getFlowType();
$next = AppletInstance::getDropZoneUrl('next');
$from = normalize_phone_to_E164($_POST['From']);
$blacklist = explode("\n", trim(AppletInstance::getValue('blacklist')));
foreach ($blacklist as $key => $value) {
    $blacklist[$key] = normalize_phone_to_E164($value);
}
$response = new TwimlResponse();
if (in_array($from, $blacklist)) {
    //reject calls
    if ($flow_type == 'voice') {
        $response->reject();
    } else {
        //empty response for sms
    }
} else {
    $response->redirect($next);
}
$response->respond();
示例#16
0
<?php

$moderator = AppletInstance::getUserGroupPickerValue('moderator');
$confId = AppletInstance::getValue('conf-id');
$confName = AppletInstance::getInstanceId() . $confId;
$caller = normalize_phone_to_E164(isset($_REQUEST['Caller']) ? $_REQUEST['Caller'] : '');
$isModerator = false;
$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;
示例#17
0
 /**
  * Dial a number directly, no special sauce here
  *
  * @param string $number 
  * @return bool
  */
 public function dialNumber($number)
 {
     $dial = $this->getDial();
     $number = normalize_phone_to_E164($number);
     $dial->number($number);
     $this->state = 'calling';
     return true;
 }
        $ci->db->delete('subscribers_lists', array('id' => $remove, 'tenant' => $tenant_id));
        if ($ci->db->affected_rows()) {
            $ci->db->delete('subscribers', array('list' => $remove));
        }
    }
    die;
}
if (!empty($_POST['type'])) {
    $list = intval($_POST['list']);
    if ($ci->db->query(sprintf('SELECT id FROM subscribers_lists WHERE id = %d AND tenant = %d', $list, $tenant_id))->num_rows()) {
        $subscribers = $ci->db->query(sprintf('SELECT value FROM subscribers WHERE list = %d', $list))->result();
    } else {
        $subscribers = array();
    }
    $type = $_POST['type'];
    $callerId = normalize_phone_to_E164($_POST['callerId']);
    $account = OpenVBX::getAccount();
    if ('sms' == $type && !empty($_POST['message'])) {
        if (count($subscribers)) {
            foreach ($subscribers as $subscriber) {
                $account->sms_messages->create($callerId, $subscriber->value, $_POST['message']);
            }
        }
    } elseif ('call' == $type) {
        $flow = OpenVBX::getFlows(array('id' => $_POST['flow'], 'tenant_id' => $tenant_id));
        if ($flow && count($subscribers) && $flow[0]->values['data']) {
            foreach ($subscribers as $subscriber) {
                $account->calls->create($callerId, $subscriber->value, site_url('twiml/start/voice/' . $flow[0]->values['id']));
            }
        }
    }
<?php

$ci =& get_instance();
$list = AppletInstance::getValue('list');
$direction = isset($_REQUEST['Direction']) ? $_REQUEST['Direction'] : 'inbound';
if (!empty($_REQUEST['From'])) {
    $number = normalize_phone_to_E164(in_array($direction, array('inbound', 'incoming')) ? $_REQUEST['From'] : $_REQUEST['To']);
    $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();
示例#20
0
 function dial()
 {
     $rest_access = $this->input->get_post('rest_access');
     $to = $this->input->get_post('to');
     $callerid = $this->input->get_post('callerid');
     if (!$this->session->userdata('loggedin') && !$this->login_call($rest_access)) {
         $this->response->addSay("Unable to authenticate this call.\tGoodbye");
         $this->response->addHangup();
         $this->response->Respond();
         return;
     }
     /* Response */
     log_message('info', $rest_access . ':: Session for phone call: ' . var_export($this->session->userdata('user_id'), true));
     $user = VBX_User::get($this->session->userdata('user_id'));
     $name = '';
     if (empty($user)) {
         log_message('error', 'Unable to find user: '******'user_id'));
     } else {
         $name = $user->first_name;
     }
     if ($this->request->Digits !== false && $this->request->Digits == 1) {
         $options = array('action' => site_url("twiml/dial_status") . '?' . http_build_query(compact('to')), 'callerId' => $callerid);
         $dial_client = false;
         $to = normalize_phone_to_E164($to);
         if (!is_numeric($to)) {
             //$to = htmlspecialchars($this->input->get_post('to'));
             // look up user by email address
             $user = VBX_User::get(array('email' => $this->input->get_post('to')));
             if (!empty($user)) {
                 $dial_client = true;
                 $to = $user->id;
             }
         }
         if (!$dial_client) {
             $this->response->addDial($to, $options);
         } else {
             $dial = new Dial(NULL, $options);
             $dial->append(new Client($to));
             $this->response->append($dial);
         }
     } else {
         $gather = $this->response->addGather(array('numDigits' => 1));
         $gather->addSay("Hello {$name}, this is a call from v b x" . ", to accept, press 1.");
     }
     $this->response->Respond();
 }
示例#21
0
 function get_by_number($number, $user_id)
 {
     $number = normalize_phone_to_E164($number);
     $ci =& get_instance();
     return $ci->db->from($this->table)->where('user_id', $user_id)->where('value', $number)->where('tenant_id', $ci->tenant->id)->get()->row();
 }
示例#22
0
 /**
  * Dial
  * 
  * Callback method that responds to a Twilio request and provides
  * a number for Twilio to dial.
  * 
  * Overloaded by Twilio Client integration - Twilio Client connection
  * requests automatically include the "1" Digit to immediately connect
  * the call
  *
  * @return void
  */
 public function dial()
 {
     validate_rest_request();
     $rest_access = $this->input->get_post('rest_access');
     $to = $this->input->get_post('to');
     $callerid = $this->input->get_post('callerid');
     if (!$this->session->userdata('loggedin') && !$this->login_call($rest_access)) {
         $this->response->say("Unable to authenticate this call.\tGoodbye", $this->say_params);
         $this->response->hangup();
         $this->response->respond();
         return;
     }
     // Response
     $user = VBX_User::get($this->session->userdata('user_id'));
     $name = '';
     if (empty($user)) {
         log_message('error', 'Unable to find user: '******'user_id'));
     } else {
         $name = $user->first_name;
     }
     $digits = clean_digits($this->input->get_post('Digits'));
     if ($digits !== false && $digits == 1) {
         $options = array('action' => site_url("twiml/dial_status") . '?' . http_build_query(compact('to')), 'callerId' => $callerid);
         if (filter_var($this->input->get_post('to'), FILTER_VALIDATE_EMAIL)) {
             $this->dial_user_by_email($this->input->get_post('to'), $options);
         } elseif (preg_match('|client:[0-9]{1,4}|', $this->input->get_post('to'))) {
             $this->dial_user_by_client_id($this->input->get_post('to'), $options);
         } else {
             $to = normalize_phone_to_E164($to);
             $this->response->dial($to, $options);
         }
     } else {
         $gather = $this->response->gather(array('numDigits' => 1));
         $gather->say("Hello {$name}, this is a call from VeeBee Ex, to accept, press 1.", $this->say_params);
     }
     $this->response->respond();
 }
        case "DELETE":
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
            break;
        default:
            break;
    }
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
    curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    $output = curl_exec($ch);
    curl_close($ch);
    $decoded = json_decode($output, TRUE);
    return $decoded;
}
$phone = normalize_phone_to_E164($_REQUEST['From']);
$phone = str_replace('+', '', $phone);
//zendesk api call
$response = curlWrap("/search.json", array("query" => "type:user phone:" . $phone), "GET");
if ($response['count'] == 0) {
    //create a new user
    $response = curlWrap("/users.json", json_encode(array("user" => array("name" => "Anonymous Caller | " . $phone, "phone" => $phone))), "POST");
    //create a new ticket in the new user's name
    $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;
        }