Use the mwi_account under accounts -> extensions to allow sending MWI to multiple extensions.

This commit is contained in:
Mark Crane 2015-06-11 06:30:21 +00:00
parent 5a168e3779
commit f80bc84639
1 changed files with 45 additions and 21 deletions

View File

@ -1,5 +1,5 @@
-- Part of FusionPBX -- Part of FusionPBX
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com> -- Copyright (C) 2013-2015 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved. -- All rights reserved.
-- --
-- Redistribution and use in source and binary forms, with or without -- Redistribution and use in source and binary forms, with or without
@ -25,29 +25,53 @@
--voicemail count if zero new messages set the mwi to no --voicemail count if zero new messages set the mwi to no
function message_waiting(voicemail_id, domain_uuid) function message_waiting(voicemail_id, domain_uuid)
sql = [[SELECT count(*) as message_count FROM v_voicemail_messages as m, v_voicemails as v --initialize the array and add the voicemail_id
WHERE v.domain_uuid = ']] .. domain_uuid ..[[' local accounts = {}
AND v.voicemail_uuid = m.voicemail_uuid table.insert(accounts, voicemail_id);
AND v.voicemail_id = ']] .. voicemail_id ..[[' --get the voicemail id and all related mwi accounts
AND (m.message_status is null or m.message_status = '') ]]; sql = [[SELECT extension, number_alias from v_extensions
if (debug["sql"]) then WHERE domain_uuid = ']] .. domain_uuid ..[['
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n"); AND (mwi_account = ']]..voicemail_id..[[' or mwi_account = ']]..voicemail_id..[[@]]..domain_name..[[')]];
end --if (debug["sql"]) then
status = dbh:query(sql, function(row) freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
--send the message waiting event --end
status = dbh:query(sql, function(row)
if (string.len(row["number_alias"]) > 0) then
table.insert(accounts, row["number_alias"]);
else
table.insert(accounts, row["extension"]);
end
end);
--get the message count
sql = [[SELECT count(*) as message_count FROM v_voicemail_messages as m, v_voicemails as v
WHERE v.domain_uuid = ']] .. domain_uuid ..[['
AND v.voicemail_uuid = m.voicemail_uuid
AND v.voicemail_id = ']] .. voicemail_id ..[['
AND (m.message_status is null or m.message_status = '') ]];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(row)
message_count = row["message_count"];
end);
--send the message waiting event
for key,value in pairs(accounts) do
local event = freeswitch.Event("message_waiting"); local event = freeswitch.Event("message_waiting");
if (row["message_count"] == "0") then if (message_count == "0") then
--freeswitch.consoleLog("notice", "[voicemail] mailbox: "..voicemail_id.."@"..domain_name.." messages: " .. row["message_count"] .. " no messages\n"); if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] mailbox: "..value.."@"..domain_name.." messages: " .. message_count .. " no messages\n");
end
event:addHeader("MWI-Messages-Waiting", "no"); event:addHeader("MWI-Messages-Waiting", "no");
else else
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] mailbox: "..voicemail_id.."@"..domain_name.." messages: " .. message_count .. " \n");
end
event:addHeader("MWI-Messages-Waiting", "yes"); event:addHeader("MWI-Messages-Waiting", "yes");
end end
event:addHeader("MWI-Message-Account", "sip:"..voicemail_id.."@"..domain_name); event:addHeader("MWI-Message-Account", "sip:"..value.."@"..domain_name);
event:addHeader("MWI-Voice-Message", row["message_count"].."/0 ("..row["message_count"].."/0)"); event:addHeader("MWI-Voice-Message", message_count.."/0 ("..message_count.."/0)");
event:fire(); event:fire();
--log to console end
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] mailbox: "..voicemail_id.."@"..domain_name.." messages: " .. row["message_count"] .. " \n");
end
end);
end end