After a lot of digging I found out where the SMS messages are stored on the Yeastar TG series.
They're in a sqlite database that can be found at /persistent/var/lib/asterisk/db/MyPBX.sqlite
, in the smsrecv
table.
The SMS API is incredibly poorly documented. Even if you can get it working it still doesn't provide a way to get messages that arrived while there was no active TCP connection. Effectively there is no way to just read the inbox.
The system runs BusyBox, so available packages are very limited and are outdated on top of that. After a lot of trial and error and back and forth with ChatGPT, I managed to create a script that will run on the TG device and do the following at your desired interval:
- Get all unread messages from the sqlite db
- Add them in a temporary sqlite db
- gzip and base64 encode that temporary database
- Do an HTTP GET request to whatever URL you want with that base64 string as payload
- If the request was successful, update all records in the main database to "read"
On the other end a webhook can live and then take the payload, decode and unzip the database and just process the records in whatever way is needed. I personally have a n8n flow that does this for example.
The script will always execute the HTTP call, whether there is data or not. It doubles as a sort of heartbeat mechanism to be able to monitor if the script is still running.
Setting up the scripts on the TG device requires the following steps:
- Get the
add.sh
,loop.sh
andprocess_texts.sh
scripts from this gist - Edit
process_texts.sh
to configure your webhook URL - Edit
add.sh
if you want to change the interval at which the script runs (it's set to 10 seconds by default) - Enable FTP in the UI if it isn't yet
- Upload the
loop.sh
andprocess_texts.sh
scripts to the/persistent/script
folder - Upload the
add.sh
script to the/persistent
folder - Reboot the device
You can check if the script is running by:
- Enabling SSH in the UI
- Connecting to the terminal of the device
- Running this command:
ps aux | grep loop.sh
- There should be an entry along the lines of
xxxx root 0:00 /bin/sh /persistent/script/loop.sh /persistent/script/process_texts.sh 10
Disclaimer: this works on my device. The scripts are provided as-is with no guarantees. Use them at your own risk.
what is default password for ftp?