Add. Tasks.send_mail_task function to send task reply.

This commit is contained in:
Alexey Melnichuk
2015-12-01 15:46:52 +03:00
parent e7ee8fb0f8
commit f8c86b42bc
3 changed files with 49 additions and 52 deletions
@@ -4,7 +4,6 @@ require "resources.functions.sleep"
local log = require "resources.functions.log".next_fax_task local log = require "resources.functions.log".next_fax_task
local Tasks = require "app.fax.resources.scripts.queue.tasks" local Tasks = require "app.fax.resources.scripts.queue.tasks"
local Esl = require "resources.functions.esl" local Esl = require "resources.functions.esl"
local send_mail = require "resources.functions.send_mail"
local FAX_OPTIONS = { local FAX_OPTIONS = {
"fax_use_ecm=false,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=default"; "fax_use_ecm=false,fax_enable_t38=true,fax_enable_t38_request=true,fax_disable_v17=default";
@@ -15,22 +14,16 @@ local FAX_OPTIONS = {
} }
local function task_send_mail(task) 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*$") 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, { Tasks.send_mail_task(task, {
"Fax to: " .. number_dialed .. " FAILED", "Fax to: " .. number_dialed .. " FAILED",
table.concat{ table.concat{
"We are sorry the fax failed to go through. ", "We are sorry the fax failed to go through. ",
"It has been attached. Please check the number "..number_dialed..", ", "It has been attached. Please check the number " .. number_dialed .. ", ",
"and if it was correct you might consider emailing it instead.", "and if it was correct you might consider emailing it instead.",
} }}
}) )
end
end end
local function next_task() local function next_task()
@@ -244,14 +244,6 @@
dbh:query(sql); dbh:query(sql);
end 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 -- add the fax files
if fax_success == "1" then if fax_success == "1" then
@@ -331,16 +323,13 @@
end end
Tasks.remove_task(task) Tasks.remove_task(task)
Tasks.send_mail_task(task, {
if task.reply_address and #task.reply_address > 0 then "Fax to: " .. number_dialed .. " SENT",
send_mail(mail_x_headers, task.reply_address, { table.concat{
"Fax to: " .. number_dialed .. " SENT", "We are happy to report the fax was sent successfully.",
table.concat{ "It has been attached for your records.",
"We are happy to report the fax was sent successfully.", }}, uuid
"It has been attached for your records.", )
}
})
end
end end
if fax_success ~= "1" then if fax_success ~= "1" then
@@ -362,16 +351,14 @@
Tasks.wait_task(task, answered, hangup_cause_q850) Tasks.wait_task(task, answered, hangup_cause_q850)
if task.status ~= 0 then if task.status ~= 0 then
Tasks.remove_task(task) Tasks.remove_task(task)
if task.reply_address and #task.reply_address > 0 then Tasks.send_mail_task(task, {
send_mail(mail_x_headers, task.reply_address, { "Fax to: " .. number_dialed .. " FAILED",
"Fax to: " .. number_dialed .. " FAILED", table.concat{
table.concat{ "We are sorry the fax failed to go through. ",
"We are sorry the fax failed to go through. ", "It has been attached. Please check the number "..number_dialed..", ",
"It has been attached. Please check the number "..number_dialed..", ", "and if it was correct you might consider emailing it instead.",
"and if it was correct you might consider emailing it instead.", }}, uuid
} )
})
end
end end
end end
end end
@@ -1,5 +1,6 @@
local Database = require "resources.functions.database" local Database = require "resources.functions.database"
local Settings = require "resources.functions.lazy_settings" local Settings = require "resources.functions.lazy_settings"
local send_mail = require "resources.functions.send_mail"
local db local db
@@ -244,6 +245,21 @@ local function cleanup_tasks()
db:query(remove_finished_tasks_sql) db:query(remove_finished_tasks_sql)
end end
local function send_mail_task(task, message, call_uuid)
if not task.reply_address or #task.reply_address == 0 then
return
end
local mail_x_headers = {
["X-FusionPBX-Domain-UUID"] = task.domain_uuid;
["X-FusionPBX-Domain-Name"] = task.domain_name;
["X-FusionPBX-Call-UUID"] = call_uuid;
["X-FusionPBX-Email-Type"] = 'email2fax';
}
return send_mail(mail_x_headers, task.reply_address, message)
end
return { return {
release_db = function() release_db = function()
if db then if db then
@@ -251,10 +267,11 @@ return {
db = nil db = nil
end end
end; end;
next_task = next_task; next_task = next_task;
wait_task = wait_task; wait_task = wait_task;
select_task = select_task; select_task = select_task;
remove_task = remove_task; remove_task = remove_task;
release_task = release_task; release_task = release_task;
cleanup_tasks = cleanup_tasks; cleanup_tasks = cleanup_tasks;
send_mail_task = send_mail_task;
} }