Call forwarding to mobile and SMS notification in the absence of a response. One of the possible implementations of a “callback”

Good day to all!

In this article I want to describe my version of the implementation of some functionality implemented on my Asterisk server.

It describes:
- an option for implementing call forwarding to mobile using a two-channel SIP-GSM gateway and a multi-channel Multifon;
- SMS-notification of the subscriber through the free email2sms service;
- implementation of a “direct” entry into the general internal numbering plan for a mobile subscriber using software (for Android) and hardware (SIM-Dialer for ordinary mobile phones) methods.

Details under the cut.

I do not pretend to be ideal for the community code, I post it “as is”. I will be glad if my work is useful to anyone.

In our organization, the departmental telephone network is mainly built on Si2000 and only we use the DX-500.

PICTURE on the topic for those who are interested:
All the pictures were taken for the competition of youth projects at our enterprise and for security reasons, they completely lack a junction with the Internet (well, and a multi-phone as a result).


...


To interface “my” IP server with “my” PBX (DX-500), Quasar-M (PCI bus) is used per PRI E1 stream. The internal numbering within the enterprise is predominantly five-digit: 2xxxx - 5xxxx. In "my" branch (on my DX-500) numbers 54xxx are allocated and used. The entire 55xxx segment goes to Asterisk.

PICTURE - Visualization of the route - CAUTION HUMOR - for those who are interested:

...


Forwarding subscribers set and remove themselves -112 55xxx (service code DX-500). The numbering is transparent - the number 54705 on the DX corresponds to 55705 on the Asterisk.

On Asterisk I use AstDB:
xxx * CLI> database show transfer
/ transfer / 55705: 7922xxxXXxx
...


Asterisk, receiving from the E1 stream incoming to a “virtual” number of the form 55xxx, checks its transfer base and, if available, makes an outgoing call to the appropriate mobile.

piece pri_inc.conf:
...
exten => _5XXXX, 1, Set (Dest4Call = 0) ; We reset the value of the variable
; 0 - direct call, 1 - call forwarding. We use
; the value of this variable in the macro calls to mobile
; for auto redial in case of no reply to the address
exten => _5XXXX, n, Set (MobNumber = $ {DB (transfer / $ {EXTEN})}) ; we take the appropriate mobile from the database if there is
exten => _5XXXX, n, GotoIf ($ [$ {ISNULL ($ {MobNumber})}] internal: transfer) ; check whether or not and go through the labels
; if MobNumber is empty - internal, otherwise - redirect
exten => _5XXXX, n (internal), Dial (SIP / $ {EXTEN}, 60, tm) ; incoming with Е1 DX - we call to the SIP account with the corresponding number
exten => _5XXXX, n, Dial (DAHDI / g0 / $ {EXTEN}, 60, tm); incoming with Е1 DX - we call to the SIP account with the corresponding number
exten => _5XXXX, n, Hangup ()
exten => _5XXXX, n (transfer), Background (/ my_sounds / call-forward) ; play “call forwarding”
exten => _5XXXX, n, Set (Dest4Call = $ {CALLERID (number)}) ;
We save the number of the caller in the variable exten => _5XXXX, n, Macro (dial-mobile, $ {MobNumber}, $ {Dest4Call}) ; we use macro calls to mobile via GSM-gateways and a multi-phone
; ARG1 - MobNumber, ARG2 - Dest4Call
...


My system uses an “iron” GSM-gateway - channels 1 and 2, the multi-phone account is bolted to channel number 3.

Outgoing calls go through a free channel. Priorities are given by the conditions in dialplan 1-> 2-> 3. A separate GSM-Channels database has been created - in it I sometimes turn off a channel as needed.
piece of extensions.conf regarding outgoing to GSM:
...
; - [macro-dial-mobile]; Macro for outgoing calls to MEGAFON
; - exten => s, 1, Set (Call_Dial_status = Blank) ;
We save the call status for the subsequent sending of SMS exten => s, n, Set (Dest_number = $ {ARG2}) ; We use a variable for the destination number
exten => s, n, ExecIF ($ ["$ {Dest_number}" == "unknown"]? Set (Dest_number = $ {CALLERID (num)}))
exten => s, n, NoOP ("USLOVIE CHANNEL 1")
exten => s, n (dial_ch1), GotoIf ($ ["$ {DB (GSM-Channels / GSM-Channel-1_status)}" = "off"]? Dial_ch2) ; check if the channel is on
; in the database GSM-Channels
exten => s, n, Dial ($ {GSM-Channel-1} / 00 $ {ARG1}, 30, gmt) ; We call through the 1st GSM channel - 0116
exten => s, n,; pass the result of the call for analysis
exten => s, n, Noop ("Dialstatus is - $ {Call_Dial_status}")
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "BUSY"]? sms) ; if the subscriber is busy or has
answered the call exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "CANCEL"]? sms) ; if not, continue
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "CONGESTION"]? sms) ; if not, continue
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "NOANSWER"]? sms) ; if not, continue
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "ANSWER"]? complete_call) ; if not, continue

