I have a unique issue regarding SIP Diversion headers generated by Call Manager. We have a department using Contact Center Express, and one of the features written into the CCX script for the agents is the ability of the caller to exit the queue and leave a callback number. When an agent gets queued up for one of these callbacks, when the agent initiates the callback it fails. It all worked fine back in the old ISDN PRI days, but since moving to centralized SIP it no longer works.
We have identified the problem. It is with the Diversion header in the initial SIP INVITE not following an expected format. The Diversion header that CUCM generates in this scenario uses the callback number - not the number of the calling agent phone. Since that callback number is not provisioned as a valid number for the customer, the SIP provider rejects the call.
So I have written a LUA script that I hope can deal with this. My logic in the script is to parse the SIP INVITE and compare the number in the "To" and "Diversion" headers, and if equal (which they are in the scenario we are dealing with) replace the number in the "Diversion" header with the number in the "From" header, which we see is the calling agent's phone number.
I have uploaded and enabled the script to the Call Manager SIP trunk, and it does not seem to have broken anything. Outbound calls all work normally, and lines with call forward all set to external PSTN numbers are working too. These forwarded calls use a proper Diversion header with the number of the forwarding phone as expected. I have asked the call center folks to give this a test. In the meantime my LUA script is attached.
Would anyone with LUA fluency kindly review my script and let me know if a got it right or not? This is my first ever attempt at CUCM SIP normalization scripting, and my first attempt with LUA as well. I found the Cisco Developer Guide for SIP Transparency and Normalization which helped out somewhat. Not the best written guide I've ever seen . . .