Skip to content

Instantly share code, notes, and snippets.

@moteus
Created April 27, 2017 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moteus/015cebda2db90c87564d7c183782afb0 to your computer and use it in GitHub Desktop.
Save moteus/015cebda2db90c87564d7c183782afb0 to your computer and use it in GitHub Desktop.
--! @usage
-- forward incoming message to some extension
-- <action application="lua" data="sms_forward.lua '${from}' '100@my.domain.com'" />
local function escape(s)
s = string.gsub(s, '\\', '\\\\')
s = string.gsub(s, '|', '\\|')
return s
end
local from = assert(argv[1])
local to = assert(argv[2])
local type = message:getHeader('type') or 'text/plain'
local body = message:getBody() or ''
local api = freeswitch.API()
local result = api:execute('chat', table.concat({
'sip', escape(from), escape(to), escape(body), escape(type)
}, '|'))
local msg = string.format('[sms_forward] message(%s) `%s`/`%s` forwarded to `%s`/`%s`: %s\n',
type,
message:getHeader('from') or '----',
message:getHeader('to') or '----',
from, to, result
)
local level = (result == 'Sent') and 'debug' or 'err'
freeswitch.consoleLog(level, msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment