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

View File

@@ -1,5 +1,5 @@
-- 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.
--
-- 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
-- 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
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- 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
function message_waiting(voicemail_id, domain_uuid)
--initialize the array and add the voicemail_id
local accounts = {}
--add the current voicemail id to the accounts array
table.insert(accounts, voicemail_id);
--get the voicemail id and all related mwi accounts
local sql = [[SELECT extension, number_alias from v_extensions
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
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
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
table.insert(accounts, row["extension"]);
end);
--get new and saved message counts
local new_messages, saved_messages = message_count_by_id(
voicemail_id, domain_uuid
)
local new_messages, saved_messages = message_count_by_id(voicemail_id, domain_uuid);
--send the message waiting event
for _,value in ipairs(accounts) do
local account = value.."@"..domain_name
mwi_notify(account, new_messages, saved_messages)
if (debug["info"]) then
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");
--add the domain to voicemail id
local account = value.."@"..domain_name;
--send the message waiting notifications
mwi_notify(account, new_messages, saved_messages);
--send information to the console
if (debug["info"]) then
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