SigMa Scripting examples

Last Updated : Jul 01, 2020 |

The SigMa scripting language is best demonstrated using some examples. This table provides some use cases and how they can be represented in a SigMa script.

Description

Scripting Example

Reverting From and To tags in all responses to REGISTER method.

within session "REGISTER"
{
act on response where %DIRECTION="INBOUND" and %ENTRY_POINT="AFTER_NETWORK"
	{
		%from_tag = %HEADERS["From"][1].PARAMS["Tag"];
		%HEADERS["From"][1].PARAMS["Tag"] = %HEADERS["To"][1].PARAMS["Tag"];
		%HEADERS["To"][1].PARAMS["Tag"] = %from_tag;
	}
}

Updating the p-asserted-identity field with the value of From header if P-Asserted-Identity field value is anonymous

within session "ALL"
{
act on message where %DIRECTION="OUTBOUND" and %ENTRY_POINT="POST_ROUTING"
	{
		if (%HEADERS["P-Asserted-Identity"][1].URI.USER = "anonymous") then
		{
			%aor = %HEADERS["From"][1].URI;
			%HEADERS["P-Asserted-Identity"][1] = %aor;
		}
	}
}

Adding a media attribute in SDP

within session "ALL"
{
	act on message where %DIRECTION="OUTBOUND" and %ENTRY_POINT="POST_ROUTING"
	{
		%SDP[1]["s"]["m"][1].ATTRIBUTES["fmtp"] = "101 0-16";
	}
}

Adding a header

within session "ALL"
{
	act on message where %DIRECTION="OUTBOUND" and %ENTRY_POINT="POST_ROUTING"
	{
		%HEADERS["SLiC-Version"][1] = "3.2.2";
	}
}

Trunking: Removing phone_context param from Request Uri, To and From headers

within session "ALL"
{
act on message where %DIRECTION="OUTBOUND" and %ENTRY_POINT="POST_ROUTING"
	{
		remove(%HEADERS["Request_Line"][1].PARAMS["phone-context"]);
		remove(%HEADERS["From"][1].PARAMS["phone-context"]);
		remove(%HEADERS["To"][1].PARAMS["phone-context"]);
	}
}

Trunking: For all new calls, add diversion header if it does not exist

within session "INVITE"
{
	act on request where %DIRECTION="OUTBOUND" and %ENTRY_POINT="POST_ROUTING"
	{
	if (%INITIAL_REQUEST = "TRUE") then
		{
			%HEADERS["Diversion"][1] = "sip:333444555@";
			append(%HEADERS["Diversion"][1], %REMOTE_IP);
		}
	}
}

Learn P-Asserted-Identity from INVITE and use this value to replace From URI in every Request

within session "INVITE"
{
act on request where %DIRECTION="OUTBOUND" and %ENTRY_POINT="POST_ROUTING"
	{
		If (%INITIAL_REQUEST = "TRUE") then
		{
			%passert_val = %HEADERS["P-Asserted-Identity"][1].URI;
		}
		else
		{
			%HEADERS["From"][1].URI = %passert_val;
		}
	}
}

Changing Max-Forwards from 0 to 45 from carriers

within session "INVITE"
{
act on request where %DIRECTION="OUTBOUND" and %ENTRY_POINT="POST_ROUTING"
	{
		if (exists(%HEADERS["Max-Forwards"][1])) then
		{
		%HEADERS["Max-Forwards"][1] = "45";
		}
	}
}

Changing the CLID to a specific number 3134657809 when a 1800-xxx-xxxx or 1877-xxx-xxxx number is dialed

This script changes the from number without changing the display name.

within session "INVITE"
{
act on request where %DIRECTION="OUTBOUND" and %ENTRY_POINT="POST_ROUTING"
	{
		if (%HEADERS["To"][1].URI.USER.regex_match("1800(.*)")) then
		{
		%HEADERS["From"][1].DISPLAY_NAME = "3134657809";
		}
		if (%HEADERS["To"][1].URI.USER.regex_match("1877(.*)")) then
		{
		%HEADERS["From"][1].DISPLAY_NAME = "3134657809";
		}
	}
}

Removing display name

within session "INVITE"
{
act on request where %DIRECTION="OUTBOUND" and %ENTRY_POINT="POST_ROUTING"
	{
		remove(%HEADERS["From"][1].DISPLAY_NAME);
		remove(%HEADERS["Contact"][1].DISPLAY_NAME);
		remove(%HEADERS["P-Asserted-Identity"][1].DISPLAY_NAME);
	}
}

Changing Inactive to RecvOnly

within session "ALL"
{
act on request where %DIRECTION="OUTBOUND" and %ENTRY_POINT="AFTER_NETWORK"
	{
		/*The "a=" field contains attributes to provide more information on the codecs. Change from inactive to recvonly in all Response Msg*/
		%BODY[1].regex_replace("a=inactive\r\n","a=recvonly\r\n");
		//add(%BODY[1]["a=recvonly\r\n"]);
	}
}

Removing duplicate in ACK

within session "INVITE"
{
/*Look only for ACK messages from SM and  process the message immediately after receiving the message. */
act on request where %DIRECTION="INBOUND" and %ENTRY_POINT="AFTER_NETWORK" and %METHOD="ACK"
	{
		/*If in the request line of ACK, a duplicate of transport=tcp;transport=tcp occurs, remove one of the duplicates. */
		if(%HEADERS["Request_Line"][1].regex_match("transport=tcp;transport=tcp")) then
		{
		%HEADERS["Request_Line"][1].regex_replace("transport=tcp;transport=tcp", "transport=tcp");
		}
	}
}

Checking the user portion of the URI for a specific prefix 50833 and replacing the prefix with an empty string when a match is found

within session "INVITE"
{
/*Look for INVITE messages only.*/
act on request where %DIRECTION="OUTBOUND" and %ENTRY_POINT="POST_ROUTING"
	{
	/* The User portion of the URI in the To header is checked to see if it starts with the prefix 50833.  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["To"][1].URI.USER.regex_replace("^.....","");
		%HEADERS["Request_Line"][1].URI.USER.regex_replace("^.....","");
	}
}