Python helper that gammu-smsd runs when a new SMS arrives. It reads the spool file, forwards the text to Telegram, then removes the file only after a successful send.
- Linux with Gammu and
gammu-smsd - Python 3.9+
- A USB modem (or compatible radio) recognized as a serial device (often
/dev/ttyUSB0)
sudo apt install gammu gammu-smsdDiscover the modem serial device:
sudo gammu-detectpython3 -m venv .venv
source .venv/bin/activate
pip install .After pip install ., the entry point sms-telegram-bot runs the same code as python src/sms.py (adjust paths if you run from the repo without installing):
sms-telegram-bot --helpFirst-time setup must be run interactively (terminal) so config.pkl can be created with your Telegram token, chat ID, and Gammu inbox folder:
python src/sms.py
# or: sms-telegram-bot- Copy the template (once): e.g.
cp gammurc.example /etc/gammurc, then edit device, paths, andrunonreceive. - Pass it to
gammu-smsd:-c /etc/gammurc(or your chosen path). - With the provided unit: set
GAMMU_CONFIG_FILE=/etc/gammurcin/etc/sysconfig/gammu-smsd(fromgammu-smsd.sysconfig.example) or in a systemd drop-in (typical on Debian/Ubuntu, where/etc/sysconfigmay not exist). The detailed steps below cover both.
What “automatic” means: one installed config file plus GAMMU_CONFIG_FILE (or -c) always pointing at it—not renaming gammurc.example on the server without copying it to that path.
-
Copy the example and edit every placeholder (device path and all
/path/to/...entries):cp gammurc.example /etc/gammurc sudo chmod 600 /etc/gammurc
-
Gammu does not read
gammurc.exampleby name. It uses the path you pass togammu-smsd -c(or the default/etc/gammurcon many systems). The.examplefile in this repo is only a template. -
Point
runonreceivein that file at your venv Python and this script, withconfig.pklas the first script argument, for example:runonreceive = /home/you/sms-telegram-bot/.venv/bin/python /home/you/sms-telegram-bot/src/sms.py /home/you/sms-telegram-bot/src/config.pklWhen a message arrives, gammu-smsd appends the path of the new SMS file after those arguments. The script uses that path when present; otherwise it scans
inboxpathfor*.txt.
The shipped unit gammu-smsd.service expects environment variables from /etc/sysconfig/gammu-smsd (common on RHEL/Fedora). On Debian/Ubuntu, use a drop-in instead of that path.
-
Copy the variable template and adjust:
sudo cp gammu-smsd.sysconfig.example /etc/sysconfig/gammu-smsd
Set at least
GAMMU_CONFIG_FILE=/etc/gammurc(or wherever you installed the config). This is what makes the daemon use the file you created fromgammurc.example. -
Debian/Ubuntu: create
/etc/systemd/system/gammu-smsd.service.d/override.conf:[Service] Environment=GAMMU_CONFIG_FILE=/etc/gammurc Environment=GAMMU_USER=root Environment=GAMMU_GROUP=root
Adjust user/group to match how you run
gammu-smsd; thensudo systemctl daemon-reload && sudo systemctl restart gammu-smsd. -
Edit
gammu-smsd.serviceif yourgammu-smsdbinary is not at/usr/bin/gammu-smsd(set the correct path inExecStart).
You can use an EUICC SIM (e.g. from AliExpress) and a USB reader (example), then create profiles with MiniLPA so the modem uses your eSIM like a normal SIM.