/** * Start an outbound call * * @param string $from - the user making the call, this is the device that'll be called first * @param string $to - the call destination * @param string $callerid - the number to use as the caller id * @param string $rest_access - token to authenticate the twiml request * @return void */ public function make_call($from, $to, $callerid, $rest_access) { try { PhoneNumber::validatePhoneNumber($from); // handle being passed an email address for calls to browser clients if (!filter_var($to, FILTER_VALIDATE_EMAIL)) { PhoneNumber::validatePhoneNumber($to); } } catch (PhoneNumberException $e) { throw new VBX_CallException($e->getMessage()); } // don't normalize email addresses that are used to identify browser clients if (!filter_var($to, FILTER_VALIDATE_EMAIL)) { $to = PhoneNumber::normalizePhoneNumberToE164($to); } $callerid = PhoneNumber::normalizePhoneNumberToE164($callerid); $from = PhoneNumber::normalizePhoneNumberToE164($from); $twiml_url = site_url("twiml/dial") . '?' . http_build_query(compact('callerid', 'to', 'rest_access')); try { $account = OpenVBX::getAccount(); $account->calls->create($callerid, $from, $twiml_url); } catch (Exception $e) { throw new VBX_CallException($e->getMessage()); } }
function make_call($from, $to, $callerid, $rest_access) { try { PhoneNumber::validatePhoneNumber($from); PhoneNumber::validatePhoneNumber($to); } catch (PhoneNumberException $e) { throw new VBX_CallException($e->getMessage()); } $callerid = PhoneNumber::normalizePhoneNumberToE164($callerid); $from = PhoneNumber::normalizePhoneNumberToE164($from); $to = PhoneNumber::normalizePhoneNumberToE164($to); $twilio = new TwilioRestClient($this->twilio_sid, $this->twilio_token, $this->twilio_endpoint); $recording_url = site_url("twiml/dial") . '?' . http_build_query(compact('callerid', 'to', 'rest_access')); $response = $twilio->request("Accounts/{$this->twilio_sid}/Calls", 'POST', array("Caller" => $callerid, "Called" => $from, "Url" => $recording_url)); if ($response->IsError) { error_log($from); throw new VBX_CallException($response->ErrorMessage); } }
function save() { if (!strlen($this->name)) { throw new VBX_DeviceException('Name is empty'); } try { PhoneNumber::validatePhoneNumber($this->value); } catch (PhoneNumberException $e) { throw new VBX_DeviceException($e->getMessage()); } return parent::save(); }
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); }
function make_call($from, $to, $callerid, $rest_access) { try { PhoneNumber::validatePhoneNumber($from); PhoneNumber::validatePhoneNumber($to); } catch (PhoneNumberException $e) { throw new VBX_CallException($e->getMessage()); } $twilio = new TwilioRestClient($this->twilio_sid, $this->twilio_token, $this->twilio_endpoint); $recording_url = site_url("twiml/dial/{$callerid}/{$to}/{$rest_access}"); $response = $twilio->request("Accounts/{$this->twilio_sid}/Calls", 'POST', array("Caller" => $callerid, "Called" => $from, "Url" => $recording_url)); if ($response->IsError) { error_log($from); throw new VBX_CallException($response->ErrorMessage); } }