What questions will you find answers in this article:
- how to send USSD via GSM / 3G / 4G-modem and read responses;
- how to send SMS via Multiphone;
- how to use Yandex SpeechKit in an answering machine on Asterisk.
Which questions you will not find answers:
- Why do you need your own "Who called?".
Everyone understands the service mechanism similar to “Who Called?”: When unavailable, the call goes to a special number, they receive it, inform the caller that the subscriber is unavailable, and send an SMS with information about the call to the subscriber. There are no subtleties in the reception of a call from the Multiphone on Asterisk.
')
In shortCheck in:
register => 79xxxxxxxxx@multifon.ru:<password>:79xxxxxxxxx@sbc.megafon.ru/79xxxxxxxxx
Trunk:
[multifon](!) type=peer insecure=port,invite host=sbc.megafon.ru fromdomain=multifon.ru context=from_multifon dtmfmode=inband [multifon-in](multifon) ; [multifon-out](multifon) defaultuser=79xxxxxxxxx fromuser=79xxxxxxxxx secret=<password>
The first question that arose before me in full growth ...
How to send SMS?
The easiest way, of course, is to buy a human HTTP API from some gate and send it cheaply through it. But first, it is not opposed. And secondly, I have a few hundred SMS on the tariff included in the monthly fee, and I almost never send them from the phone.
Having tried all possible options with the
MessageSend (through both the dialplan, the AMI, and the bald devil), as well as
SipSak , I gave up and tried the
script for Yate .
Oh miracle! SMS via Multiphone sent.
But Yate is a too heavy engine, I thought. Yate has to be a daemon and requires a completely redundant configuration for these tasks, I thought. Therefore, having studied the pearl barley script, I isolated the main one from it and returned to the sipsak. The main thing was a set of non-standard headers (including the mandatory completely specific user agent, yeah):
User-Agent: MCPC-MG-1-0-34-3490/2.0.0.5301 X-Movial-Content: sms/text X-Movial-DeliveryReport: true Content-Type: text/plain; charset=ISO-10646-UCS-2
By the way, the custom user agent, as far as I understand, initially completely excluded the possibility of sending through Asterisk.
At first glance, everything seemed simple. But the messages still did not go away. Turning on the debugging of the sipsack, I realized that this beast has a set of predefined headers that are stupidly duplicated if given on the command line. I had to pick up the file.
Having processed sipsak so that he considers custom headers to be priorities and discard duplicates, I finally achieved the first result. But my joy would be incomplete if the sipsac correctly encoded the transmitted message. I will not write the whole epic of sticking into code built on null-terminated lines, I will immediately present the results of my labors to your court:
https://github.com/wolandtel/sipsak . I wrapped the process of sending SMS in a
convenient script . For the bundle in the latest repository, there is a script settings.sh, which simplifies setting up a password and routing (SIP, GSM + SIP, GSM) on a multi-phone.
Well, here, we can send SMS. Now you can customize yourself ...
Answering machine
AGI will help us here. I will say right away that I didn’t implement the AGI protocol from natural laziness, but only did an emulation in the script that allows you to accomplish the task. Namely, the script must wait for an asterisk response to the STREAM FILE command so that the playback does not end prematurely.
Dialplan ; autoresponder exten => 79xxxxxxxxx,1,NoOp same => n,AGI(notify.agi) same => n,Set(MSG=" . , . ?") same => n,Answer ; Params: speaker, emotion, robot ; speaker: []: zahar, ermil; []: jane, omazh. ; emotion: good, neutral, evil, mixed. ; robot: true, false. same => n,AGI(tts.agi,${MSG},ermil,neutral,true) same => n,Hangup
It was possible, of course, to send SMS from the same script that plays the message, but in terms of the structure of the application, it was logical to separate them.
notify.agi #!/bin/bash while read line; do [ -z "$line" ] && break num=$(echo $line | grep 'agi_callerid: ' | sed 's/agi_callerid: //') [ -n "$num" ] && break done < /dev/stdin [ -z "$num" ] && exit 1 /usr/local/multifon/sms.sh 79xxxxxxxxx " [$(date '+%Y-%m-%d %H:%M:%S')] +$num"
Absolutely no AGI, in fact. Just do what is required and round up.
tts.agi #!/bin/bash text= speaker= emotion= robot= key=<yandex API key> dir=/var/lib/asterisk/tts url=https://tts.voicetech.yandex.net/generate dbg=${0/.agi/.log} fname=$text-$speaker-$emotion-$robot wav= echo -e > while read line; do echo $line >> [ -z ] && break done < /dev/stdin [ -f ] || /usr/bin/curl -s --data-urlencode \ --data-urlencode format=wav \ --data-urlencode lang=ru-RU \ --data-urlencode \ --data-urlencode \ --data-urlencode \ --data-urlencode \ > || exit 1 for f in al ul gsm; do [ -f ] || /usr/bin/sox -r8k || exit 2 done echo -e read line < /dev/stdin echo $line >>
AGI is not here either. We are just waiting for a response from Asterisk with the read command, so as not to close before it plays the message. Please pay attention to the
-r8k option for socks. For some reason, without parameters, it incorrectly raises the output file, and the message is slowed down twice. Details of the Yandex SpeechKit API itself and how to get the key are in the
documentation .
The main part is over. But the article will be incomplete without a description of the nuances.
Sim card preparation
Obviously, for all this to start, you will need a separate number with the Multifunction. Do you buy a sim card and ...? A simple and obvious way is to insert it into the phone, dial the necessary queries and start using. But we are not looking for easy ways. Since ancient times, I have a bundle of 3G modems (the famous E1550 and a little less famous E150), but there is not a single free phone. I don’t like to use my own for such operations: turn it off once again, open it.
So, we will use long-known and well-known
smstools to receive and send SMS. I will not describe the setting, for it is dupe. Only do not include auto-decoding. And then you will be garbage instead of the message body.
So, after acquiring a SIM card, you need to do two things:
- get a password for a personal account (for these baboons killed the Service Guide, and now each number requires its own login);
- to connect the Multiphone (for these baboons broke the web interface , and not to do without USSD).
And if with SMS reception everything is clear, then USSD is not such a transparent thing.
Before continuing, you can familiarize yourself with the
repository of add-ons to smstools, which facilitate the work with SMS and USSD. In the example section of the repository there is a pearl barley tool for working with USSD, which I used to understand the essence of the encoding / decoding of characters in the USSD. Authorship is not specified, and there are no links because I do not remember where I got it. You can use it, but personally I don’t understand perl, and I don’t like technomagic. Therefore, in order to feel the control over the situation, I wrote the utilities encode and decode. As it seems to me, the C code is much easier to understand, so the utilities will be useful to those who want knowledge too.
I suspect that if you set another encoding with the AT + CSCS command, the problem will disappear by itself, but we are not looking for ...
The rest of the work with USSD is simple: the modem registers three ttyUSB devices. We write to the first, we read from the last.
To connect your personal
account, simply send 105:
./ussd.sh '* 105 #' (it is understood that / dev / modem points to the first of the ttyUSB modem). We are waiting for the SMS with the password (it is most convenient to do this with the
ls -lrt / var / spool / incoming command ), and then we watch
./viewsms <path> .
The
multi-phone is connected in two stages: running
cat / dev / ttyUSB2 , send * 137 #. We copy the answer and find out what is written there using
decode . And the menu comes back in response, where you need to select item 1 to connect. We
execute ./ussd 1 and get the SMS password.
This could be the end, but since we are dealing with baboons, it is worth mentioning ...
Organizational issues
- Be sure to specify that a new SIM card is connected to an existing personal account. As far as I understand, disconnection due to inactivity does not work if there is one balance for all numbers. And generally more convenient. When a service guide was alive with the ability to manage all numbers from under one account, this advice was even more relevant.
- In the modern world of business, no one needs to explain that immediately after the purchase of a SIM card, it is necessary to disable all shareware options (including “Who called?”, Yeah). But! Baboons went further and some of the shareware options are not displayed in your account. You can disable them only by calling the contact center. It is advisable to read the fare description in detail to find out what wonderful things you need.
vparil have sold. - As a number to send SMS, I use my main number, because it has a prepaid package. Naturally, for this, the Multiphone on it must also be enabled (but it is not necessary to keep it permanently registered). Additional number is used only for receiving calls.
PS
Unfortunately, the Multiphone does not transmit the number that forwarded the call. Therefore, if you want to connect your bonus “Who called?” To friends / relatives, you will have to buy a separate number for the answering machine for each person. You can also try forwarding with add. set (+ 79XXXXXXXXXXpXX), but I did not check. If check, write.
And now - everything!