📜 ⬆️ ⬇️

Forwarding to mobile and SMS notification in the absence of a response. One of the possible implementations of the "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.

Described:
- implementation of forwarding to mobile using a two-channel SIP-GSM gateway and multi-channel Multiphone;
- SMS notification to the subscriber via the free email2sms service;
- implementation of a “direct” entry into a common internal numbering plan for a mobile subscriber using software (for Android) and hardware (SIM Dialer for regular cell phones) methods.
')
Details under the cut.

I do not pretend to the ideality of the code presented to the community, I post it "as is". I would be glad if someone will use my work.

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

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


...


To connect “my” IP server with “my” PBX (DX-500), use Quasar-M (PCI bus) for one PRI E1 stream. Internal numbering within the enterprise is predominantly five-digit: 2xxxx - 5xxxx. In my branch (on my DX-500), the numbers 54xxx are allocated and used. The whole 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 DX corresponds to 55705 on Asterisk.

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


Asterisk, receiving from the E1 stream the incoming “virtual” number of the type 55xxx, checks its transfer and, if there is, makes an outgoing call to the appropriate mobile one.

a piece of pri_inc.conf:
...
exten => _5XXXX, 1, Set (Dest4Call = 0) ; Resetting variable
; 0 - direct call, 1 - call forwarding. We use
; the value of this variable in the macro calls to mobile
; for autoddle if the addressee does not answer
exten => _5XXXX, n, Set (MobNumber = $ {DB (transfer / $ {EXTEN})}) ; we take from the base the corresponding mobile if there is
exten => _5XXXX, n, GotoIf ($ [$ {ISNULL ($ {MobNumber})}]? internal: transfer) ; check whether or not and go by tags
; if MobNumber is empty - internal, otherwise - redirect
exten => _5XXXX, n (internal), Dial (SIP / $ {EXTEN}, 60, tm) ; incoming from 1 DX - we call to the SIP-account with the corresponding number
exten => _5XXXX, n, Dial (DAHDI / g0 / $ {EXTEN}, 60, tm) ; incoming from 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) ; lose the "call forwarding"
exten => _5XXXX, n, Set (Dest4Call = $ {CALLERID (number)}) ; Store caller number in variable
exten => _5XXXX, n, Macro (dial-mobile, $ {MobNumber}, $ {Dest4Call}) ; use macro calls to mobile via GSM-gateways and multi-phone
; ARG1 - MobNumber, ARG2 - Dest4Call
...


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

Outgoing go on a free channel. Priorities are given by the conditions in the dialplan 1-> 2-> 3. A separate GSM-Channels database has been created - in it I sometimes turn off any channel as needed.
a 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 SMS
exten => s, n, Set (Dest_number = $ {ARG2}) ; Use the 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 GSM-Channels database
exten => s, n, Dial ($ {GSM-Channel-1} / 00 $ {ARG1}, 30, gmt) ; Call through 1st GSM channel - 0116
exten => s, n, Set (Call_Dial_status = $ {DIALSTATUS}) ; we transfer result of a call for the 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 picked up the call
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "CANCEL"]? sms) ; if not, we continue
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "CONGESTION"]? sms) ; if not, we continue
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "NOANSWER"]? sms) ; if not, we continue
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "ANSWER"]? complete_call) ; if not, we continue

exten => s, n, NoOP ("USLOVIE CHANNEL 2")
exten => s, n (dial_ch2), GotoIf ($ ["$ {DB (GSM-Channels / GSM-Channel-2_status)}" = "off"]? dial_ch3) ; check if the channel is on
; in GSM-Channels database
exten => s, n, Dial ($ {GSM-Channel-2} / 01 $ {ARG1}, 30, gmt) ; Call through the 2nd GSM channel - 0117
exten => s, n, Set (Call_Dial_status = $ {DIALSTATUS}) ; we transfer result of a call for the 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 picked up the call
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "CANCEL"]? sms) ; if not, we continue
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "CONGESTION"]? sms) ; if not, we continue
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "NOANSWER"]? sms) ; if not, we continue
exten => s, n, GotoIf ($ ["$ {Call_Dial_status}" = "ANSWER"]? complete_call) ; if not, we continue
...

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

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

Our Asterisk sends a specially-formed e-mail letter to the mailbox of a 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.

For me personally, it is very expensive to send ordinary SMS messages from a GSM modem, but maybe with the SMS package connected, someone decides to do just that with the goal of isolating Asteriska from “external influences”.

Setting up email2sms service:
The mobile subscriber needs to send a free message to 000908 with the letter C (I suppose that from the English word create-create).


a piece of extensions.conf regarding sending an SMS notification:
; 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 $ Yourself an ARG1 [is@sms.ugsm.ru)
exten => s, n, NoOp ("SMS to $ {ARG1} from number $ {Dest_number} sent now.")
exten => s, n, Background (sms_sended) ; "He sent an SMS with your number."
exten => s, n, hangup ()
...


Go ahead.

In order to completely abandon the deployed solution of Informtekhniki - DECT-tubes (and the base stations placed around the industrial site), something else was done from the atavism that has outlived its usefulness.

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

...


“My” mobile subscribers are divided by equipment into two conditional categories: Android users and users of the usual ancient mobile phones (usually age guides). All of them use the corporate tariff, where all internal corporate calls are free / unlimited.
Multi-account, due to its multi-channel, works great for incoming communication.

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 according to the usual numbers, one rule is enough:

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

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

In the near future I will correct the dialplan regarding DISA to check the CallerID of an incoming call in the transfer database - there’s no need to listen to a voice greeting and a request to dial an extension number to subscribers whose Prefixer is set up - let the number be dialed right away.

The second category of subscribers, for some reason, still uses regular mobile phones. For them, interesting devices were ordered from China - SIM-Dialer. They are a sort of “lining” for the SIM card, they are configured absolutely simply and provide functionality similar to Prefixer. Issue price at the time of order 4.5-5 USD per piece.
Detailed description of the SIM-Dialer:
toster.ru/answer?answer_id=418483 is the topic where the links to the description in PDF are posted.
My current settings (the device replaces the operator's SIM-menu) are as follows:
Password 8888
Set ACC N; setting dialing number = prefix
ACC 1 N: ## 8922xxxXXxx ; Asterisk Multifon Account
Acc delay: 01 ; 3 sec delay, calculated as 01x3
Set Dialplan; rule set
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 is able to make CallBack - see the instructions on the link above.
I have not tested this feature 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 when calling a DISA number (mobile) for “their” to remove voice instructions. In principle, for those who need to weed out incoming calls from "alien" numbers. Details under the spoiler. Welcome!

CallerID filtering of incoming calls:
[Voice_Disa]; Incoming DISA
exten => s, 1, Answer (); Pick up the phone
exten => s, n, Wait (0.2); waiting for a pause

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

exten => s, n, Set (result = $ {SHELL (asterisk -rx "database show transfer" | grep $ {CALLERID (num)} | wc -l)}); check its availability
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); Subject to “non-hair” - short version
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); call log
exten => s, n, Hangup (); hang up

exten => s, n (no_voice), DISA (no-password, from_sip); Sent to main context
exten => s, n, System (echo "$ {DATETIME} - $ {CALLERID} - $ {CHANNEL}" >> / var / log / asterisk / DISA_mobile_calls); call log
exten => s, n, hangup ()


I do not think that there is a tricky or original code, but probably it may be useful to someone ... Especially since this is a logical continuation of the above described functionality.

Source: https://habr.com/ru/post/243139/


All Articles