--[[ Description: SIP Diversion Header manipulation for Melbourne UCCX callback number handling. Applies to outbound calls processed by agents using callback queueing feature. This examines the directory number (DN) associated with the TO and DIVERSION headers and if they are the same it replaces the DIVERSION header DN with the FROM header DN. This should only ever apply for calls generated by the UCCX callback feature for the Melbourne call center. --]] M = {} function M.outbound_INVITE(msg) -- This script is applicable only for initial INVITE if msg:isReInviteRequest() then return end -- Get DIVERSION header - If there is no DIVERSION header then return local divHeader = msg:getHeader("Diversion") if not divHeader then return end -- Get URI from the DIVERSION header local divString = msg:getUri("Diversion") if divString then -- Parse URI and get DN local divUri = sipUtils.parseUri(divString) if divUri then divDN = divUri:getUser() end end -- Get URI from the TO header local toString = msg:getUri("To") if toString then -- Parse URI and get DN local toUri = sipUtils.parseUri(toString) if toUri then toDN = toUri:getUser() end end -- Get URI from the FROM header local fromString = msg:getUri("From") if fromString then -- Parse URI and get DN local fromUri = sipUtils.parseUri(fromString) if fromUri then fromDN = fromUri:getUser() end end -- Compare the DNs from the DIVERSION and TO headers, if equal then this is an Invite generated -- by the UCCX agent callback queueing script. This should be the only case where these DNs are -- the same. In this case we want to set the DIVERSION header DN to be the same as the FROM header -- DN, as DIVERSION header DN must be the same as the redirecting agent phone DN. if (string.match(divDN, toDN)) then newHeader = string.gsub(divHeader, divDN, fromDN) msg:modifyHeader("Diversion", newHeader) end end return M