From 2bcb3b343bcdde61658c8a3372ffe2f9e5c62847 Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Mon, 2 Aug 2021 16:47:47 -0600 Subject: [PATCH] Replace show channels like Like statement failed for a customer replaced with show channels then search the results to destination is available or busy. --- app/scripts/resources/scripts/page.lua | 55 +++++++++++--------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/app/scripts/resources/scripts/page.lua b/app/scripts/resources/scripts/page.lua index 4b315e43f4..b75a78ce96 100644 --- a/app/scripts/resources/scripts/page.lua +++ b/app/scripts/resources/scripts/page.lua @@ -163,39 +163,30 @@ --prevent calling the user that initiated the page if (sip_from_user ~= destination) then - --cmd = "username_exists id "..destination.."@"..domain_name; - --reply = trim(api:executeString(cmd)); - --if (reply == "true") then - destination_status = "show channels like "..destination.."@"; - reply = trim(api:executeString(destination_status)); - if (reply == "0 total.") then - freeswitch.consoleLog("NOTICE", "[page] destination "..destination.." available\n"); - if destination == 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,rtp_secure_media="..rtp_secure_media..",origination_caller_id_name='"..caller_id_name.."',origination_caller_id_number="..caller_id_number.."}user/"..destination.."@"..domain_name.." conference:"..conference_bridge.."+"..flags.." inline"; - api:executeString(cmd_string); - destination_count = destination_count + 1; - end - --freeswitch.consoleLog("NOTICE", "cmd_string "..cmd_string.."\n"); - else - --look inside the reply to check for the correct domain_name - if string.find(reply, domain_name, nil, true) then - --found: user is busy - else - --not found - 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,rtp_secure_media="..rtp_secure_media..",origination_caller_id_name='"..caller_id_name.."',origination_caller_id_number="..caller_id_number.."}user/"..destination.."@"..domain_name.." conference:"..conference_bridge.."+"..flags.." inline"; - api:executeString(cmd_string); - destination_count = destination_count + 1; - end - end + + cmd_string = "show channels"; + channel_result = api:executeString(cmd_string); + + destination_status = 'available'; + channel_array = explode("\n", channel_result); + for index,row in pairs(channel_array) do + if string.find(row, destination..'@'..domain_name, nil, true) then + destination_status = 'busy'; end - --end + end + + if (destination_status == 'available') then + freeswitch.consoleLog("NOTICE", "[page] destination "..destination.." available\n"); + if destination == 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,rtp_secure_media="..rtp_secure_media..",origination_caller_id_name='"..caller_id_name.."',origination_caller_id_number="..caller_id_number.."}user/"..destination.."@"..domain_name.." conference:"..conference_bridge.."+"..flags.." inline"; + api:executeString(cmd_string); + destination_count = destination_count + 1; + end + end + end end end