Skip to content
This repository was archived by the owner on Mar 4, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 12 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
2 changes: 1 addition & 1 deletion OpenVBX/controllers/numbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,4 @@ public function refresh_select() {

$this->respond('', 'dialer/numbers', $response);
}
}
}
67 changes: 67 additions & 0 deletions OpenVBX/helpers/token_helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
$ci = &get_instance();

$ci->load->helper('format_helper');

function token_replace($input, $reset = false) {
static $tokens = null;

if(!isset($tokens) || $reset){
$tokens = array();
$token_names = token_names();
foreach ($token_names as $token) {
if(isset($_REQUEST[$token])) {
$tokens['{' . $token . '}'] = $_REQUEST[$token];
switch ($token) {
case 'To':
case 'From':
$tokens['{' . $token . '_Formatted}'] = format_phone($_REQUEST[$token]);
break;
default:
}
}
}
}

return strtr($input, $tokens);
}

function token_list() {
$token_list = '';
foreach(token_names() as $token){
$token_list .= "<li>{{$token}}</li>";
}
return "<ul>$token_list</ul>";
}

function token_names(){
return array(
'CallSid',
'AccountSid',
'From',
'To',
'CallStatus',
'ApiVersion',
'Direction',
'ForwardedFrom',
'CallerName',
'FromCity',
'FromState',
'FromZip',
'FromCountry',
'ToCity',
'ToState',
'ToZip',
'ToCountry',
'DialCallStatus',
'DialCallSid',
'DialCallDuration',
'RecordingUrl',

'MessageSid',
'Body',
'NumMedia',
'MediaContentType1',
'MediaUrl1',
);
}
9 changes: 9 additions & 0 deletions OpenVBX/libraries/User_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function __construct()
$this->load->model('vbx_rest_access');
$this->load->model('vbx_message');
$this->load->model('vbx_incoming_numbers');
$this->load->model('vbx_outgoing_caller_ids');
$this->load->model('vbx_device');

// When we're in testing mode, allow access to set Hiccup configuration
Expand Down Expand Up @@ -373,13 +374,21 @@ protected function get_twilio_numbers()
{
/* 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)
{
error_log($e->getMessage());
throw new User_ControllerException($e->getMessage());
/* Silent fail */
}

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 assets/c/applet.css
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@
.radio-table .radio-table-row.on .content-cell { background-color: #e5f6ff; }
.radio-table .radio-table-row.off .content-cell { background-color: #eee; }

.radio-table .radio-table-row.fist .content-cell {
.radio-table .radio-table-row.first .content-cell {
-moz-border-radius-topright: 4px; /* FF1+ */
-webkit-border-top-right-radius: 4px; /* Saf3+, Chrome */
-khtml-border-top-right-radius: 4px; /* Konqueror */
Expand Down
10 changes: 10 additions & 0 deletions plugins/sms/applets/sms/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$(document).ready(function(){
var app = $('.flow-instance.standard---sms');

$('.radio-table .radio-cell input', app).live('click', function(event) {
var table = $(event.target).closest('.radio-table');
var table_row = $(event.target).closest('.radio-table-row');
$('.radio-table-row', table).removeClass('on').addClass('off');
table_row.removeClass('off').addClass('on');
});
});
60 changes: 57 additions & 3 deletions plugins/sms/applets/sms/twiml.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,77 @@
<?php

$ci = &get_instance();

$ci->load->helper('format_helper');
$ci->load->helper('token_helper');
$ci->load->library('DialList');

$sms = AppletInstance::getValue('sms');
$next = AppletInstance::getDropZoneUrl('next');
$message_whom_selector = AppletInstance::getValue('message-whom-selector', 'caller');
$message_whom_user_or_group = AppletInstance::getUserGroupPickerValue('message-whom-user-or-group');
$message_whom_number = AppletInstance::getValue('message-whom-number');
$from_number = AppletInstance::getValue('from-number', null);

switch($message_whom_selector) {
case 'user-or-group':
// create a dial list from the input state
$dial_list = DialList::get($message_whom_user_or_group);

while ($device = $dial_list->next())
{
if ($device instanceof VBX_Device && $device->sms)
{
if (strpos($device->value, 'client:') !== false)
{
$to_number = str_replace('client:', '', $device->value);
}
else
{
$to_number = $device->value;
}
break;
}
}
break;
case 'number':
$to_number = normalize_phone_to_E164($message_whom_number);
break;
case 'caller':
default:
$to_number = $_REQUEST['From'];
}

if($from_number == '') {
$from_number = $_REQUEST['From'];
}
else if($from_number == 'called') {
$from_number = $_REQUEST['To'];
}

$sms = token_replace($sms);

$response = new TwimlResponse;

$message_opts = array(
'to' => $to_number,
'from' => $from_number,
);

// Call flows still use the legacy <Sms> TwiML
// for sending messages during calls.
if(AppletInstance::getFlowType() == 'voice')
{
$response->sms($sms);
$response->sms($sms, $message_opts);
}
else
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this the opposite of the PSR2 recommendation?
http://www.php-fig.org/psr/psr-2/#if-elseif-else

{
$response->message($sms);
$response->message($sms, $message_opts);
}

if(!empty($next))
{
$response->redirect($next);
}

$response->respond();
$response->respond();
Loading