~singpolyma/cheogram-sip

6284c2bac76a19c455599d3cce4485c380038f65 — Stephen Paul Weber 8 months ago c46ceee
Support inbound SIP MESSAGE
1 files changed, 16 insertions(+), 8 deletions(-)

M extensions.lua
M extensions.lua => extensions.lua +16 -8
@@ 13,6 13,14 @@ function jid_escape(s)
		:gsub("@", "\\40")
end

function make_jid(extension, from_header)
	return (
		jid_escape(extension)
		.. "@sip.cheogram.com/"
		.. jid_escape(from_header:gsub("^[^<]*<sip:", ""):gsub(">.*$", ""))
	):gsub("\\", "\\\\")
end

extensions = {
	public = {
		["_X!"] = function(context, extension)


@@ 29,15 37,15 @@ extensions = {
		end;

		["_."] = function(context, extension)
			local jid = (
				jid_escape(extension)
				.. "@sip.cheogram.com/"
				.. jid_escape(channel.SIP_HEADER("From"):get():gsub("^[^<]*<sip:", ""):gsub(">.*$", ""))
			):gsub("\\", "\\\\")
			if channel.CHANNEL("channeltype"):get() == "Message" then
				local jid = make_jid(extension, channel.MESSAGE("from"):get())

				app.MessageSend("xmpp:" .. jid, "xmpp:asterisk")
			else
				local jid = make_jid(extension, channel.SIP_HEADER("From"):get())

			app.dial(
				"Motif/jingle-endpoint/" .. jid
			)
				app.dial("Motif/jingle-endpoint/" .. jid)
			end
		end;
	};
}