This content originally appeared on DEV Community and was authored by Stephano Kambeta
Sometimes you want to be alerted instantly when something important happens on your Android device. It could be a new SMS from a client, a system warning, or even a security event. By combining Termux-API and Telegram , you can create an automation that sends you real-time notifications wherever you are.
This guide will walk you step-by-step on how to set up this system. You don’t need to be a pro, but you should already have Termux installed and a basic understanding of running commands. If you’ve tried automation projects before, like those from our quick Termux project ideas, this will feel like a fun upgrade.
Why Automate SMS Notifications?
- Stay informed instantly even when your phone is silent or in another room.
- Get alerts in places where SMS is unreliable but internet works fine via Telegram.
- Track potential security threats, like suspicious texts related to phishing scams (see MaxPhisher educational demo).
- Keep a log of all incoming texts for business purposes.
For small business owners, this is a low-cost alerting system that complements a good cybersecurity plan and helps prevent missing urgent updates.
Step 1: Install Termux-API
First, you need the Termux:API app from F-Droid and the Termux-API package inside Termux. This lets scripts access device features like reading SMS or sending them.
pkg update && pkg upgrade -y
pkg install termux-api -y
If you’ve never used Termux for hardware access before, this is similar to how you’d prepare for other integrations like Ngrok tunneling.
Step 2: Enable SMS Permissions
Termux-API needs permission to read incoming SMS. Open your Android settings → Apps → Termux → Permissions → Enable “SMS” and “Phone” access. Without this, your script won’t work.
Step 3: Set Up Telegram Bot
You’ll use Telegram’s Bot API to send alerts.
- Open Telegram and search for @botfather.
- Start a chat and run:
/newbot
. - Follow the prompts to set a name and username.
- Copy the API token BotFather gives you.
- Get your personal chat ID by messaging @userinfobot and noting the number it returns.
Store these details securely — just like you would with sensitive API keys for threat intelligence tools.
Step 4: Write the Automation Script
Create a script that checks for new SMS and sends them to Telegram. Save it as sms_alert.sh
in Termux.
#!/data/data/com.termux/files/usr/bin/bash
# Your Telegram bot details
BOT_TOKEN="YOUR_BOT_TOKEN"
CHAT_ID="YOUR_CHAT_ID"
# Get the latest SMS
SMS=$(termux-sms-list -n 1)
# Send to Telegram
curl -s -X POST https://api.telegram.org/bot$BOT_TOKEN/sendMessage \
-d chat_id=$CHAT_ID \
-d text="New SMS Alert: $SMS"
This works just like setting up remote triggers in other monitoring scripts you might run on Netcat or custom web servers.
Step 5: Automate with Termux:Widget or Cron
You can run this script manually, but the power is in automation.
- Termux:Widget – Place a button on your home screen to run it instantly.
- cron – Install cronie and set the script to check every minute.
pkg install cronie -y
crontab -e
*/1 * * * * bash /data/data/com.termux/files/home/sms_alert.sh
Security Considerations
Automating message forwarding means handling sensitive data. Be careful if messages may contain private information. Store your API token securely and avoid exposing it in shared scripts. For added protection, consider using a VPN from our list of recommended Termux VPNs when sending data online.
Also, if you’re doing this for security monitoring, pair it with other layers such as network security best practices and endpoint protection.
Practical Uses
- Forward OTP codes securely to your own Telegram account when your SIM is in another phone.
- Get immediate alerts for system SMS like balance updates or server downtime notifications.
- Monitor for possible phishing SMS and store them for analysis, similar to what you’d do in an incident response workflow.
Conclusion
With Termux-API and Telegram, you can bridge the gap between mobile events and online messaging in a way that’s fast, private, and cost-effective. This is a great small-scale automation that can be part of a bigger defensive strategy — just like how we connect cybersecurity with business risk in larger setups.
If you’re ready for more hands-on projects, explore our quick Termux projects guide next and keep building your mobile automation skills.
This content originally appeared on DEV Community and was authored by Stephano Kambeta