Merge pull request #1267 from moteus/fax_queue

Add. Send reply message after fax task done.
This commit is contained in:
FusionPBX
2015-11-30 11:05:19 -07:00
7 changed files with 83 additions and 23 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,