summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-03-26 15:52:40 +0100
committerPeter Kozak <spag@golwen.net>2013-03-26 15:52:40 +0100
commitd79da64a619f83e06990c372dd1f2787b3109e7a (patch)
tree45775e9967916a398a4e859d1a20d718f1472be4 /misc/freeswitch/scripts
parent2c1136bd6d3a772f13cf4aacdca0d17baeb79ffe (diff)
ivr methods
Diffstat (limited to 'misc/freeswitch/scripts')
-rw-r--r--misc/freeswitch/scripts/dialplan/ivr.lua67
1 files changed, 56 insertions, 11 deletions
diff --git a/misc/freeswitch/scripts/dialplan/ivr.lua b/misc/freeswitch/scripts/dialplan/ivr.lua
index f8b8a2d..2a16e3b 100644
--- a/misc/freeswitch/scripts/dialplan/ivr.lua
+++ b/misc/freeswitch/scripts/dialplan/ivr.lua
@@ -21,29 +21,51 @@ function Ivr.new(self, arg)
end
-function Ivr.ivr_phrase(self, phrase, keys, timeout, ivr_repeat)
+function Ivr.ivr_break(self)
+ return self.exit or not self.caller:ready();
+end
+
+
+function Ivr.ivr_phrase(self, phrase, keys, timeout, ivr_repeat, phrase_data)
ivr_repeat = ivr_repeat or 3;
timeout = timeout or 30;
self.digit = '';
self.exit = false;
self.break_keys = {};
+ local query_keys = {};
+
for index=1, #keys do
- self.break_keys[keys[index]] = true;
+ if type(keys[index]) == 'table' then
+ if tostring(keys[index].key) ~= '' then
+ table.insert(query_keys, keys[index].key);
+ end
+ self.break_keys[keys[index].key] = keys[index];
+ else
+ if tostring(keys[index]) ~= '' then
+ table.insert(query_keys, keys[index]);
+ end
+ self.break_keys[keys[index]] = true;
+ end
end
global_callback:callback('dtmf', 'ivr_ivr_phrase', self.ivr_phrase_dtmf, self);
-
+ local continue = true;
for index=0, ivr_repeat do
- self.caller.session:sayPhrase(phrase, table.concat(keys, ':'));
- self.caller:sleep(timeout * 1000);
- if self.exit then
+ continue = self:ivr_break() or self.caller.session:sayPhrase(phrase, phrase_data or table.concat(query_keys, ':'));
+ continue = self:ivr_break() or self.caller:sleep(timeout * 1000);
+
+ if self:ivr_break() then
break;
end
end
global_callback:callback_unset('dtmf', 'ivr_ivr_phrase');
+ if type(self.break_keys[self.digit]) == 'table' then
+ return self.digit, self.break_keys[self.digit];
+ end
+
return self.digit;
end
@@ -66,8 +88,8 @@ function Ivr.read_phrase(self, phrase, phrase_data, max_keys, min_keys, timeout,
timeout = timeout or 30;
global_callback:callback('dtmf', 'ivr_read_phrase', self.read_phrase_dtmf, self);
- self.caller.session:sayPhrase(phrase, phrase_data or enter_key or '');
- self.caller:sleep(timeout * 1000);
+ local continue = self:ivr_break() or self.caller.session:sayPhrase(phrase, phrase_data or enter_key or '');
+ continue = self:ivr_break() or self.caller:sleep(timeout * 1000);
global_callback:callback_unset('dtmf', 'ivr_read_phrase');
return self.digits;
@@ -88,7 +110,7 @@ function Ivr.read_phrase_dtmf(self, dtmf)
end
-function Ivr.check_pin(self, phrase, pin, pin_timeout, pin_repeat, key_enter)
+function Ivr.check_pin(self, phrase_enter, phrase_incorrect, pin, pin_timeout, pin_repeat, key_enter)
if not pin then
return nil;
end
@@ -101,19 +123,42 @@ function Ivr.check_pin(self, phrase, pin, pin_timeout, pin_repeat, key_enter)
for i = 1, pin_repeat do
if digits == pin then
self.caller:send_display('PIN: OK');
- break
+ break;
elseif digits ~= "" then
self.caller:send_display('PIN: wrong');
+ self.caller.session:sayPhrase(phrase_incorrect, '');
+ elseif self:ivr_break() then
+ break;
end
self.caller:send_display('Enter PIN');
- digits = ivr:read_phrase(phrase, nil, 0, pin:len() + 1, pin_timeout, key_enter);
+ digits = ivr:read_phrase(phrase_enter, nil, 0, pin:len() + 1, pin_timeout, key_enter);
end
if digits ~= pin then
self.caller:send_display('PIN: wrong');
+ self.caller.session:sayPhrase(phrase_incorrect, '');
return false
end
self.caller:send_display('PIN: OK');
return true;
end
+
+
+function Ivr.record(self, file_name, phrase_record, phrase_too_short, record_length_max, record_length_min, record_repeat, silence_level, silence_lenght_abort)
+ local duration = nil;
+ for index=1, record_repeat do
+ if (duration and duration >= record_length_min) or not self.caller:ready() then
+ break;
+ elseif duration then
+ self.caller:send_display('Recording too short');
+ self.caller.session:sayPhrase(phrase_too_short);
+ end
+ self.caller.session:sayPhrase(phrase_record);
+ self.caller:send_display('Recording...');
+ local result = self.caller.session:recordFile(file_name, record_length_max, silence_level, silence_lenght_abort);
+ duration = self.caller:to_i('record_seconds');
+ end
+
+ return duration or 0;
+end