Hi Habr!
The purpose of this post is to use an example to show how to create custom contexts created by the user in FreePBX using Custom Destination (usually in the /etc/asterisk/extensions_custom.conf file).
')
Often, the standard functions of FreePBX is enough to satisfy the needs of customers. But sometimes there are very specific requests for which you have to write different custom context. And everything seems to be fine, until the problem arises of sending calls to these contexts via the FreePBX admin panel. This is where the Custom Destination feature comes in!
For example:
Given:Suppose our customer has 2 stores in the city. In one of them there is a server with AsteriskNow on board, which handles calls for both stores. The customer bought from sip provider a beautiful number for 8 channels of the form 560560.
In the city of 4 districts:
Plyushkino - phone numbers start at 33
Cheryomushka - phone numbers start at
45Moths - phone numbers start at 77
Beavers - phone numbers start at
31Geographically, they are located as in the figure.

One store is located in the area of
Plyushkino , where the number of the ring-group of sellers will be 600.
Another store in the area
Cheryomushka , where the number of the ring-group of sellers will be 601.
TaskWe need that all incoming calls from potential buyers be processed by the store, which is closer to them geographically. For example, if the call came from the number 312323, it means that the caller is in the
Beavers area, respectively, the nearest store is in the
Cheryomushka area, i.e. The call should be directed to the number of the ring group of sellers 601.
Those. Depending on the first 2 digits of the buyer's Caller-ID, we must direct the call to the ring group we need.
DecisionTo do this, we add to the /etc/asterisk/extensions_custom.conf file a new context with the name check-tel-location-mag, of the following form:
[check-tel-location-mag]
exten => s,1,Set(telnum=${CALLERID(num)})
exten => s,n,GotoIf($[ $["${telnum:0:2}" = "33"] | $["${telnum:0:2}" = "77"] ]?pluwki)
exten => s,n,GotoIf($[ $["${telnum:0:2}" = "31"] | $["${telnum:0:2}" = "45"] ]?ceremuska)
exten => s,n(pluwki),Goto(ext-group,600,1)
exten => s,n(ceremuska),Goto(ext-group,601,1)
Now we can register the context we created in FreePBX.
For this you need:
1. Enter the admin panel FreePBX -> Tools -> Custom Destination
enter the context in the Custom Destination field - check-tel-location-mag, s, 1
fill in the remaining fields as convenient:

2. Click Submit Changes
Now you can create an incoming route to the number 560560, in which you can select the Custom Custom Destination created earlier:

As a result, the customer is satisfied, he received the required functionality, and we learned how to create Custom Destination.
References:
FreePBX Extension Registry HOW-TO