From f8103e1b370cdaf6e3ed7a65baf30800788a35ef Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Tue, 21 Oct 2014 22:57:29 +0000 Subject: [PATCH] Fix extension number-alias for extensions using paging. --- .../switch/conf/dialplan/250_page.xml | 2 +- resources/install/scripts/page.lua | 38 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/dialplan/resources/switch/conf/dialplan/250_page.xml b/app/dialplan/resources/switch/conf/dialplan/250_page.xml index cfea8b2b47..766d595934 100644 --- a/app/dialplan/resources/switch/conf/dialplan/250_page.xml +++ b/app/dialplan/resources/switch/conf/dialplan/250_page.xml @@ -26,7 +26,7 @@ - + diff --git a/resources/install/scripts/page.lua b/resources/install/scripts/page.lua index 705fc70420..be7de749cf 100644 --- a/resources/install/scripts/page.lua +++ b/resources/install/scripts/page.lua @@ -49,10 +49,13 @@ if ( session:ready() ) then pin_number = session:getVariable("pin_number"); domain_name = session:getVariable("domain_name"); sounds_dir = session:getVariable("sounds_dir"); - extension_list = session:getVariable("extension_list"); + destinations = session:getVariable("destinations"); + if (destinations == nil) then + destinations = session:getVariable("extension_list"); + end + destination_table = explode(",",destinations); caller_id_name = session:getVariable("caller_id_name"); caller_id_number = session:getVariable("caller_id_number"); - extension_table = explode(",",extension_list); sip_from_user = session:getVariable("sip_from_user"); mute = session:getVariable("mute"); @@ -119,24 +122,27 @@ if ( session:ready() ) then destination_count = 0; api = freeswitch.API(); - for index,value in pairs(extension_table) do + for index,value in pairs(destination_table) do if (string.find(value, "-") == nill) then value = value..'-'..value; end sub_table = explode("-",value); - for extension=sub_table[1],sub_table[2] do - --extension_exists = "username_exists id "..extension.."@"..domain_name; - --reply = trim(api:executeString(extension_exists)); + for destination=sub_table[1],sub_table[2] do + --get the destination required for number-alias + destination = api:execute("user_data", destination .. "@" .. domain_name .. " attr id"); + + --cmd = "username_exists id "..destination.."@"..domain_name; + --reply = trim(api:executeString(cmd)); --if (reply == "true") then - extension_status = "show channels like "..extension.."@"; - reply = trim(api:executeString(extension_status)); + destination_status = "show channels like "..destination.."@"; + reply = trim(api:executeString(destination_status)); if (reply == "0 total.") then - --freeswitch.consoleLog("NOTICE", "extension "..extension.." available\n"); - if (extension == tonumber(sip_from_user)) then - --this extension is the caller that initated the page + --freeswitch.consoleLog("NOTICE", "destination "..destination.." available\n"); + if (destination == tonumber(sip_from_user)) 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/"..extension.."@"..domain_name.." conference:page-"..destination_number.."@page+"..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:page-"..destination_number.."@page+"..flags.." inline"; api:executeString(cmd_string); destination_count = destination_count + 1; end @@ -144,14 +150,14 @@ if ( session:ready() ) then else --look inside the reply to check for the correct domain_name if string.find(reply, domain_name) then - --found: extension number is busy + --found: user is busy else --not found - if (extension == tonumber(sip_from_user)) then - --this extension is the caller that initated the page + if (destination == tonumber(sip_from_user)) 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/"..extension.."@"..domain_name.." conference:page-"..destination_number.."@page+"..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:page-"..destination_number.."@page+"..flags.." inline"; api:executeString(cmd_string); destination_count = destination_count + 1; end