FreeSWITCH 分机网关路由

不废话了,直接贴代码:

--[[
	作用:分机网关呼叫

	第一个参数: 分机号码
	第二个参数: 被叫号码
	第三个参数: 主叫号码

	使用例子:
	<extension name="usergw">
		<condition>
			<action application="lua" data="usergw.lua vos 075512345678 137xxxxxxxx"/>
		</condition>
	</extension>
--]]

function bridge_dest(url)
	session:consoleLog("NOTICE", "bridge => " .. url .. "\n")
	session:execute("bridge", url)
	local hcause = session:getVariable("originate_disposition")
	local sip_invite_failure_status = session:getVariable("sip_invite_failure_status") or ""
	return hcause, sip_invite_failure_status
end

local user = argv[1] or "1001"
local called = argv[2] or "8001"
local caller = argv[3] or "2001"

local api = freeswitch.API()
local contact = api:executeString("sofia_contact " .. user)

session:consoleLog("INFO", "sofia_contact = " .. contact .. "\n")

if contact == "error/user_not_registered" then return end

session:execute("set", "transfer_ringback=${cn-ring}")
session:execute("set", "ringback=${cn-ring}")
session:execute("set", "instant_ringback=true")
session:execute("export", "sip_sticky_contact=true")

-- replace callee
new_contact = contact:gsub("^(.+)sip:(.+)@(.+)", "%1sip:" .. called .. "@%3")
session:consoleLog("NOTICE", "new_contact = " .. new_contact .. "\n")

local url = string.format("{origination_caller_id_name=%s,origination_caller_id_number=%s,ignore_early_media=false,absolute_codec_string=pcma\\,pcmu}%s", caller, caller, new_contact)

session:consoleLog("NOTICE", "url " .. url .. "\n")

local hcause, status_code = bridge_dest(url)
session:consoleLog("NOTICE", "hcause =  " .. hcause .. "\n")
session:consoleLog("NOTICE", "status_code =  " .. status_code .. "\n")

分机网关路由应该来自 FusionPBX

可以参考下面这个 api

bgapi expand originate ${regex(${sofia_contact(internal/1013@${domain_name})}|^(.+)sip:(.+)@(.+)|%1sip:018612345678@%3)}
 

上一篇:论文阅读:OpenSTL: A Comprehensive Benchmark of Spatio-Temporal Predictive Learning-正文


下一篇:使用AVX2指令集加速推荐系统MMR层余弦相似度计算