diff --git a/.gitignore b/.gitignore index 44bbe755..077742e6 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ info.php memcache.php .idea /nbproject/* +.DS_Store \ No newline at end of file diff --git a/OpenVBX/controllers/numbers.php b/OpenVBX/controllers/numbers.php index e2229869..a91973a3 100644 --- a/OpenVBX/controllers/numbers.php +++ b/OpenVBX/controllers/numbers.php @@ -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() @@ -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; } diff --git a/OpenVBX/libraries/User_Controller.php b/OpenVBX/libraries/User_Controller.php index d09cbe69..7374a790 100644 --- a/OpenVBX/libraries/User_Controller.php +++ b/OpenVBX/libraries/User_Controller.php @@ -363,11 +363,14 @@ 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) { @@ -375,6 +378,10 @@ protected function get_twilio_numbers() throw new User_ControllerException($e->getMessage()); /* Silent fail */ } + catch (VBX_OutgoingCallerIdException $e) + { + throw new NumbersException($e->getMessage(), $e->getCode()); + } return $numbers; } diff --git a/OpenVBX/models/vbx_outgoing_caller_ids.php b/OpenVBX/models/vbx_outgoing_caller_ids.php new file mode 100644 index 00000000..a70be8e0 --- /dev/null +++ b/OpenVBX/models/vbx_outgoing_caller_ids.php @@ -0,0 +1,88 @@ +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); + } +} \ No newline at end of file diff --git a/plugins/standard/applets/dial/TwimlDial.php b/plugins/standard/applets/dial/TwimlDial.php index 208c61b9..2d0e7084 100644 --- a/plugins/standard/applets/dial/TwimlDial.php +++ b/plugins/standard/applets/dial/TwimlDial.php @@ -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; diff --git a/plugins/standard/applets/dial/ui.php b/plugins/standard/applets/dial/ui.php index 37011a94..73426ad8 100644 --- a/plugins/standard/applets/dial/ui.php +++ b/plugins/standard/applets/dial/ui.php @@ -1,14 +1,21 @@ 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);