From d72718ea9f86912e4284f05486e2804ce1d2be84 Mon Sep 17 00:00:00 2001 From: Stephen Forster Date: Tue, 1 Oct 2019 02:18:27 +0200 Subject: [PATCH] Fix table name, variables and syntax Follow me Lua (#4609) * Fix table name, variables and syntax Follow me Lua Correct the wrong table name on line 123. Correct the param on line 126 and correct the syntax on line 347. * Update index.lua Missing AND in where clause. * Change order of preference Caller ID Changed order of preference for Caller ID. If user exists should take preference over Follow Me override select caller ID. This is my preference and my opinion only. May not be the desired effect of others. Perhaps a select option to choose a preference like the following options: Set caller ID override all, Local user else Caller ID --- .../install/scripts/app/follow_me/index.lua | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/resources/install/scripts/app/follow_me/index.lua b/resources/install/scripts/app/follow_me/index.lua index ae533d79b4..3ef2697573 100644 --- a/resources/install/scripts/app/follow_me/index.lua +++ b/resources/install/scripts/app/follow_me/index.lua @@ -120,10 +120,10 @@ if (follow_me_uuid ~= nil) then local sql = "select cid_name_prefix, cid_number_prefix, "; sql = sql .. "follow_me_enabled, follow_me_caller_id_uuid, follow_me_ignore_busy "; - sql = sql .. "from v_extensions "; + sql = sql .. "from v_follow_me "; sql = sql .. "where domain_uuid = :domain_uuid "; - sql = sql .. "follow_me_uuid = :follow_me_uuid; "; - local params = {domain_uuid = domain_uuid,destination_number = destination_number}; + sql = sql .. "and follow_me_uuid = :follow_me_uuid; "; + local params = {domain_uuid = domain_uuid,follow_me_uuid = follow_me_uuid}; if (debug["sql"]) then freeswitch.consoleLog("notice", "SQL:" .. sql .. "; params: " .. json.encode(params) .. "\n"); end @@ -323,6 +323,23 @@ toll_allow = ''; end + --get the destination caller id name and number + if (follow_me_caller_id_uuid ~= nil) then + local sql = "select destination_uuid, destination_number, destination_description, destination_caller_id_name, destination_caller_id_number "; + sql = sql .. "from v_destinations "; + sql = sql .. "where domain_uuid = :domain_uuid "; + sql = sql .. "and destination_uuid = :destination_uuid "; + sql = sql .. "order by destination_number asc "; + local params = {domain_uuid = domain_uuid, destination_uuid = follow_me_caller_id_uuid}; + if (debug["sql"]) then + freeswitch.consoleLog("notice", "SQL:" .. sql .. "; params: " .. json.encode(params) .. "\n"); + end + status = dbh:query(sql, params, function(field) + caller_id_name = field["destination_caller_id_name"]; + caller_id_number = field["destination_caller_id_number"]; + end); + end + --check if the user exists if tonumber(caller_id_number) ~= nil then cmd = "user_exists id ".. caller_id_number .." "..domain_name; @@ -339,22 +356,6 @@ end end - --get the destination caller id name and number - if (follow_me_caller_id_uuid ~= nil) then - local sql = "select destination_uuid, destination_number, destination_description, destination_caller_id_name, destination_caller_id_number "; - sql = sql .. "from v_destinations "; - sql = sql .. "where domain_uuid = :domain_uuid "; - sql = sql .. "and destination_uuid = 'destination_uuid' "; - sql = sql .. "order by destination_number asc "; - local params = {domain_uuid = domain_uuid, destination_uuid = follow_me_caller_id_uuid}; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "SQL:" .. sql .. "; params: " .. json.encode(params) .. "\n"); - end - status = dbh:query(sql, params, function(field) - caller_id_name = field["destination_caller_id_name"]; - caller_id_number = field["destination_caller_id_number"]; - end); - end --set the caller id caller_id = '';