提交 41ff0963 authored 作者: Chad Phillips's avatar Chad Phillips

refactor custom setting of min/max digit length in get_digits action -- now…

refactor custom setting of min/max digit length in get_digits action -- now either can be set to the length of a string by passing it to the parameter prefixed with a colon.
上级 9cf12686
...@@ -4,8 +4,18 @@ module(..., package.seeall) ...@@ -4,8 +4,18 @@ module(..., package.seeall)
Gets digit input from the user. Gets digit input from the user.
]] ]]
function get_digits(action) function get_digits(action)
local min_digits = action.min_digits or 1 local min_digits = action.min_digits
local max_digits = action.max_digits or 10 local max_digits = action.max_digits
if min_digits then
min_digits = set_digit_length(min_digits)
else
min_digits = 1
end
if max_digits then
max_digits = set_digit_length(max_digits)
else
max_digits = 10
end
local max_tries = action.max_tries or 3 local max_tries = action.max_tries or 3
local timeout = action.timeout and (action.timeout * 1000) or 3000 local timeout = action.timeout and (action.timeout * 1000) or 3000
local terminators = action.terminators or "#" local terminators = action.terminators or "#"
...@@ -16,18 +26,20 @@ function get_digits(action) ...@@ -16,18 +26,20 @@ function get_digits(action)
end end
local bad_input = action.bad_input or "ivr/ivr-that_was_an_invalid_entry.wav" local bad_input = action.bad_input or "ivr/ivr-that_was_an_invalid_entry.wav"
local digits_regex = action.digits_regex or "\\d+" local digits_regex = action.digits_regex or "\\d+"
local exact_match = action.exact_match
local key = action.storage_key or "digits" local key = action.storage_key or "digits"
-- Since exact match was passed, we can use it's length to set min and max
-- digits, and save the user any timeout wait.
if exact_match then
local digit_length = string.len(exact_match)
min_digits = digit_length
max_digits = digit_length
digits_regex = "^" .. exact_match .. "$"
end
local digits = session:playAndGetDigits(min_digits, max_digits, max_tries, timeout, terminators, audio_files, bad_input, digits_regex) local digits = session:playAndGetDigits(min_digits, max_digits, max_tries, timeout, terminators, audio_files, bad_input, digits_regex)
jester.debug_log("Got digits: %s", digits) jester.debug_log("Got digits: %s", digits)
jester.set_storage("get_digits", key, digits) jester.set_storage("get_digits", key, digits)
end end
--[[
Set the digit length to the length of the passed string if prefixed with the
length operator.
]]
function set_digit_length(digit_length)
if type(digit_length) == "string" and string.sub(digit_length, 1, 1) == ":" then
digit_length = string.len(digit_length) - 1
end
return digit_length
end
...@@ -8,9 +8,8 @@ jester.help_map.get_digits.actions.get_digits = {} ...@@ -8,9 +8,8 @@ jester.help_map.get_digits.actions.get_digits = {}
jester.help_map.get_digits.actions.get_digits.description_short = [[Collect user input from the channel.]] jester.help_map.get_digits.actions.get_digits.description_short = [[Collect user input from the channel.]]
jester.help_map.get_digits.actions.get_digits.description_long = [[This action collects user input from a channel, in the form of DTMF key presses, and stores the collected digits in the 'get_digits' storage area. Note that if no user input is collected, or validation fails, an empty string is saved to the storage area instead.]] jester.help_map.get_digits.actions.get_digits.description_long = [[This action collects user input from a channel, in the form of DTMF key presses, and stores the collected digits in the 'get_digits' storage area. Note that if no user input is collected, or validation fails, an empty string is saved to the storage area instead.]]
jester.help_map.get_digits.actions.get_digits.params = { jester.help_map.get_digits.actions.get_digits.params = {
min_digits = [[(Optional) The minimum number of digits to collect. Default is 1.]], min_digits = [[(Optional) The minimum number of digits to collect. Default is 1. Alternatively, a string prefixed with a colon can be passed, and the length of the string will be used to set the value.]],
max_digits = [[(Optional) The maximum number of digits to collect. Default is 10.]], max_digits = [[(Optional) The maximum number of digits to collect. Default is 10. Alternatively, a string prefixed with a colon can be passed, and the length of the string will be used to set the value.]],
exact_match = [[(Optional) If set, the entered digits must be an exact match to the value of this parameter. Setting this overrides the min_digits, max_digits, and digits_regex parameters.]],
max_tries = [[(Optional) The maximum amount of times that validation will fail before giving up. Default is 3.]], max_tries = [[(Optional) The maximum amount of times that validation will fail before giving up. Default is 3.]],
timeout = [[(Optional) Number of seconds to wait for max_digits before trying to validate. Default is 3.]], timeout = [[(Optional) Number of seconds to wait for max_digits before trying to validate. Default is 3.]],
terminators = [[(Optional) A string of keys that the user can use to end the collection before the timeout. Multiple values keys can be used, eg. '*' or '*#'. To accept no terminators, pass an empty string. Default is '#'.]], terminators = [[(Optional) A string of keys that the user can use to end the collection before the timeout. Multiple values keys can be used, eg. '*' or '*#'. To accept no terminators, pass an empty string. Default is '#'.]],
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论