Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Allow verified numbers to be used as outgoing caller id #259

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ info.php
memcache.php
.idea
/nbproject/*
.DS_Store
7 changes: 7 additions & 0 deletions OpenVBX/controllers/numbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function __construct()
$this->section = 'numbers';
$this->template->write('title', 'Numbers');
$this->load->model('vbx_incoming_numbers');
$this->load->model('vbx_outgoing_caller_ids');
}

function index()
Expand Down Expand Up @@ -347,11 +348,17 @@ private function get_outgoingcallerid()
try
{
$numbers = $this->vbx_incoming_numbers->get_numbers();
$callerIds = $this->vbx_outgoing_caller_ids->get_caller_ids();
$numbers = array_merge($numbers, $callerIds);
}
catch (VBX_IncomingNumberException $e)
{
throw new NumbersException($e->getMessage(), $e->getCode());
}
catch (VBX_OutgoingCallerIdException $e)
{
throw new NumbersException($e->getMessage(), $e->getCode());
}

return $numbers;
}
Expand Down
7 changes: 7 additions & 0 deletions OpenVBX/libraries/User_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,25 @@ protected function message_counts()
protected function get_twilio_numbers()
{
$this->load->model('vbx_incoming_numbers');
$this->load->model('vbx_outgoing_caller_ids');
$numbers = array();
try
{
/* Retrieve twilio numbers w/o sandbox */
$numbers = $this->vbx_incoming_numbers->get_numbers();
$callerIds = $this->vbx_outgoing_caller_ids->get_caller_ids();
$numbers = array_merge($numbers, $callerIds);
}
catch(VBX_IncomingNumberException $e)
{
error_log($e->getMessage());
throw new User_ControllerException($e->getMessage());
/* Silent fail */
}
catch (VBX_OutgoingCallerIdException $e)
{
throw new NumbersException($e->getMessage(), $e->getCode());
}

return $numbers;
}
Expand Down
88 changes: 88 additions & 0 deletions OpenVBX/models/vbx_outgoing_caller_ids.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* "The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/

* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.

* The Original Code is OpenVBX, released June 15, 2010.

* The Initial Developer of the Original Code is Twilio Inc.
* Portions created by Twilio Inc. are Copyright (C) 2010.
* All Rights Reserved.

* Contributor(s):
**/

require_once(APPPATH . 'libraries/twilio.php');

class VBX_OutgoingCallerIdException extends Exception {}

class VBX_Outgoing_caller_ids extends Model
{
public function __construct()
{
parent::__construct();
}

public function get_caller_ids()
{
$ci =& get_instance();
$cache_key = 'outgoing-caller-ids';
if ($cache = $ci->api_cache->get($cache_key, __CLASS__, $ci->tenant->id))
{
return $cache;
}

$caller_ids = array();
try {
$account = OpenVBX::getAccount();
foreach ($account->outgoing_caller_ids as $caller_id)
{
// check that caller_id is a proper instance type
$caller_ids[] = $this->parseOutgoingCallerId($caller_id);
}
}
catch (Exception $e) {
$msg = 'Unable to fetch Numbers: ';
switch ($e->getCode())
{
case 20003:
$msg .= 'Authentication Failed.';
break;
default:
$msg .= $e->getMessage();
}
throw new VBX_OutgoingCallerIdException($msg, $e->getCode());
}

$ci->api_cache->set('outgoing-caller-ids', $caller_ids, __CLASS__, $ci->tenant->id);

return $caller_ids;
}

private function parseOutgoingCallerId($item)
{
$num = new stdClass();
$num->id = $item->sid;
$num->name = $item->friendly_name;
$num->phone = format_phone($item->phone_number);
$num->phone_number = $item->phone_number;
$num->capabilities = new stdClass();
$num->capabilities->voice = true;
$num->capabilities->sms = false;

return $num;
}

protected function clear_cache()
{
$ci =& get_instance();
$ci->api_cache->invalidate(__CLASS__, $ci->tenant->id);
}
}
2 changes: 1 addition & 1 deletion plugins/standard/applets/dial/TwimlDial.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TwimlDial {
private $use_ci_session = true;

static $hangup_stati = array('completed', 'answered');
static $voicemail_stati = array('no-answer', 'failed');
static $voicemail_stati = array('no-answer', 'failed', 'busy');
static $default_voicemail_message = 'Please leave a message. Press the pound key when you are finished.';

protected $cookie_name;
Expand Down
7 changes: 7 additions & 0 deletions plugins/standard/applets/dial/ui.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<?php
$ci =& get_instance();
$ci->load->model('vbx_incoming_numbers');
$ci->load->model('vbx_outgoing_caller_ids');

try {
$numbers = $ci->vbx_incoming_numbers->get_numbers();
$callerIds = $ci->vbx_outgoing_caller_ids->get_caller_ids();
$numbers = array_merge($numbers, $callerIds);
}
catch (VBX_IncomingNumberException $e) {
log_message('Incoming numbers exception: '.$e->getMessage.' :: '.$e->getCode());
$numbers = array();
}
catch (VBX_OutgoingCallerIdException $e) {
log_message('Outgoing callerids exception: '.$e->getMessage.' :: '.$e->getCode());
$numbers = array();
}

$callerId = AppletInstance::getValue('callerId', null);
$version = AppletInstance::getValue('version', null);
Expand Down