Setting up number conversion rules

When setting up SIP-accounts from some service providers or registering with PBX, whose settings are not on our list Server templates you may need to manually set up number conversion rules for outgoing calls.

Before sending your phone to a SIP operator, you may need to convert the number to its format. For example, telephone numbers are often written with 8, with brackets and spaces. It is best to convert such numbers to a standard format for compatibility:

8 (926) 123-45-67 → 79261234567

The essence of the number conversion required: remove spaces, brackets and hyphens. The digit 8 at the beginning of the number must be converted into a country code, e.g. for Russia it is 7.

These conversions are done using one or more regular expression rules.

  • There are 2 types of rules: those that contain an = sign (equality) and those that do not
  • All rules apply one at a time
  • We recommend using a ` (single quote) character at the beginning and end of rules to disable possible conversion of part of the rule into smiley faces.

First type of rule (with an equal sign =)

Such rules replace the left of = part with the right part. Both parts of the rule are regular expressions. If the left part of the rule is not found in a phone number, the rule is skipped.
[^+*#\w]= ^8=7
Example 1: The conversion contains 2 rules. The first one removes all characters from the dialed number except numbers, letters and the +, *, # and _ signs. The second rule replaces the first digit 8 in the number with 7.
Example 2: Two equivalent rules, replace the 8 and +7 at the beginning of the phone number with a 7 (the dot at the end of the rule is important).
Example 3: Converts any number to an empty value. This value is, for example, the default for Gateway lines (SIP accounts), so that possible text messages from the default user are not treated as numbers and the line call only goes to the explicitly set number (Number on PBX).

Second type of rule (without the equal sign =)

Such regular expressions set a mask to restrict the use of the operator. If a regular expression does not match a phone number, this operator is excluded and subsequent rules are not considered. If there is a match, the following rule is reviewed.
Example 4: restricts the use of the SIP account to Russian telephone numbers only (beginning with 7 and then 10 digits)
Example 5: Russian mobile numbers
Example 6: three-digit (usually internal) numbers

See also

Payment options for the SIP.TG gateway for transferring calls between Telegram and SIP telephony

Frequent problems and solutions when setting up a gateway for calls between Telegram and SIP telephony

Configuring codecs for SIP accounts when setting up a SIP.TG gateway for Telegram voice calls

Setting up and using the DTMF keypad on Telegram calls

Error codes and their decoding that may occur when setting up a gateway for Telegram calls

How to transfer fare administration to another user, transfer of fare administration, and transfer of ownership of tariff

SIP.TG account management request to help users whose user categories can access the function

IP telephony operators for different geographical areas, vetted by our team

Purpose, benefits, installation and configuration of own Worker servers for SIP.TG

Purpose, benefits, installation and configuration of your own Telegram Session Store for SIP.TG