Add Fax Queue TX Email Variables (#6460)

* Add db field to v_fax_queue to link to fax log

* Add fax_duration field to v_fax_logs

Add fax duration to db to allow for logging of this data for fax email templates.

* Add new email variables to fax send

* Fix some logging variables and fax_log_uuid

Added back some missing session variables for the fax log.

Also update the email queue db field with the fax_log_uuid to allow us to add variables to the fax email templates later.

* Update hangup_tx.lua
This commit is contained in:
emak 2022-08-19 20:08:43 -04:00 committed by GitHub
parent f8f09f9a31
commit 26b3e7893b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 92 additions and 10 deletions

View File

@ -764,6 +764,10 @@
$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "fax_duration";
$apps[$x]['db'][$y]['fields'][$z]['type'] = "numeric";
$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = "fax_date";
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "timestamptz";
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "date";

View File

@ -114,6 +114,14 @@
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'fax_log_uuid';
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'foreign';
$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = 'v_fax_logs';
$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'fax_log_uuid';
$z++;
$apps[$x]['db'][$y]['fields'][$z]['name'] = 'fax_date';
$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'timestamptz';
$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'date';

View File

@ -160,6 +160,7 @@
$domain_name = $row['domain_name'];
$fax_uuid = $row['fax_uuid'];
$origination_uuid = $row['origination_uuid'];
$fax_log_uuid = $row['fax_log_uuid'];
$hostname = $row["hostname"];
$fax_date = $row["fax_date"];
$fax_caller_id_name = $row["fax_caller_id_name"];
@ -498,6 +499,33 @@
$fax_file_name = $fax_file_filename . '.' . $fax_file_extension;
}
//get fax log data for email variables
if (isset($fax_email_address) && strlen($fax_email_address) > 0 && isset($fax_log_uuid)) {
$sql = "select * ";
$sql .= "from v_fax_logs ";
$sql .= "where fax_log_uuid = :fax_log_uuid ";
$parameters['fax_log_uuid'] = $fax_log_uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row)) {
$fax_success = $row['fax_success'];
$fax_result_code = $row['fax_result_code'];
$fax_result_text = $row['fax_result_text'];
$fax_ecm_used = $row['fax_ecm_used'];
$fax_local_station_id = $row['fax_local_station_id'];
$fax_document_transferred_pages = $row["fax_document_transferred_pages"];
$fax_document_total_pages = $row["fax_document_total_pages"];
$fax_image_resolution = $row["fax_image_resolution"];
$fax_image_size = $row["fax_image_size"];
$fax_bad_rows = $row["fax_bad_rows"];
$fax_transfer_rate = $row["fax_transfer_rate"];
$fax_epoch = $row["fax_epoch"];
$fax_duration = $row["fax_duration"];
$fax_duration_formatted = sprintf('%02dh %02dm %02ds', ($fax_duration/ 3600),($fax_duration/ 60 % 60), $fax_duration% 60);
}
unset($parameters);
}
//replace variables in email subject
$email_subject = str_replace('${domain_name}', $domain_uuid, $email_subject);
$email_subject = str_replace('${number_dialed}', $fax_number, $email_subject);
@ -507,6 +535,21 @@
$email_subject = str_replace('${fax_file_warning}', $fax_file_warning, $email_subject);
$email_subject = str_replace('${fax_subject_tag}', $fax_email_inbound_subject_tag, $email_subject);
$email_subject = str_replace('${fax_success}', $fax_success, $email_subject);
$email_subject = str_replace('${fax_result_code}', $fax_result_code, $email_subject);
$email_subject = str_replace('${fax_result_text}', $fax_result_text, $email_subject);
$email_subject = str_replace('${fax_ecm_used}', $fax_ecm_used, $email_subject);
$email_subject = str_replace('${fax_local_station_id}', $fax_local_station_id, $email_subject);
$email_subject = str_replace('${fax_document_transferred_pages}', $fax_document_transferred_pages, $email_subject);
$email_subject = str_replace('${fax_document_total_pages}', $fax_document_total_pages, $email_subject);
$email_subject = str_replace('${fax_image_resolution}', $fax_image_resolution, $email_subject);
$email_subject = str_replace('${fax_image_size}', $fax_image_size, $email_subject);
$email_subject = str_replace('${fax_bad_rows}', $fax_bad_rows, $email_subject);
$email_subject = str_replace('${fax_transfer_rate}', $fax_transfer_rate, $email_subject);
$email_subject = str_replace('${fax_date}', date('Y-m-d H:i:s', $fax_epoch), $email_subject);
$email_subject = str_replace('${fax_duration}', $fax_duration, $email_subject);
$email_subject = str_replace('${fax_duration_formatted}', $fax_duration_formatted, $email_subject);
//replace variables in email body
$email_body = str_replace('${domain_name}', $domain_uuid, $email_body);
$email_body = str_replace('${number_dialed}', $fax_number, $email_body);
@ -516,6 +559,21 @@
$email_body = str_replace('${fax_file_warning}', $fax_file_warning, $email_body);
$email_body = str_replace('${fax_subject_tag}', $fax_email_inbound_subject_tag, $email_body);
$email_body = str_replace('${fax_success}', $fax_success, $email_body);
$email_body = str_replace('${fax_result_code}', $fax_result_code, $email_body);
$email_body = str_replace('${fax_result_text}', $fax_result_text, $email_body);
$email_body = str_replace('${fax_ecm_used}', $fax_ecm_used, $email_body);
$email_body = str_replace('${fax_local_station_id}', $fax_local_station_id, $email_body);
$email_body = str_replace('${fax_document_transferred_pages}', $fax_document_transferred_pages, $email_body);
$email_body = str_replace('${fax_document_total_pages}', $fax_document_total_pages, $email_body);
$email_body = str_replace('${fax_image_resolution}', $fax_image_resolution, $email_body);
$email_body = str_replace('${fax_image_size}', $fax_image_size, $email_body);
$email_body = str_replace('${fax_bad_rows}', $fax_bad_rows, $email_body);
$email_body = str_replace('${fax_transfer_rate}', $fax_transfer_rate, $email_body);
$email_body = str_replace('${fax_date}', date('Y-m-d H:i:s', $fax_epoch), $email_body);
$email_body = str_replace('${fax_duration}', $fax_duration, $email_body);
$email_body = str_replace('${fax_duration_formatted}', $fax_duration_formatted, $email_body);
//send the email
if (isset($fax_email_address) && strlen($fax_email_address) > 0) {
//add the attachment

View File

@ -122,6 +122,8 @@
fax_success = env:getHeader("fax_success");
fax_result_text = env:getHeader("fax_result_text");
fax_local_station_id = env:getHeader("fax_local_station_id");
fax_image_resolution = env:getHeader("fax_image_resolution");
fax_image_size = env:getHeader("fax_image_size");
fax_ecm_used = env:getHeader("fax_ecm_used");
fax_uri = env:getHeader("fax_uri");
fax_extension_number = env:getHeader("fax_extension_number");
@ -133,9 +135,11 @@
bridge_hangup_cause = env:getHeader("bridge_hangup_cause");
fax_result_code = env:getHeader("fax_result_code");
fax_remote_station_id = env:getHeader("fax_remote_station_id");
fax_document_transferred_pages = env:getHeader("fax_document_transferred_pages");
fax_document_total_pages = env:getHeader("fax_document_total_pages");
hangup_cause_q850 = tonumber(env:getHeader("hangup_cause_q850"));
fax_file = env:getHeader("fax_file");
fax_duration = env:getHeader("billsec");
--prevent nil errors
if (fax_file == nil) then
@ -223,15 +227,6 @@
fax_file_name = array[count(array)];
end
--update the email queue status
if (fax_success == '1') then
sql = "update v_fax_queue ";
sql = sql .. "set fax_status = :fax_status ";
sql = sql .. "where fax_queue_uuid = :fax_queue_uuid ";
local params = {fax_queue_uuid = fax_queue_uuid, fax_status = fax_status}
dbh:query(sql, params);
end
--add to fax logs
sql = "insert into v_fax_logs ";
sql = sql .. "(";
@ -267,6 +262,9 @@
if (fax_uri ~= nil) then
sql = sql .. "fax_uri, ";
end
if (fax_duration ~= nil) then
sql = sql .. "fax_duration, ";
end
sql = sql .. "fax_date, ";
sql = sql .. "fax_epoch ";
sql = sql .. ") ";
@ -304,6 +302,9 @@
if (fax_uri ~= nil) then
sql = sql .. ":fax_uri, ";
end
if (fax_duration ~= nil) then
sql = sql .. ":fax_duration, ";
end
if (database["type"] == "sqlite") then
sql = sql .. ":fax_date, ";
else
@ -328,14 +329,25 @@
fax_bad_rows = fax_bad_rows;
fax_transfer_rate = fax_transfer_rate;
fax_uri = fax_uri;
fax_duration = fax_duration;
fax_date = os.date("%Y-%m-%d %X");
fax_time = os.time();
};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[fax] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params);
--update the email queue status
if (fax_success == '1') then
sql = "update v_fax_queue ";
sql = sql .. "set fax_status = :fax_status, fax_log_uuid = :fax_log_uuid ";
sql = sql .. "where fax_queue_uuid = :fax_queue_uuid ";
local params = {fax_queue_uuid = fax_queue_uuid, fax_status = fax_status, fax_log_uuid = uuid}
dbh:query(sql, params);
end
--prepare base64
if (storage_type == "base64") then
--include the file io