exten => s, n, NoOP ("USLOVIE CHANNEL 2")
exten => s, n (dial_ch2), GotoIf ($ ["; check if the channel is on
; in the database GSM-Channels
exten => s, n, Dial ($ {GSM-Channel-2} / 01 $ {ARG1}, 30, gmt) ; We call through the 2nd GSM channel - 0117
extending => s, n, Set (Call_Dial_status = $ {DIALSTATUS}) ; pass the result of the call for analysis
exten => s, n, Noop ("Dialstatus is - $ {Call_Dial_status}")
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "BUSY"]? sms) ; if the subscriber is busy or has
answered the call exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "CANCEL"]? sms) ; if not, continue
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "CONGESTION"]? sms) ; if not, continue
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "NOANSWER"]? sms) ;
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "ANSWER"]? complete_call) ; if not, continue
...

Channel 3 is a “multi-channel” multiphone, limited only by the call-limit option in sip.conf.

Alas, through GSM-gateways and a multi-phone, we can not replace CallerID and the subscriber sees the incoming from the SIM card number installed in the gateway - he does not know who is calling him. If it does not answer (or forcibly rejects an incoming call), an SMS notification with the caller's number (and the time of the call) is sent to the subscriber.

Our Asterisk sends a specially formed e-mail letter to the mailbox of the mobile subscriber. As a result, the mobile subscriber receives the text of the letter in the form of SMS. The implemented function is completely free and works without noticeable delays.

Personally, it’s very expensive for me to send regular SMSs from a GSM modem, but maybe with a connected SMS package someone decides to do just that in order to isolate Asteriska from “external influences”.

Email2sms service setup:
The mobile subscriber needs to send a free message to 000908 with the letter C (I believe that from the English word create-create).


