提交 a5f81bdc authored 作者: Mitch Capper's avatar Mitch Capper
...@@ -37,6 +37,7 @@ function bootstrap(args) ...@@ -37,6 +37,7 @@ function bootstrap(args)
-- Handle some session-based setup if we have a session. -- Handle some session-based setup if we have a session.
if session then if session then
channel.uuid = get_variable("uuid") channel.uuid = get_variable("uuid")
set_storage("channel", "uuid", channel.uuid)
-- Set up the global key handler. -- Set up the global key handler.
_G.key_handler = key_handler _G.key_handler = key_handler
......
...@@ -38,4 +38,8 @@ jester.action_map.load_profile = { ...@@ -38,4 +38,8 @@ jester.action_map.load_profile = {
mod = "core_actions", mod = "core_actions",
func = "load_profile", func = "load_profile",
} }
jester.action_map.api_command = {
mod = "core_actions",
func = "api_command",
}
...@@ -153,3 +153,20 @@ function load_profile(action) ...@@ -153,3 +153,20 @@ function load_profile(action)
end end
end end
--[[
Execute a FreeSWITCH API command.
]]
function api_command(action)
local command = action.command
local key = action.storage_key or "result"
if command then
jester.debug_log("Executing API command: %s", command)
local api = freeswitch.API()
local result = api:executeString(command)
-- Remove final carriage return from result.
result = string.sub(result, 1, -2)
jester.debug_log("Command result: %s", result)
jester.set_storage("api_command", key, result)
end
end
...@@ -83,3 +83,11 @@ jester.help_map.core_actions.actions.load_profile.params = { ...@@ -83,3 +83,11 @@ jester.help_map.core_actions.actions.load_profile.params = {
sequence = [[(Optional) A sequence to execute after loading the profile. If this is provided, any running sequences in the current loop will be discarded, and this sequence will be run from the top of a new sequence stack.]], sequence = [[(Optional) A sequence to execute after loading the profile. If this is provided, any running sequences in the current loop will be discarded, and this sequence will be run from the top of a new sequence stack.]],
} }
jester.help_map.core_actions.actions.api_command = {}
jester.help_map.core_actions.actions.api_command.description_short = [[Execute a FreeSWITCH API command.]]
jester.help_map.core_actions.actions.api_command.description_long = [[This action allows you to execute a FreeSWITCH API command, as if from the console command line. The command result is stored in the specified key.]]
jester.help_map.core_actions.actions.api_command.params = {
command = [[The command to execute.]],
storage_key = [[(Optional) The key to store the command result under in the 'api_command' storage area. Default is 'result'.]],
}
...@@ -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 "#"
...@@ -22,3 +32,14 @@ function get_digits(action) ...@@ -22,3 +32,14 @@ function get_digits(action)
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,8 +8,8 @@ jester.help_map.get_digits.actions.get_digits = {} ...@@ -8,8 +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.]],
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 '#'.]],
......
...@@ -10,7 +10,7 @@ return ...@@ -10,7 +10,7 @@ return
}, },
{ {
action = "call_sequence", action = "call_sequence",
phrase = "exit", sequence = "exit",
}, },
} }
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论