This commit is contained in:
markjcrane
2015-11-30 12:33:48 -07:00
13 changed files with 171 additions and 37 deletions

View File

@@ -4,6 +4,7 @@ require "resources.functions.sleep"
local log = require "resources.functions.log".next_fax_task
local Tasks = require "app.fax.resources.scripts.queue.tasks"
local Esl = require "resources.functions.esl"
local send_mail = require "resources.functions.send_mail"
local FAX_OPTIONS = {
"fax_use_ecm=false,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=default";
@@ -13,6 +14,25 @@ local FAX_OPTIONS = {
"fax_use_ecm=false,fax_enable_t38=false,fax_enable_t38_request=false,fax_disable_v17=false";
}
local function task_send_mail(task)
local mail_x_headers = {
["X-FusionPBX-Domain-UUID"] = task.domain_uuid;
["X-FusionPBX-Domain-Name"] = task.domain_name;
["X-FusionPBX-Email-Type"] = 'email2fax';
}
local number_dialed = task.uri:match("/([^/]-)%s*$")
if task.reply_address and #task.reply_address > 0 then
send_mail(mail_x_headers, task.reply_address, {
"Fax to: " .. number_dialed .. " FAILED",
table.concat{
"We are sorry the fax failed to go through. ",
"It has been attached. Please check the number "..number_dialed..", ",
"and if it was correct you might consider emailing it instead.",
}
})
end
end
local function next_task()
local task, err = Tasks.next_task()
@@ -43,6 +63,7 @@ local function next_task()
Tasks.wait_task(task, false, info)
if task.status ~= 0 then
Tasks.remove_task(task)
task_send_mail(task)
end
log.noticef('Can not originate to `%s` cause: %s: %s ', task.uri, tostring(status), tostring(info))
else

View File

@@ -4,10 +4,11 @@
require "resources.functions.split";
require "resources.functions.count";
local log = require "resources.functions.log".fax_retry
local Database = require "resources.functions.database"
local Settings = require "resources.functions.lazy_settings"
local Tasks = require "app.fax.resources.scripts.queue.tasks"
local log = require "resources.functions.log".fax_retry
local Database = require "resources.functions.database"
local Settings = require "resources.functions.lazy_settings"
local Tasks = require "app.fax.resources.scripts.queue.tasks"
local send_mail = require "resources.functions.send_mail"
local fax_task_uuid = env:getHeader('fax_task_uuid')
local task = Tasks.select_task(fax_task_uuid)
@@ -69,11 +70,7 @@
local fax_uuid = task.fax_uuid
-- Email variables
local email_address = env:getHeader("mailto_address")
local from_address = env:getHeader("mailfrom_address") or email_address
local number_dialed = fax_uri:match("/([^/]-)%s*$")
local email_message_fail = "We are sorry the fax failed to go through. It has been attached. Please check the number "..number_dialed..", and if it was correct you might consider emailing it instead."
local email_message_success = "We are happy to report the fax was sent successfully. It has been attached for your records."
log.noticef([[<<< CALL RESULT >>>
uuid: = '%s'
@@ -86,7 +83,6 @@
accountcode: = '%s'
origination_caller_id_name: = '%s'
origination_caller_id_number: = '%s'
mailfrom_address: = '%s'
mailto_address: = '%s'
hangup_cause_q850: = '%s'
fax_options = '%s'
@@ -101,8 +97,7 @@
tostring(accountcode) ,
tostring(origination_caller_id_name) ,
tostring(origination_caller_id_number) ,
tostring(from_address) ,
tostring(email_address) ,
tostring(task.reply_address) ,
tostring(hangup_cause_q850) ,
fax_options
)
@@ -249,6 +244,14 @@
dbh:query(sql);
end
--prepare the headers
local mail_x_headers = {
["X-FusionPBX-Domain-UUID"] = domain_uuid;
["X-FusionPBX-Domain-Name"] = domain_name;
["X-FusionPBX-Call-UUID"] = uuid;
["X-FusionPBX-Email-Type"] = 'email2fax';
}
-- add the fax files
if fax_success == "1" then
@@ -328,6 +331,16 @@
end
Tasks.remove_task(task)
if task.reply_address and #task.reply_address > 0 then
send_mail(mail_x_headers, task.reply_address, {
"Fax to: " .. number_dialed .. " SENT",
table.concat{
"We are happy to report the fax was sent successfully.",
"It has been attached for your records.",
}
})
end
end
if fax_success ~= "1" then
@@ -349,6 +362,16 @@
Tasks.wait_task(task, answered, hangup_cause_q850)
if task.status ~= 0 then
Tasks.remove_task(task)
if task.reply_address and #task.reply_address > 0 then
send_mail(mail_x_headers, task.reply_address, {
"Fax to: " .. number_dialed .. " FAILED",
table.concat{
"We are sorry the fax failed to go through. ",
"It has been attached. Please check the number "..number_dialed..", ",
"and if it was correct you might consider emailing it instead.",
}
})
end
end
end
end

View File

@@ -43,6 +43,7 @@ select
t1.task_dtmf as dtmf,
t1.task_fax_file as fax_file,
t1.task_wav_file as wav_file,
t1.task_reply_address as reply_address,
t1.task_no_answer_counter as no_answer_counter,
t1.task_no_answer_retry_counter as no_answer_retry_counter,
t1.task_retry_counter as retry_counter,

View File

@@ -1,4 +1,4 @@
text = {};
text = text or {};
text['label-download'] = {};
text['label-download']['en-us'] = "Download";
@@ -24,3 +24,4 @@ text['label-attached']['fr-fr'] = "Attaché";
text['label-attached']['de-de'] = "im Anhang";
text['label-attached']['de-at'] = "im Anhang";
return text

View File

@@ -25,10 +25,6 @@
local send_mail = require 'resources.functions.send_mail'
local function T(str)
return text[str][default_language..'-'..default_dialect] or text[str]['en-us']
end
--define a function to send email
function send_email(id, uuid)
--get voicemail message details
@@ -58,7 +54,8 @@
--require the email address to send the email
if (string.len(voicemail_mail_to) > 2) then
--include languages file
require "app.voicemail.app_languages";
local Text = require "resources.functions.text"
local text = Text.new("app.voicemail.app_languages")
--get voicemail message details
sql = [[SELECT * FROM v_voicemail_messages
@@ -142,11 +139,11 @@
body = body:gsub("${sip_to_user}", id);
body = body:gsub("${dialed_user}", id);
if (voicemail_file == "attach") then
body = body:gsub("${message}", T'label-attached');
body = body:gsub("${message}", text['label-attached']);
elseif (voicemail_file == "link") then
body = body:gsub("${message}", "<a href='https://"..domain_name.."/app/voicemails/voicemail_messages.php?action=download&type=vm&t=bin&id="..id.."&voicemail_uuid="..db_voicemail_uuid.."&uuid="..uuid.."&src=email'>"..T'label-download'.."</a>");
body = body:gsub("${message}", "<a href='https://"..domain_name.."/app/voicemails/voicemail_messages.php?action=download&type=vm&t=bin&id="..id.."&voicemail_uuid="..db_voicemail_uuid.."&uuid="..uuid.."&src=email'>"..text['label-download'].."</a>");
else
body = body:gsub("${message}", "<a href='https://"..domain_name.."/app/voicemails/voicemail_messages.php?action=autoplay&id="..db_voicemail_uuid.."&uuid="..uuid.."'>"..T'label-listen'.."</a>");
body = body:gsub("${message}", "<a href='https://"..domain_name.."/app/voicemails/voicemail_messages.php?action=autoplay&id="..db_voicemail_uuid.."&uuid="..uuid.."'>"..text['label-listen'].."</a>");
end
body = body:gsub(" ", "&nbsp;");
body = body:gsub("%s+", "");

View File

@@ -0,0 +1,71 @@
---
-- @tparam table dict Dictionary
-- @tparam[opt='en'] string language default language
-- @tparam[opt='us'] string dialect default language
-- @return[1] nil if key is unknown
-- @return[2] empty string if language/dialect unknown or there no appropriate value for default language/dialect
-- @return[3] translated value accordint dictionary/language/dialect
--
-- @usage
-- local dict = {
-- ['label-text'] = {
-- ['en-us'] = 'text';
-- ['ru-ru'] = 'текст';
-- }
-- }
-- local text = Text.new(dict)
-- -- use global `default_language` and `default_dialect` to resolve language
-- var = text['label-attached']
-- -- use prefix form
-- var = text'label-attached'
-- -- Implicit specify language
-- var = text('label-attached', 'ru', 'ru')
-- -- set global variables(you can set them even after ctor call)
-- default_language, default_dialect = 'ru', 'ru'
-- var = text['label-attached']
local function make_text(dict, language, dialect)
if not (language and dialect) then
language, dialect = 'en', 'us'
end
if type(dict) == 'string' then
dict = require(dict)
end
local default = (language .. '-' .. dialect):lower()
local function index(_, k)
local t = dict[k]
if not t then return end
local lang
if default_language and default_dialect then
lang = (default_language .. '-' .. default_dialect):lower()
end
if not lang then lang = default end
return t[lang] or t[default] or ''
end
local function call(self, k, language, dialect)
if language and dialect then
local t = dict[k]
if not t then return end
local lang = (language .. '-' .. dialect):lower()
local v = t[lang]
if v then return v end
end
return self[k]
end
return setmetatable({},{
__newindex = function()
error('Can not add field to proxy')
end;
__index = index;
__call = call;
})
end
return {
new = make_text;
}