piece extensions.conf regarding sending SMS notifications:
; continued macro [macro-dial-mobile] ...
...
exten => s, n (complete_call), Background (/ my_sounds / goodbue)
exten => s, n, NoOp ("Call to $ {ARG1} from $ {Dest_number} is complete! ”)
exten => s, n, Hangup ()

exten => s, n (sms), Background (busy_now) ; “The subscriber’s device is busy.”
Exten => s, n, System (rm / my_scripts / sms / sendfile_mail $ {ARG1})
exten => s, n, System (touch / my_scripts / sms / sendfile_mail $ {ARG1})
exten = > s, n, System (chmod 777 -R / my_scripts / sms / sendfile_mail $ {ARG1})

exten => s, n, System (echo "Subject: 'HOMEP - $ {ARG2}'" >> / my_scripts / sms / sendfile_mail $ {ARG1})
exten => s, n, System (echo "Mime-Version: 1.0" >> / my_scripts / sms / sendfile_mail $ {ARG1})
exten => s, n, System (echo "Content-Type: text / plain; charset =" UTF-8 "" >> / my_scripts / sms / sendfile_mail $ {ARG1})
exten => s, n, System (echo "Content-Transfer-Encoding: 8bit" >> / my_scripts / sms / sendfile_mail $ {ARG1})
exten => s, n, System (echo "" >> / my_scripts / sms / sendfile_mail $ {ARG1})
exten => s, n, System (echo "$ {STRFTIME ($ {EPOCH} ,,% d.% m .-% H:% M :)}" >> / my_scripts / sms / sendfile_mail $ {ARG1})
exten => s, n, System (echo "" >> / my_scripts / sms / sendfile_mail $ {ARG1})
exten => s, n, System (echo "." >> / my_scripts / sms / sendfile_mail $ {ARG1})
exten = > s, n, System (echo "" >> / my_scripts / sms / sendfile_mail $ {ARG1})
exten => s, n,System (cat / my_scripts / sms / sendfile_mail $ {ARG1} | sendmail -f XXxxXX@mail.ru -t ${ARG1►@sms.ugsm.ru)
exten => s, n, NoOp ("SMS to $ {ARG1} from number $ {Dest_number} sent now.")
exten => s, n, Background (sms_sended)
; “An SMS was sent to him with your number.”
Exten => s, n, Hangup ()
...


Move on.

For the complete rejection of the deployed IT solution - DECT tubes (and base stations located on the industrial site), as from an outdated atavism, something else has been done.

PICTURE - Visualization of the route - CAUTION HUMOR - for those who are interested:

...


“My” mobile subscribers are divided into two conditional categories according to their equipment: Android users and users of ordinary ancient mobile phones (usually an age guide). All of them use the corporate tariff, where all intra-company calls are free / unlimited.
Thanks to its multi-channel nature, a multi-account account works great for incoming calls.

PICTURE on the topic for those who are interested:

...


Android users use the Prefixer application (you will find in the market - not advertising). For outgoing to the internal departmental network at the usual numbers, one rule is enough:

When number matches - [2-5]. * - the rule processes all numbers starting with 2,3,4,5.
Add prefix: 8922xxxXXxx ,,, - Asterisk server multifonovy account, three commas - this is a pause three seconds after the connection (at this time, Asterisk server DISA happily greets the caller).

Thus, when a mobile subscriber dials the number 54705 familiar to him on his mobile phone, the application intercepts the call control, dials the prefix defined in the rule (multi-phone account number), waits a pause of three seconds to skip the voice greeting, and dials the numbers 5 4 7 0 5 into the channel using the DTMF.

In the near future I will correct the DISA dialplan to check the CallerID of an incoming call in the transfer database - why not listen to a voice greeting every time and ask to dial an extension number to subscribers who have Prefixer configured - let the number be dialed right away.

The second category of subscribers, for some reason, still uses ordinary mobile phones. For them, interesting devices were ordered from China - SIM-Dialer. They represent a sort of “lining” for the SIM card, they are configured absolutely simply and provide functionality similar to Prefixer. The issue price at the time of ordering is 4.5-5 USD per unit.
Detailed description of SIM-Dialer:
toster.ru/answer?answer_id=418483 - a topic where links to the description in PDF are laid out.
My current settings (the device replaces the operator’s SIM-menu) are:
Password 8888
Set ACC N; setting dialer number = prefix
ACC 1 N: ## 8922xxxXXxx ; Asterisk
Acc delay server multi-phone account : 01 ; 3 sec delay, calculated as 01x3
Set Dialplan; set rule
catch prx for Acc1: 2 * 3 * 4 * 5 ; filter rules for numbers 2,3,4,5
Other
Ending code: # ; default
Mode: 4 ;
It is worth mentioning that this device can do CallBack - see the instructions at the link above.
I did not test this function as unnecessary.

Thus, my mobile subscribers have convenient (for themselves) and free (for the enterprise budget) calls to the internal corporate network.

Continuation of the article ...
There was a need to remove voice instructions when calling a DISA number (mobile) for "ours". In principle, for those who need to, you can weed out incoming calls from "foreign" numbers. Details under the spoiler. Welcome!

CallerID filtering of incoming calls:
[Voice_Disa]; Incoming DISA
exten => s, 1, Answer (); Take the tube
exten => s, n, Wait (0.2); we wait a pause

exten => s, n, NoOp ("Incomming DISA-Call from number $ {CALLERID (num)}"); show the CALLERID of the incoming call

exten => s, n, Set (result = $ {SHELL (asterisk -rx "database show transfer" | grep $ {CALLERID (num)} | wc -l)}); check its presence
exten => s, n, NoOp ($ {result}); in the tranfer database, save
; and show this variable
exten => s, n, GotoIf ($ [$ {result}> 0]? no_voice); check the value of the variable in the database and route
exten => s, n, Wait (0.2); by the condition of “non-voice” - a short variant
exten => s, n (voice), PlayBack (/ my_sounds / GO / hi); “Hello”
exten => s, n, Wait (0.5)

exten => s, n, PlayBack (/ my_sounds / dial_2_transfer); “Enter the number to transfer the call”
exten => s, n, Wait (0.5)
exten => s, n, DISA (no-password, from_sip); We send to the main context
exten => s, n, System (echo "$ {DATETIME} - $ {CALLERID} - $ {CHANNEL}" >> / var / log / asterisk / DISA_mobile_calls);
keep a log of calls exten => s, n, Hangup (); hang up

exten => s, n (no_voice), DISA (no-password, from_sip); We send to the main context
exten => s, n, System (echo "$ {DATETIME} - $ {CALLERID} - $ {CHANNEL}" >> / var / log / asterisk / DISA_mobile_calls);
keep a log of calls exten => s, n, Hangup ()


I don’t think that this code is tricky or original, but it can probably come in handy for someone ... Moreover, this is a logical continuation of the functionality described above.

Also popular now: