mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-01 01:33:49 +00:00
Add. mail templates for fax server responses.
This commit is contained in:
9
resources/install/scripts/app/fax/app_languages.lua
Normal file
9
resources/install/scripts/app/fax/app_languages.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
text = text or {};
|
||||
|
||||
text['message-send_success'] = {}
|
||||
text['message-send_success']['en-us'] = "We are happy to report the fax was sent successfully. It has been attached for your records."
|
||||
|
||||
text['message-send_fail'] = {}
|
||||
text['message-send_fail']['en-us'] = "We are sorry the fax failed to go through. It has been attached. Please check the number, and if it was correct you might consider emailing it instead."
|
||||
|
||||
return text
|
||||
@@ -1,6 +1,7 @@
|
||||
require "resources.functions.config"
|
||||
|
||||
require "resources.functions.sleep"
|
||||
require "resources.functions.file_exists"
|
||||
local log = require "resources.functions.log".next_fax_task
|
||||
local Tasks = require "app.fax.resources.scripts.queue.tasks"
|
||||
local Esl = require "resources.functions.esl"
|
||||
@@ -13,17 +14,27 @@ 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 function task_send_mail(task, err)
|
||||
local number_dialed = task.uri:match("/([^/]-)%s*$")
|
||||
|
||||
Tasks.send_mail_task(task, {
|
||||
"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.",
|
||||
}}
|
||||
)
|
||||
local Text = require "resources.functions.text"
|
||||
local text = Text.new("app.fax.app_languages")
|
||||
|
||||
local env = {
|
||||
destination_number = number_dialed:match("^([^@]*)");
|
||||
hangup_cause = err;
|
||||
message = text['message-send_fail'];
|
||||
}
|
||||
|
||||
local body = Tasks.build_template(task, 'outbound/fail/body', env)
|
||||
local subject = Tasks.build_template(task, 'outbound/fail/subject', env)
|
||||
|
||||
if not subject then
|
||||
log.warning("Can not find template for email")
|
||||
subject = "Fax to: " .. number_dialed .. " FAILED"
|
||||
end
|
||||
|
||||
Tasks.send_mail_task(task, {subject, body}, nil, file_exists(task.fax_file))
|
||||
end
|
||||
|
||||
local function next_task()
|
||||
@@ -56,7 +67,7 @@ local function next_task()
|
||||
Tasks.wait_task(task, false, info)
|
||||
if task.status ~= 0 then
|
||||
Tasks.remove_task(task)
|
||||
task_send_mail(task)
|
||||
task_send_mail(task, tostring(info))
|
||||
end
|
||||
log.noticef('Can not originate to `%s` cause: %s: %s ', task.uri, tostring(status), tostring(info))
|
||||
else
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
-- include libraries
|
||||
require "resources.functions.config";
|
||||
require "resources.functions.explode";
|
||||
require "resources.functions.split";
|
||||
require "resources.functions.count";
|
||||
require "resources.functions.file_exists";
|
||||
|
||||
local log = require "resources.functions.log".fax_retry
|
||||
local Database = require "resources.functions.database"
|
||||
@@ -28,6 +27,10 @@
|
||||
|
||||
local dbh = Database.new('system')
|
||||
|
||||
-- Global environment
|
||||
default_language = env:getHeader("default_language")
|
||||
default_dialect = env:getHeader("default_dialect")
|
||||
|
||||
-- Channel/FusionPBX variables
|
||||
local uuid = env:getHeader("uuid")
|
||||
local fax_queue_task_session = env:getHeader('fax_queue_task_session')
|
||||
@@ -312,18 +315,32 @@
|
||||
--Success
|
||||
log.infof("RETRY STATS SUCCESS: GATEWAY[%s]", fax_options);
|
||||
|
||||
Tasks.remove_task(task)
|
||||
|
||||
local Text = require "resources.functions.text"
|
||||
local text = Text.new("app.fax.app_languages")
|
||||
|
||||
local env = {
|
||||
fax_options = fax_options;
|
||||
destination_number = number_dialed:match("^([^@]*)");
|
||||
document_transferred_pages = fax_document_transferred_pages;
|
||||
document_total_pages = fax_document_total_pages;
|
||||
message = text['message-send_success'];
|
||||
}
|
||||
|
||||
local body = Tasks.build_template(task, 'outbound/success/body', env)
|
||||
local subject = Tasks.build_template(task, 'outbound/success/subject', env)
|
||||
|
||||
if not subject then
|
||||
log.warning("Can not find template for email")
|
||||
subject = "Fax to: " .. number_dialed .. " SENT"
|
||||
end
|
||||
|
||||
Tasks.send_mail_task(task, {subject, body}, uuid, file_exists(fax_file))
|
||||
|
||||
if keep_local == "false" then
|
||||
os.remove(fax_file);
|
||||
end
|
||||
|
||||
Tasks.remove_task(task)
|
||||
Tasks.send_mail_task(task, {
|
||||
"Fax to: " .. number_dialed .. " SENT",
|
||||
table.concat{
|
||||
"We are happy to report the fax was sent successfully.",
|
||||
"It has been attached for your records.",
|
||||
}}, uuid
|
||||
)
|
||||
end
|
||||
|
||||
if fax_success ~= "1" then
|
||||
@@ -345,14 +362,32 @@
|
||||
Tasks.wait_task(task, answered, hangup_cause_q850)
|
||||
if task.status ~= 0 then
|
||||
Tasks.remove_task(task)
|
||||
Tasks.send_mail_task(task, {
|
||||
"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.",
|
||||
}}, uuid
|
||||
)
|
||||
|
||||
local Text = require "resources.functions.text"
|
||||
local text = Text.new("app.fax.app_languages")
|
||||
|
||||
local env = {
|
||||
fax_options = fax_options;
|
||||
destination_number = number_dialed:match("^([^@]*)");
|
||||
document_transferred_pages = fax_document_transferred_pages;
|
||||
document_total_pages = fax_document_total_pages;
|
||||
hangup_cause = hangup_cause;
|
||||
hangup_cause_q850 = hangup_cause_q850;
|
||||
fax_result_code = fax_result_code;
|
||||
fax_result_text = fax_result_text;
|
||||
message = text['message-send_fail'];
|
||||
}
|
||||
|
||||
local body = Tasks.build_template(task, 'outbound/fail/body', env)
|
||||
local subject = Tasks.build_template(task, 'outbound/fail/subject', env)
|
||||
|
||||
if not subject then
|
||||
log.warning("Can not find template for email")
|
||||
subject = "Fax to: " .. number_dialed .. " FAILED"
|
||||
end
|
||||
|
||||
Tasks.send_mail_task(task, {subject, body}, uuid, file_exists(fax_file))
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -203,8 +203,6 @@ local function wait_task(task, answered, q850)
|
||||
task.uuid
|
||||
)
|
||||
|
||||
print(sql)
|
||||
|
||||
local ok, err = db:query( sql )
|
||||
|
||||
if not ok then return nil, err end
|
||||
@@ -245,7 +243,7 @@ local function cleanup_tasks()
|
||||
db:query(remove_finished_tasks_sql)
|
||||
end
|
||||
|
||||
local function send_mail_task(task, message, call_uuid)
|
||||
local function send_mail_task(task, message, call_uuid, file)
|
||||
if not task.reply_address or #task.reply_address == 0 then
|
||||
return
|
||||
end
|
||||
@@ -257,7 +255,61 @@ local function send_mail_task(task, message, call_uuid)
|
||||
["X-FusionPBX-Email-Type"] = 'email2fax';
|
||||
}
|
||||
|
||||
return send_mail(mail_x_headers, task.reply_address, message)
|
||||
return send_mail(mail_x_headers, task.reply_address, message, file)
|
||||
end
|
||||
|
||||
local function read_file(name, mode)
|
||||
local f, err, code = io.open(name, mode or 'rb')
|
||||
if not f then return nil, err, code end
|
||||
local data = f:read("*all")
|
||||
f:close()
|
||||
return data
|
||||
end
|
||||
|
||||
local function read_template(app, name, lang)
|
||||
local default_language_path = 'en/us'
|
||||
|
||||
local full_path_tpl = scripts_dir .. '/app/' .. app .. '/resources/templates/{lang}/' .. name .. '.tpl'
|
||||
|
||||
local path
|
||||
|
||||
if lang then
|
||||
path = file_exists((full_path_tpl:gsub('{lang}', lang)))
|
||||
end
|
||||
|
||||
if (not path) and (lang ~= default_language_path) then
|
||||
path = file_exists((full_path_tpl:gsub('{lang}', default_language_path)))
|
||||
end
|
||||
|
||||
if path then
|
||||
return read_file(path)
|
||||
end
|
||||
end
|
||||
|
||||
local function build_template(task, templ, env)
|
||||
local lang
|
||||
|
||||
if default_language and default_dialect then
|
||||
lang = (default_language .. '/' .. default_dialect):lower()
|
||||
else
|
||||
local settings = Settings.new(dbh or 'system', task.domain_name, task.domain_uuid)
|
||||
lang = settings:get('domain', 'language', 'code')
|
||||
if lang then lang = lang:gsub('%-', '/'):lower() end
|
||||
end
|
||||
|
||||
local body = read_template('fax', templ, lang)
|
||||
|
||||
body = body:gsub("[^\\](${.-})", function(name)
|
||||
name = name:sub(3, -2)
|
||||
if type(env) == 'table' then
|
||||
return env[name] or ''
|
||||
end
|
||||
if type(env) == 'function' then
|
||||
return env(name) or ''
|
||||
end
|
||||
end)
|
||||
|
||||
return body
|
||||
end
|
||||
|
||||
return {
|
||||
@@ -274,4 +326,5 @@ return {
|
||||
release_task = release_task;
|
||||
cleanup_tasks = cleanup_tasks;
|
||||
send_mail_task = send_mail_task;
|
||||
build_template = build_template;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<html>
|
||||
<table width="400" border="0" cellspacing="0" cellpadding="0" align="center"
|
||||
style="border: 1px solid #cbcfd5;-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px; border-radius: 4px;">
|
||||
<tr>
|
||||
<td valign="middle" align="center" bgcolor="#ff7174" style="background-color: #ff7174;
|
||||
color: #000; font-family: Arial; font-size: 14px; padding: 7px;-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px; border-radius: 4px;">
|
||||
<strong>Send fax fail</strong>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" style="padding: 15px;">
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td style="color: #333; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
<strong>To</strong>
|
||||
</td>
|
||||
<td style="color: #666; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
${destination_number}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="color: #333; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
<strong>Pages</strong>
|
||||
</td>
|
||||
<td style="color: #666; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
${document_transferred_pages}/${document_total_pages}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="color: #333; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
<strong>Message</strong>
|
||||
</td>
|
||||
<td style="color: #666; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
${message}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="color: #333; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
<strong>Error</strong>
|
||||
</td>
|
||||
<td style="color: #666; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
${hangup_cause}/${fax_result_code}/${fax_result_text}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
Fax to: ${destination_number} FAILED
|
||||
@@ -0,0 +1,51 @@
|
||||
<html>
|
||||
<table width="400" border="0" cellspacing="0" cellpadding="0" align="center"
|
||||
style="border: 1px solid #cbcfd5;-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px; border-radius: 4px;">
|
||||
<tr>
|
||||
<td valign="middle" align="center" bgcolor="#e5e9f0" style="background-color: #e5e9f0;
|
||||
color: #000; font-family: Arial; font-size: 14px; padding: 7px;-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px; border-radius: 4px;">
|
||||
<strong>Send fax successfully</strong>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" style="padding: 15px;">
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td style="color: #333; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
<strong>To</strong>
|
||||
</td>
|
||||
<td style="color: #666; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
${destination_number}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="color: #333; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
<strong>Pages</strong>
|
||||
</td>
|
||||
<td style="color: #666; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
${document_transferred_pages}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="color: #333; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
<strong>Message</strong>
|
||||
</td>
|
||||
<td style="color: #666; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
${message}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="color: #333; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
<strong>Options</strong>
|
||||
</td>
|
||||
<td style="color: #666; font-family: Arial; font-size: 12px; padding-bottom: 11px;">
|
||||
${fax_options}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
Fax to: ${destination_number} sent
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
--check if a file exists
|
||||
function file_exists(name)
|
||||
local f=io.open(name,"r")
|
||||
if f~=nil then io.close(f) return true else return false end
|
||||
local f = io.open(name, "r")
|
||||
if not f then return end
|
||||
f:close()
|
||||
return name
|
||||
end
|
||||
Reference in New Issue
Block a user