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 = '';