This project aims at wiring together many pieces of Linux software required to do the following:
Specifically, the setup includes Asterisk server with the GSM-modem dongle and tg2sip bridge and many other components glued together with Shell and Python scripts. The high degree of build automation is achieved thanks to the Nix package manager.
Go and get a GSM modem.
You need to find a
supported GSM modem and plug it into the USB port of your computer. We tested
Huawei-E173
only, but in theory any model supported by
chan_dongle
should work.
./run.sh
will check for the presence of /dev/ttyUSB0
. If
it is not present, the script would attempt to run the usb_modeswitch
procedure.git clone --recursive <this-repo-url> ; cd ...
./secrets.nix
file by copying and editing ./secrets_template.nix
.
api_id
and api_hash
values../run.sh
will print available chat identifiers at
some point during the startup../run.sh
is VERY INSECURE.
It configures Asterisk to use binary codec and then runs it as root../run.sh
.
tg2sip
(TODO: find out how to reuse the first session).
*CLI>
console prompt and be able type commands.run.sh
attempts to run usb_modeswitch procedure automatically for devices
known to author. In case the procedure fails, one could attempt the manual way:
nix-build -A usb_modeswitch
.lsusb
to find out your modem's vendor:product numberssudo ./result/usr/sbin/usb_modeswitch -v <vendor> -p <product> -X
/dec/ttyUSB[01]
devices should appear. You should be able
to minicom -D /dev/ttyUSB0
and type some AT command, say ATI
.run.sh
script by adding new line like below to the
corresponding place
try_to_deal_with "<your_device_id>" "<your_device_vendor>" && wait_for_chardev "/dev/ttyUSB0"
Author uses VIM as the main development IDE. The start procedure is as follows:
$ nix-shell
(nix-shell) $ vim . # Edit sources enjoying code navigaiton
(nix-shell) $ ipython # Testing telethon bot, etc
dongle sms dongle0 89097777777 HiHi
.telegram_master_nicname
Telegram account.
telegram_chat_id
(could be a group) with wav
attachments.secrets.telegram_phone
, then go to the private chat and send a message with
a phone number to call to. Asterisk will initiate an outgoing call
from your Telegram account to the GSM network.<sip:softphone@192.168.1.2:5063>
where
192.168.1.2
should be copied into softphone_bind_ip
address. The 5063
is the SIP port the softphone application should listen to. It is hardcoded
into default.nix
currently.<sip:softphone@192.168.1.1>
where
192.168.1.1
is your asterisk_bind_ip
(could be the same as
softphone_bind_ip
). Set 'softphone' as a password (also hardcoded).sip:1001@192.168.1.1
to talk to Lenny botsip:1000@192.168.1.1
to start the outgoing GSM call.telegram_master_nicname
and send the GSM number to call to (a simple
oneline message). Asterisk will use GSM dongle to call this number.We use the following USB dongle:
*CLI> dongle show devices
ID Group State RSSI Mode Submode Provider Name Model Firmware IMEI IMSI Number
dongle0 0 Free 9 0 0 Beeline E173 11.126.85.00.209 *************** *************** Unknown
See also somewhat outdated list of supported devices
~~tg2sip calls stopped working properly. GSM callers hear themselves but can't hear the telegram side. Softphone calls work fine.~~
tg2sip
crashes on incoming calls :(
https://github.com/Infactum/tg2sip/issues/63
chan_opus.so
is required by tg2sip. Consider replacing it with
https://github.com/traud/asterisk-opuschan_dongle
hardcodings.dongleman_daemon
has to reconnect automatically in case of network failures.
Currently it issues the error ConnectionError: Cannot send requests while disconnected
../3gpp2ulaw.sh
aplay -t raw -f MU_LAW <FILE>
cutlast() {
ffmpeg -i "$2" -ss 0 -to $(echo $(ffprobe -i "$2" -show_entries format=duration -v quiet -of csv="p=0") - "$1" | bc) -c copy "$3"
}
#!/bin/bash -x
cmds()
{
cat <<EOF
dongle cmd dongle0 AT+CPMS=\"SM\",\"SM\",\"SM\"
dongle cmd dongle0 AT+CMGD=1,4
dongle cmd dongle0 AT+CPMS=\"ME\",\"ME\",\"ME\"
dongle cmd dongle0 AT+CMGD=1,4
exit
EOF
}
cmds | asterisk -r
Show channels
core show channels
PJSIP
ARI
ARI (probably the preferred way to interact with Asterisk)
ARI (without Python) https://wiki.asterisk.org/wiki/display/AST/Getting+Started+with+ARI
Local ARI explorer http://ari.asterisk.org/#!/asterisk
About wscat
in NixOS
https://msitko.pl/blog/2020/04/22/isolated-ennvironments-with-nix-shell-and-zsh.html
A sample websocket app in Python https://linuxhint.com/how-to-implement-a-websocket-in-python/
Python Websocket docs https://websockets.readthedocs.io/en/3.0/intro.html
Habr post about ARI https://habr.com/ru/post/308652/
Wiki about making calls via ARI https://wiki.asterisk.org/wiki/display/AST/ARI+and+Bridges%3A+Basic+Mixing+Bridges