Test Case 4: Replace From Header For a Set of Users

Last Updated : Apr 24, 2018 |

Use case

In an organization, several phones used by the employees and each of them might have a unique From URI associated with phones. The organization might require that all outgoing calls have the same From URI. For this purpose, the following script can be used.

Script

within session "INVITE"{
/* For users whose Uri begins with the prefix 10, when the message comes towards the SBCE, the Uri is changed to “9000”<sip:9000@domain>. So, when the receiver answers the call, the From is 9000. */
		act on request where %DIRECTION="INBOUND" and %ENTRY_POINT="AFTER_NETWORK"
		{
				/*A Uri can be represented as “<diplay_name>”<scheme>:<user>@<host>:<port>", eg: ”shalini”<sip:shalini@Avaya.com:5060>. "URI.USER" extracts the user portion of the URI.  "regex_match"tries to match the string against the regular expression. It is of the form <string>.regex_match(“<regular expression>”).In this example,it is checked if the "USER" portion in the “From” Header starts with the prefix 10 */

				if(%HEADERS["From"][1].URI.USER.regex_match("^10"))then
				{
				/*The uri and display name of the actual user is stored in temporary variables*/
				%OriginalFromUri = %HEADERS["From"][1].URI.USER;
				%OriginalFromName = %HEADERS["From"][1].DISPLAY_NAME;

				/* The display name and uri is changed to the new values.*/
				%HEADERS["From"][1].DISPLAY_NAME = "9000";
				%HEADERS["From"][1].URI.USER = "9000";
				}
		}

/* When the response comes back, we need to change the URI USER and DISPLAY NAME to the actual user. So,before the message is sent out to the wire from the SBC, it is checked if the URI.USER is 9000.  If yes, then change it back to the original user’s details. */
/* Message should be a response "act on response" and the messages going out from the SBC should be considered (“%DIRECTION="INBOUND"). The actions are invoked before the message goes out (%ENTRY_POINT="BEFORE_NETWORK") */

		act on response where %DIRECTION="OUTBOUND" and %ENTRY_POINT="BEFORE_NETWORK"
		{
				/*Check if the user portion of the From URI is 9000*/
				if(%HEADERS["From"][1].URI.USER = "9000")then
		{
		/*Change the URI.USER and display name to the original user’s details, which are saved in the temporary variables*/
		%HEADERS["From"][1].URI.USER = %OriginalFromUri;
		%HEADERS["From"][1].DISPLAY_NAME = %OriginalFromName;
		}
	}
}

Description

The previous example shows how to modify a message (request) on its way out and also modify a message (response) when it comes in.

Limitations

The example illustrates the use of regex_match. The regular expression provided within the parentheses, that is, regex_match(<regular expression>), can be any valid Perl regular expression. However, the symbol can not be used in the regular expression.