Created
April 27, 2017 11:38
-
-
Save moteus/015cebda2db90c87564d7c183782afb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--! @usage | |
-- forward incoming message to some extension | |
-- <action application="lua" data="sms_forward.lua '${from}' '[email protected]'" /> | |
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