Update message_waiting.lua

This commit is contained in:
FusionPBX
2016-10-30 12:15:25 -06:00
committed by GitHub
parent abf61c5ea2
commit 75eecb9dd9
@@ -1,5 +1,5 @@
-- Part of FusionPBX -- Part of FusionPBX
-- Copyright (C) 2013-2015 Mark J Crane <markjcrane@fusionpbx.com> -- Copyright (C) 2013-2016 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
@@ -12,7 +12,7 @@
-- notice, this list of conditions and the following disclaimer in the -- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution. -- documentation and/or other materials provided with the distribution.
-- --
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, -- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, -- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
@@ -25,39 +25,44 @@
--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)
--initialize the array and add the voicemail_id --initialize the array and add the voicemail_id
local accounts = {} local accounts = {}
--add the current voicemail id to the accounts array
table.insert(accounts, voicemail_id); table.insert(accounts, voicemail_id);
--get the voicemail id and all related mwi accounts --get the voicemail id and all related mwi accounts
local sql = [[SELECT extension, number_alias from v_extensions local sql = [[SELECT extension, number_alias from v_extensions
WHERE domain_uuid = ']] .. domain_uuid ..[[' WHERE domain_uuid = ']] .. domain_uuid ..[['
AND (mwi_account = ']]..voicemail_id..[[' or mwi_account = ']]..voicemail_id..[[@]]..domain_name..[[')]]; AND (
mwi_account = ']]..voicemail_id..[['
or mwi_account = ']]..voicemail_id..[[@]]..domain_name..[['
or number_alias = ']]..voicemail_id..[['
)]];
if (debug["sql"]) then if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n"); freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end end
dbh:query(sql, function(row) dbh:query(sql, function(row)
if (string.len(row["number_alias"]) > 0) then table.insert(accounts, row["extension"]);
table.insert(accounts, row["number_alias"]);
else
table.insert(accounts, row["extension"]);
end
end); end);
--get new and saved message counts --get new and saved message counts
local new_messages, saved_messages = message_count_by_id( local new_messages, saved_messages = message_count_by_id(voicemail_id, domain_uuid);
voicemail_id, domain_uuid
)
--send the message waiting event --send the message waiting event
for _,value in ipairs(accounts) do for _,value in ipairs(accounts) do
local account = value.."@"..domain_name --add the domain to voicemail id
mwi_notify(account, new_messages, saved_messages) local account = value.."@"..domain_name;
if (debug["info"]) then --send the message waiting notifications
if new_messages == "0" then mwi_notify(account, new_messages, saved_messages);
freeswitch.consoleLog("notice", "[voicemail] mailbox: "..account.." messages: no new messages\n"); --send information to the console
else if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] mailbox: "..account.." messages: " .. new_messages .. " new message(s)\n"); if new_messages == "0" then
freeswitch.consoleLog("notice", "[voicemail] mailbox: "..account.." messages: no new messages\n");
else
freeswitch.consoleLog("notice", "[voicemail] mailbox: "..account.." messages: " .. new_messages .. " new message(s)\n");
end
end end
end
end end
end end