cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
810
Views
5
Helpful
4
Replies

Help with LUA scripting for SIP trunk

mnora
Level 1
Level 1

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 . . .

 

Thank you.

 

4 Replies 4

davidn#
Cisco Employee
Cisco Employee

Hi mnora,

 

The problem is with the logic of your script.  Starting from the getUri if statement, those if statement conditions are independent of one another but at the end, you're assuming that the fromXXX vars are all defined. You need to combine them together with 'and' operand or nest those if statements; otherwise the last if block are not valid. HTH.

 

David

Although I will try modifying it as you suggested and see if anything changes . . .

 

mnora
Level 1
Level 1

David --

Thank you for your response David.  I enabled the script as is on the SIP trunk and asked the users to test it.  They say the callback feature is working now!  So something in that script seems to be correct. I think I'll leave it in place. 

When dealing with SIP profiles on a CUBE router, Cisco has a nifty SIP profile tester that lets you test and validate your profiles before actually enabling them on the router.  I searched for a similar test tool for Call Manager SIP normalization scripts, but alas I could not find one.  What a great tool that would be, Cisco.  Hint.  Hint.

 

davidn#
Cisco Employee
Cisco Employee

The script will work some of the time if all of those conditions are met. However, it will crash if one those fromXXX is undefined in the last if statement so the correct way to do it is to rewrite and combine or nest those if statements or add return statement in the previous ifs.

 

David