This repository was archived by the owner on Mar 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 343
Added many features and fixes #376
Open
jmtorres
wants to merge
14
commits into
twilio:develop
Choose a base branch
from
jmtorres:dev-jmtorres
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7ed912a
Merge branch 'release/1.2.20'
Gipetto 22ea4fb
Allow verified numbers to be used as outgoing caller id
chadsmith 82ee4d1
Allow verified numbers to be used in OpenVBX mobile
chadsmith 8607061
Fixed value processing for form_dropdown optgroups in form_helper.
jmtorres 454d6b2
Fixed radio table row selector in css.
jmtorres 2adde7a
Added token_helper to use in message bodies.
jmtorres df4de8d
Added many features to sms plugin.
jmtorres a840dc4
Changed wording for caller id in sms applet.
jmtorres fa61707
Regrouped Outgoing Caller ID selector in dial applet.
jmtorres f42f839
Merge branch 'master' into dev-jmtorres
jmtorres fec7a46
Move outgoing caller id handling out of numbers controller.
jmtorres 5e3ed3c
Fixed brace formatting.
jmtorres 9bf75e3
Fixed rogue single quotes.
jmtorres 7de933b
Moved validate_rest_request response to handle request type properly.
jmtorres File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -421,4 +421,4 @@ public function refresh_select() { | |
|
|
||
| $this->respond('', 'dialer/numbers', $response); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| { | ||
| $response->message($sms); | ||
| $response->message($sms, $message_opts); | ||
| } | ||
|
|
||
| if(!empty($next)) | ||
| { | ||
| $response->redirect($next); | ||
| } | ||
|
|
||
| $response->respond(); | ||
| $response->respond(); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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