
Despite the fact that a significant portion of people are increasingly using Internet services instead of telephone or fax, the telephone line will be a mandatory element of the office for a long time. Therefore, for any SIP / PBX solution, it is important to know how to connect a PSTN (PSTN) gateway to it.
In this post we will analyze:
- Connecting a local PSTN gateway
- Connecting a SIP provider as a second “gateway” for cheaper international calls
- Routing outgoing calls between gateways
')
PSTN gateways are usually fairly standard SIP devices. But due to the peculiarities of classic telephone networks, users may experience problems when connecting directly to the device:
- The PSNT network uses the E.164 address format (for example +7901234567) and not account @ domain as in SIP
- For outgoing calls, authentication is required in most cases.
- Not all gateways support call forwarding.
- Some PSTN gateways and SIP providers are configured to work with a separate SIP device and require periodic REGISTER requests to redirect incoming calls to it.
To solve these problems, Communigate Pro has two PBX applications designed to send and receive calls from gateways - gatewaycaller and gatewayincomming. In addition, a popular application for receiving calls from PSTN networks is the pbx application, which implements the functions of auto-secretary.
The PBX application on the Communigate Pro server is a program in an interpreted CG / PL language that can act as a B2BUA. Texts of standard programs are open and can be found on the Users-> PBX page:

In this article, a deep understanding of the work of PBX applications is not needed, we will simply use them and only need to be able to run them.
The main way to launch applications is to redirect a signal (for example, SIP INVITE) to an address like “appName # account @ domain” using a rule or in a router.
The basics of the functioning of PBX applications in Communigate Pro can be viewed in a previous post .
Receive calls from PSTN gateway
Most modern gateways can be configured so that incoming calls are sent to a SIP device, in our case CGPro. For routing inside CGPro, we use the
routing table (in the WebAdmin interface Settings-> Router).
Suppose the gateway sends an incoming call with the SIP field To: +74951234567@gateway.company.dom (gateway.company.dom is a dummy domain, used only to route calls from the gateway), then such an entry in the router
<+74951234567@gateway.company.dom> = pbx
Send all calls from the telephone network to the voice menu of the auto-secretary.
Some gateway models have another mode for receiving calls from the PSTN network. When calling from a PSTN to a SIP PBX, a long beep is sent to the caller (as if simply picking up the handset) and he needs to dial the number of a specific user for further connection.
Of course, such functionality is usually needed only in the absence of a full IVR and, in principle, it is better to disable it.
But in this case, you can configure a convenient routing. The To: call field has the format nnn@gateway.company.dom, where "nnn" is the dialed numbers.
; (3 )@gateway.company.dom gatewayincomming, ; <(3d)@gateway.company.dom> = gatewayincomming{*}
Receive calls from a SIP provider
SIP providers and some old \ simple PSTN gateways require SIP registration to send incoming calls to the device. In this case, on the CGPro side, you need to select the user who will receive calls (usually this is a pbx account, since by default all incoming calls of this user will go to the IVR). And set up his RSIP:

RSIP settings are absolutely identical to the settings of a regular SIP client.
Outgoing calls
Routing outgoing calls can be very difficult. For greater clarity, consider a simplified situation:
- If the number starts with 7 and consists of 11 digits, the PSTN gateway is 10.1.1.1
- If the number starts with 1 and consists of 11 digits - the route to the (fictional) SIP provider sipprov.net
- Both services require authentication.
First of all, add authentication settings on both gateways for all accounts on the server:

Since there are several gateways, each setting is recorded in the form of a settings dictionary, where the key is the name of the gateway. "$" in the CallerID field is substituted for the account name.
Records of the router with this problem setting and authentication settings look like this:
Signal:<7(10d)@*>=gatewaycaller{+7*,gwru}
Let us explain the work of these settings on the example of a call to Russia.
Suppose the user dialed the number 7 (123) 456-78-90.
When using a record, the router will allocate the last 10 digits, add +7 as the first characters (phone in E.164 format, understandable to any PSTN network operator) and transmit the resulting number as the first parameter to the gatewaycaller application.
After this, the gatewaycaller looks at the PSTN settings of the calling user and searches there for a group of settings with the key “gwru”, which is transferred to the program by the second parameter.
Writing PSTN settings in the form of account settings allows on the one hand to quickly change settings for most (by default), on the other, allows each user to have their own set of gateways.
Brief summary
Of course, all possible configuration options for PSTN gateways and the corresponding settings of the Communigate Pro server in a short article cannot be considered, but I tried to touch on all the main and standard cases.
Test platform for exploring CommuniGate Pro:
www.bestvoip.ru