Update page.lua

Add leading zero support to page.lua.
This commit is contained in:
FusionPBX 2016-06-30 15:08:14 -06:00 committed by GitHub
parent 118bcb132b
commit 35149d0ff3
1 changed files with 144 additions and 123 deletions

View File

@ -24,9 +24,10 @@
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
pin_number = "";
max_tries = "3";
digit_timeout = "3000";
--set default settings
pin_number = "";
max_tries = "3";
digit_timeout = "3000";
--define the trim function
require "resources.functions.trim";
@ -34,7 +35,22 @@ digit_timeout = "3000";
--define the explode function
require "resources.functions.explode";
if ( session:ready() ) then
--define the leading_zeros function
function leading_zeros(str)
zeros = '';
for i = 1, string.len(str) do
c = string.sub(str, i, i);
if (c == '0') then
zeros = zeros .. '0';
else
return zeros;
end
end
end
--make sure the session is ready
if ( session:ready() ) then
--answer the call
session:answer();
--get the dialplan variables and set them as local variables
destination_number = session:getVariable("destination_number");
@ -59,7 +75,7 @@ if ( session:ready() ) then
if (not default_dialect) then default_dialect = 'us'; end
if (not default_voice) then default_voice = 'callie'; end
local conf_name = "page-"..destination_number.."-"..domain_name.."@page"
local conference_name = "page-"..destination_number.."-"..domain_name.."@page"
if (caller_id_name) then
--caller id name provided do nothing
@ -117,7 +133,12 @@ if ( session:ready() ) then
value = value..'-'..value;
end
sub_table = explode("-",value);
zeros = leading_zeros(sub_table[1]);
for destination=sub_table[1],sub_table[2] do
--add the leading zeros back again
destination = zeros .. destination;
--get the destination required for number-alias
destination = api:execute("user_data", destination .. "@" .. domain_name .. " attr id");
@ -134,7 +155,7 @@ if ( session:ready() ) then
--this destination is the caller that initated the page
else
--originate the call
cmd_string = "bgapi originate {sip_auto_answer=true,sip_h_Alert-Info='Ring Answer',hangup_after_bridge=false,origination_caller_id_name='"..caller_id_name.."',origination_caller_id_number="..caller_id_number.."}user/"..destination.."@"..domain_name.." conference:"..conf_name.."+"..flags.." inline";
cmd_string = "bgapi originate {sip_auto_answer=true,sip_h_Alert-Info='Ring Answer',hangup_after_bridge=false,origination_caller_id_name='"..caller_id_name.."',origination_caller_id_number="..caller_id_number.."}user/"..destination.."@"..domain_name.." conference:"..conference_name.."+"..flags.." inline";
api:executeString(cmd_string);
destination_count = destination_count + 1;
end
@ -149,7 +170,7 @@ if ( session:ready() ) then
--this destination is the caller that initated the page
else
--originate the call
cmd_string = "bgapi originate {sip_auto_answer=true,hangup_after_bridge=false,origination_caller_id_name='"..caller_id_name.."',origination_caller_id_number="..caller_id_number.."}user/"..destination.."@"..domain_name.." conference:"..conf_name.."+"..flags.." inline";
cmd_string = "bgapi originate {sip_auto_answer=true,hangup_after_bridge=false,origination_caller_id_name='"..caller_id_name.."',origination_caller_id_number="..caller_id_number.."}user/"..destination.."@"..domain_name.." conference:"..conference_name.."+"..flags.." inline";
api:executeString(cmd_string);
destination_count = destination_count + 1;
end
@ -167,9 +188,9 @@ if ( session:ready() ) then
else
moderator_flag = "";
end
session:execute("conference", conf_name.."+flags{endconf"..moderator_flag.."}");
session:execute("conference", conference_name.."+flags{endconf"..moderator_flag.."}");
else
session:execute("playback", "tone_stream://%(500,500,480,620);loops=3");
end
end
end