Test Case 6: Prefix Stripping

Last Updated : Apr 24, 2018 |

Use case

Phone numbers might contain a prefix. Sometimes, this prefix needs to be stripped off before the call is routed. This prefix is useful in scenarios where a call transfer is made and the number to which the call must be transferred is entered with a prefix.

Script

within session "INVITE"  
{
/*Look for REFER messages only.  This is specified with the extra condition %METHOD="REFER" in the "where" clause*/
	 		act on request where %DIRECTION="INBOUND" and %ENTRY_POINT="AFTER_NETWORK" and %METHOD="REFER"
			{
		/* The User portion of the URI in the "Refer-To"  header is checked to see if it starts with the prefix 011.  If it does, then it is replaced with an empty string. If URI.USER does not match the regex, then the action is ignored and the message is left intact.*/
					%HEADERS["Refer-To"][1].URI.USER.regex_replace("^011","");
			}
}

Description

Messages that have the Refer-To method are checked for a prefix in the URI. If so, the prefix is stripped before sending the message out.

Limitations

The regular expression in regex_replace can not have the $ symbol.