Add multi-lingual support to the missed call emails.

This commit is contained in:
markjcrane
2015-09-15 08:49:37 -06:00
parent 852353605e
commit bd1551a369
5 changed files with 164 additions and 83 deletions
@@ -31,43 +31,69 @@
require "resources.functions.config"; require "resources.functions.config";
require "resources.functions.explode"; require "resources.functions.explode";
require "resources.functions.trim"; require "resources.functions.trim";
require "resources.functions.base64";
--check the missed calls --check the missed calls
function missed() function missed()
if (missed_call_app ~= nil and missed_call_data ~= nil) then if (missed_call_app ~= nil and missed_call_data ~= nil) then
if (missed_call_app == "email") then if (missed_call_app == "email") then
headers = '{"X-FusionPBX-Domain-UUID":"'..domain_uuid..'",'; --set the sounds path for the language, dialect and voice
headers = headers..'"X-FusionPBX-Domain-Name":"'..domain_name..'",'; default_language = session:getVariable("default_language");
headers = headers..'"X-FusionPBX-Call-UUID":"'..uuid..'",'; default_dialect = session:getVariable("default_dialect");
headers = headers..'"X-FusionPBX-Email-Type":"missed"}'; default_voice = session:getVariable("default_voice");
if (not default_language) then default_language = 'en'; end
if (not default_dialect) then default_dialect = 'us'; end
if (not default_voice) then default_voice = 'callie'; end
subject = "Missed Call from ${caller_id_name} <${caller_id_number}>"; --prepare the files
subject = subject:gsub("${caller_id_name}", caller_id_name); file_subject = scripts_dir.."/app/missed_calls/resources/templates/"..default_language.."/"..default_dialect.."/email_subject.tpl";
subject = subject:gsub("${caller_id_number}", caller_id_number); file_body = scripts_dir.."/app/missed_calls/resources/templates/"..default_language.."/"..default_dialect.."/email_body.tpl";
subject = subject:gsub("${sip_to_user}", sip_to_user); if (not file_exists(file_subject)) then
subject = subject:gsub("${dialed_user}", dialed_user); file_subject = scripts_dir.."/app/missed_calls/resources/templates/en/us/email_subject.tpl";
file_body = scripts_dir.."/app/missed_calls/resources/templates/en/us/email_body.tpl";
end
--prepare the headers
headers = '{"X-FusionPBX-Domain-UUID":"'..domain_uuid..'",';
headers = headers..'"X-FusionPBX-Domain-Name":"'..domain_name..'",';
headers = headers..'"X-FusionPBX-Call-UUID":"'..uuid..'",';
headers = headers..'"X-FusionPBX-Email-Type":"missed"}';
body = "Missed Call from ${caller_id_name} <${caller_id_number}> to ${sip_to_user} ext ${dialed_user}"; --prepare the subject
body = body:gsub("${caller_id_name}", caller_id_name); local f = io.open(file_subject, "r");
body = body:gsub("${caller_id_number}", caller_id_number); local subject = f:read("*all");
body = body:gsub("${sip_to_user}", sip_to_user); f:close();
body = body:gsub("${dialed_user}", dialed_user); subject = subject:gsub("${caller_id_name}", caller_id_name);
subject = subject:gsub("${caller_id_number}", caller_id_number);
subject = subject:gsub("${sip_to_user}", sip_to_user);
subject = subject:gsub("${dialed_user}", dialed_user);
subject = trim(subject);
subject = '=?utf-8?B?'..base64.encode(subject)..'?=';
body = body:gsub(" ", "&nbsp;"); --prepare the body
body = body:gsub("%s+", ""); local f = io.open(file_body, "r");
body = body:gsub("&nbsp;", " "); local body = f:read("*all");
body = body:gsub("\n", ""); f:close();
body = body:gsub("\n", ""); body = body:gsub("${caller_id_name}", caller_id_name);
body = body:gsub("'", "&#39;"); body = body:gsub("${caller_id_number}", caller_id_number);
body = body:gsub([["]], "&#34;"); body = body:gsub("${sip_to_user}", sip_to_user);
body = trim(body); body = body:gsub("${dialed_user}", dialed_user);
body = body:gsub(" ", "&nbsp;");
cmd = "luarun email.lua "..missed_call_data.." "..missed_call_data.." "..headers.." '"..subject.."' '"..body.."'"; body = body:gsub("%s+", "");
if (debug["info"]) then body = body:gsub("&nbsp;", " ");
freeswitch.consoleLog("notice", "[missed call] cmd: " .. cmd .. "\n"); body = body:gsub("\n", "");
end body = body:gsub("\n", "");
api = freeswitch.API(); body = body:gsub("'", "&#39;");
result = api:executeString(cmd); body = body:gsub([["]], "&#34;");
body = trim(body);
--send the email
cmd = "luarun email.lua "..missed_call_data.." "..missed_call_data.." "..headers.." '"..subject.."' '"..body.."'";
if (debug["info"]) then
freeswitch.consoleLog("notice", "[missed call] cmd: " .. cmd .. "\n");
end
api = freeswitch.API();
result = api:executeString(cmd);
end end
end end
end end
+54 -28
View File
@@ -28,7 +28,8 @@
require "resources.functions.config"; require "resources.functions.config";
require "resources.functions.explode"; require "resources.functions.explode";
require "resources.functions.trim"; require "resources.functions.trim";
-- require "resources.functions.file_exists"; require "resources.functions.base64";
require "resources.functions.file_exists";
--create the api object --create the api object
api = freeswitch.API(); api = freeswitch.API();
@@ -37,37 +38,62 @@
function missed() function missed()
if (missed_call_app ~= nil and missed_call_data ~= nil) then if (missed_call_app ~= nil and missed_call_data ~= nil) then
if (missed_call_app == "email") then if (missed_call_app == "email") then
headers = '{"X-FusionPBX-Domain-UUID":"'..domain_uuid..'",'; --set the sounds path for the language, dialect and voice
headers = headers..'"X-FusionPBX-Domain-Name":"'..domain_name..'",'; default_language = session:getVariable("default_language");
headers = headers..'"X-FusionPBX-Call-UUID":"'..uuid..'",'; default_dialect = session:getVariable("default_dialect");
headers = headers..'"X-FusionPBX-Email-Type":"missed"}'; default_voice = session:getVariable("default_voice");
if (not default_language) then default_language = 'en'; end
if (not default_dialect) then default_dialect = 'us'; end
if (not default_voice) then default_voice = 'callie'; end
subject = "Missed Call from ${caller_id_name} <${caller_id_number}>"; --prepare the files
subject = subject:gsub("${caller_id_name}", caller_id_name); file_subject = scripts_dir.."/app/missed_calls/resources/templates/"..default_language.."/"..default_dialect.."/email_subject.tpl";
subject = subject:gsub("${caller_id_number}", caller_id_number); file_body = scripts_dir.."/app/missed_calls/resources/templates/"..default_language.."/"..default_dialect.."/email_body.tpl";
subject = subject:gsub("${sip_to_user}", sip_to_user); if (not file_exists(file_subject)) then
subject = subject:gsub("${dialed_user}", dialed_user); file_subject = scripts_dir.."/app/missed_calls/resources/templates/en/us/email_subject.tpl";
file_body = scripts_dir.."/app/missed_calls/resources/templates/en/us/email_body.tpl";
end
body = "Missed Call from ${caller_id_name} <${caller_id_number}> to ${sip_to_user} ext ${dialed_user}"; --prepare the headers
body = body:gsub("${caller_id_name}", caller_id_name); headers = '{"X-FusionPBX-Domain-UUID":"'..domain_uuid..'",';
body = body:gsub("${caller_id_number}", caller_id_number); headers = headers..'"X-FusionPBX-Domain-Name":"'..domain_name..'",';
body = body:gsub("${sip_to_user}", sip_to_user); headers = headers..'"X-FusionPBX-Call-UUID":"'..uuid..'",';
body = body:gsub("${dialed_user}", dialed_user); headers = headers..'"X-FusionPBX-Email-Type":"missed"}';
body = body:gsub(" ", "&nbsp;"); --prepare the subject
body = body:gsub("%s+", ""); local f = io.open(file_subject, "r");
body = body:gsub("&nbsp;", " "); local subject = f:read("*all");
body = body:gsub("\n", ""); f:close();
body = body:gsub("\n", ""); subject = subject:gsub("${caller_id_name}", caller_id_name);
body = body:gsub("'", "&#39;"); subject = subject:gsub("${caller_id_number}", caller_id_number);
body = body:gsub([["]], "&#34;"); subject = subject:gsub("${sip_to_user}", sip_to_user);
body = trim(body); subject = subject:gsub("${dialed_user}", dialed_user);
subject = trim(subject);
subject = '=?utf-8?B?'..base64.encode(subject)..'?=';
cmd = "luarun email.lua "..missed_call_data.." "..missed_call_data.." "..headers.." '"..subject.."' '"..body.."'"; --prepare the body
if (debug["info"]) then local f = io.open(file_body, "r");
freeswitch.consoleLog("notice", "[missed call] cmd: " .. cmd .. "\n"); local body = f:read("*all");
end f:close();
result = api:executeString(cmd); body = body:gsub("${caller_id_name}", caller_id_name);
body = body:gsub("${caller_id_number}", caller_id_number);
body = body:gsub("${sip_to_user}", sip_to_user);
body = body:gsub("${dialed_user}", dialed_user);
body = body:gsub(" ", "&nbsp;");
body = body:gsub("%s+", "");
body = body:gsub("&nbsp;", " ");
body = body:gsub("\n", "");
body = body:gsub("\n", "");
body = body:gsub("'", "&#39;");
body = body:gsub([["]], "&#34;");
body = trim(body);
--send the emails
cmd = "luarun email.lua "..missed_call_data.." "..missed_call_data.." "..headers.." '"..subject.."' '"..body.."'";
if (debug["info"]) then
freeswitch.consoleLog("notice", "[missed call] cmd: " .. cmd .. "\n");
end
result = api:executeString(cmd);
end end
end end
end end
@@ -0,0 +1 @@
Missed Call from ${caller_id_name} &lt;${caller_id_number}&gt; to ${sip_to_user} ext ${dialed_user}
@@ -0,0 +1 @@
Missed Call from ${caller_id_name} <${caller_id_number}>
@@ -34,6 +34,8 @@
--include functions --include functions
require "resources.functions.trim"; require "resources.functions.trim";
require "resources.functions.explode"; require "resources.functions.explode";
require "resources.functions.base64";
require "resources.functions.file_exists";
--get the variables --get the variables
domain_name = session:getVariable("domain_name"); domain_name = session:getVariable("domain_name");
@@ -119,36 +121,61 @@
function missed() function missed()
if (missed_call_app ~= nil and missed_call_data ~= nil) then if (missed_call_app ~= nil and missed_call_data ~= nil) then
if (missed_call_app == "email") then if (missed_call_app == "email") then
headers = '{"X-FusionPBX-Domain-UUID":"'..domain_uuid..'",'; --set the sounds path for the language, dialect and voice
headers = headers..'"X-FusionPBX-Domain-Name":"'..domain_name..'",'; default_language = session:getVariable("default_language");
headers = headers..'"X-FusionPBX-Call-UUID":"'..uuid..'",'; default_dialect = session:getVariable("default_dialect");
headers = headers..'"X-FusionPBX-Email-Type":"missed"}'; default_voice = session:getVariable("default_voice");
if (not default_language) then default_language = 'en'; end
if (not default_dialect) then default_dialect = 'us'; end
if (not default_voice) then default_voice = 'callie'; end
subject = "Missed Call from ${caller_id_name} <${caller_id_number}> ${ring_group_name}"; --prepare the files
subject = subject:gsub("${caller_id_name}", caller_id_name); file_subject = scripts_dir.."/app/missed_calls/resources/templates/"..default_language.."/"..default_dialect.."/email_subject.tpl";
subject = subject:gsub("${caller_id_number}", caller_id_number); file_body = scripts_dir.."/app/missed_calls/resources/templates/"..default_language.."/"..default_dialect.."/email_body.tpl";
subject = subject:gsub("${ring_group_name}", ring_group_name); if (not file_exists(file_subject)) then
file_subject = scripts_dir.."/app/missed_calls/resources/templates/en/us/email_subject.tpl";
file_body = scripts_dir.."/app/missed_calls/resources/templates/en/us/email_body.tpl";
end
body = "Missed Call from ${caller_id_name} <${caller_id_number}> to ${ring_group_name}"; --prepare the headers
body = body:gsub("${caller_id_name}", caller_id_name); headers = '{"X-FusionPBX-Domain-UUID":"'..domain_uuid..'",';
body = body:gsub("${caller_id_number}", caller_id_number); headers = headers..'"X-FusionPBX-Domain-Name":"'..domain_name..'",';
body = body:gsub("${ring_group_name}", ring_group_name); headers = headers..'"X-FusionPBX-Call-UUID":"'..uuid..'",';
headers = headers..'"X-FusionPBX-Email-Type":"missed"}';
body = body:gsub(" ", "&nbsp;"); --prepare the subject
body = body:gsub("%s+", ""); local f = io.open(file_subject, "r");
body = body:gsub("&nbsp;", " "); local subject = f:read("*all");
body = body:gsub("\n", ""); f:close();
body = body:gsub("\n", ""); subject = subject:gsub("${caller_id_name}", caller_id_name);
body = body:gsub("'", "&#39;"); subject = subject:gsub("${caller_id_number}", caller_id_number);
body = body:gsub([["]], "&#34;"); subject = subject:gsub("${ring_group_name}", ring_group_name);
body = trim(body); subject = trim(subject);
subject = '=?utf-8?B?'..base64.encode(subject)..'?=';
cmd = "luarun email.lua "..missed_call_data.." "..missed_call_data.." "..headers.." '"..subject.."' '"..body.."'"; --prepare the body
if (debug["info"]) then local f = io.open(file_body, "r");
freeswitch.consoleLog("notice", "[missed call] cmd: " .. cmd .. "\n"); local body = f:read("*all");
end f:close();
api = freeswitch.API(); body = body:gsub("${caller_id_name}", caller_id_name);
result = api:executeString(cmd); body = body:gsub("${caller_id_number}", caller_id_number);
body = body:gsub("${ring_group_name}", ring_group_name);
body = body:gsub(" ", "&nbsp;");
body = body:gsub("%s+", "");
body = body:gsub("&nbsp;", " ");
body = body:gsub("\n", "");
body = body:gsub("\n", "");
body = body:gsub("'", "&#39;");
body = body:gsub([["]], "&#34;");
body = trim(body);
--send the email
cmd = "luarun email.lua "..missed_call_data.." "..missed_call_data.." "..headers.." '"..subject.."' '"..body.."'";
if (debug["info"]) then
freeswitch.consoleLog("notice", "[missed call] cmd: " .. cmd .. "\n");
end
api = freeswitch.API();
result = api:executeString(cmd);
end end
end end
end end