Call Flow add label, tone, and presence for use with blf.

This commit is contained in:
Mark Crane 2012-09-20 07:19:15 +00:00
parent 85df50139c
commit ba7c6a67b9
1 changed files with 32 additions and 20 deletions

View File

@ -67,12 +67,14 @@ if (session:ready()) then
x = 0; x = 0;
dbh:query(sql, function(row) dbh:query(sql, function(row)
--call_flow_name = row.call_flow_name; call_flow_name = row.call_flow_name;
call_flow_extension = row.call_flow_extension; call_flow_extension = row.call_flow_extension;
call_flow_feature_code = row.call_flow_feature_code; call_flow_feature_code = row.call_flow_feature_code;
--call_flow_context = row.call_flow_context; --call_flow_context = row.call_flow_context;
call_flow_status = row.call_flow_status; call_flow_status = row.call_flow_status;
pin_number = row.call_flow_pin_number; pin_number = row.call_flow_pin_number;
call_flow_label = row.call_flow_label;
call_flow_anti_label = row.call_flow_anti_label;
if (string.len(call_flow_status) == 0) then if (string.len(call_flow_status) == 0) then
app = row.call_flow_app; app = row.call_flow_app;
@ -93,6 +95,7 @@ if (session:ready()) then
if (string.len(pin_number) > 0) then if (string.len(pin_number) > 0) then
min_digits = string.len(pin_number); min_digits = string.len(pin_number);
max_digits = string.len(pin_number)+1; max_digits = string.len(pin_number)+1;
session:answer();
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+"); digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
if (digits == pin_number) then if (digits == pin_number) then
--pin is correct --pin is correct
@ -104,7 +107,6 @@ if (session:ready()) then
end end
--feature code - toggle the status --feature code - toggle the status
freeswitch.consoleLog("notice", "Call Flow: toggle\n");
if (string.len(call_flow_status) == 0) then if (string.len(call_flow_status) == 0) then
toggle = "false"; toggle = "false";
else else
@ -115,50 +117,60 @@ if (session:ready()) then
end end
end end
if (toggle == "true") then if (toggle == "true") then
--set the presence to terminated - blf green --set the presence to terminated - turn the lamp off:
event = freeswitch.Event("PRESENCE_IN"); event = freeswitch.Event("PRESENCE_IN");
event:addHeader("proto", "sip"); event:addHeader("proto", "sip");
event:addHeader("event_type", "presence"); event:addHeader("event_type", "presence");
event:addHeader("alt_event_type", "dialog"); event:addHeader("alt_event_type", "dialog");
event:addHeader("Presence-Call-Direction", "outbound"); event:addHeader("Presence-Call-Direction", "outbound");
event:addHeader("state", "Active (1 waiting)"); event:addHeader("state", "Active (1 waiting)");
event:addHeader("from", call_flow_feature_code.."@"..domain_name);
event:addHeader("force-status", "Empty"); event:addHeader("login", call_flow_feature_code.."@"..domain_name);
event:addHeader("rpid", "unknown"); event:addHeader("unique-id", call_flow_uuid);
event:addHeader("channel-state", "CS_HANGUP");
event:addHeader("call-direction", "inbound");
event:addHeader("from", call_flow_extension.."@"..domain_name);
event:addHeader("login", call_flow_extension.."@"..domain_name);
--event:addHeader("unique-id", uuid);
event:addHeader("answer-state", "terminated"); event:addHeader("answer-state", "terminated");
event:fire(); event:fire();
--answer and play a tone
session:answer();
if (string.len(call_flow_label) > 0) then
api = freeswitch.API();
reply = api:executeString("uuid_display "..session:get_uuid().." "..call_flow_label);
end
session:execute("sleep", "2000");
session:execute("playback", "tone_stream://%(200,0,500,600,700)");
--show in the console --show in the console
freeswitch.consoleLog("notice", "Call Flow: "..call_flow_uuid.." On"); freeswitch.consoleLog("notice", "Call Flow: status=true uuid="..call_flow_uuid.."\n");
else else
--set presence in - blf red --set presence in - turn lamp on
event = freeswitch.Event("PRESENCE_IN"); event = freeswitch.Event("PRESENCE_IN");
event:addHeader("proto", "sip"); event:addHeader("proto", "sip");
event:addHeader("login", call_flow_extension.."@"..domain_name); event:addHeader("login", call_flow_feature_code.."@"..domain_name);
event:addHeader("from", call_flow_extension.."@"..domain_name); event:addHeader("from", call_flow_feature_code.."@"..domain_name);
event:addHeader("status", "Active (1 waiting)"); event:addHeader("status", "Active (1 waiting)");
event:addHeader("rpid", "unknown"); event:addHeader("rpid", "unknown");
event:addHeader("event_type", "presence"); event:addHeader("event_type", "presence");
event:addHeader("alt_event_type", "dialog"); event:addHeader("alt_event_type", "dialog");
event:addHeader("event_count", "1"); event:addHeader("event_count", "1");
--event:addHeader("unique-id", uuid); event:addHeader("unique-id", call_flow_uuid);
--event:addHeader("Presence-Call-Direction", "outbound") event:addHeader("Presence-Call-Direction", "outbound")
event:addHeader("answer-state", "confirmed"); event:addHeader("answer-state", "confirmed");
event:fire(); event:fire();
--answer and play a tone
session:answer();
if (string.len(call_flow_anti_label) > 0) then
api = freeswitch.API();
reply = api:executeString("uuid_display "..session:get_uuid().." "..call_flow_anti_label);
end
session:execute("sleep", "2000");
session:execute("playback", "tone_stream://%(500,0,300,200,100,50,25)");
--show in the console --show in the console
freeswitch.consoleLog("notice", "Call Flow: "..call_flow_uuid.." Off"); freeswitch.consoleLog("notice", "Call Flow: status=false uuid="..call_flow_uuid.."\n");
end end
dbh:query("UPDATE v_call_flows SET call_flow_status = '"..toggle.."' WHERE call_flow_uuid = '"..call_flow_uuid.."'"); dbh:query("UPDATE v_call_flows SET call_flow_status = '"..toggle.."' WHERE call_flow_uuid = '"..call_flow_uuid.."'");
else else
--app_data --app_data
freeswitch.consoleLog("notice", "Call Flow: " .. app .. " " .. data .. "\n"); freeswitch.consoleLog("notice", "Call Flow: " .. app .. " " .. data .. "\n");
--exucute the appliation --exucute the application
session:execute(app, data); session:execute(app, data);
--timeout application --timeout application
--if (not session:answered()) then --if (not session:answered()) then