Build a Private SMS Telegram Gateway with VPS and SIM Module: Solution for Sending OTP and Alerts to Small Businesses
A detailed guide to building a private SMS Telegram Gateway using VPS and SIM module for sending OTP and alerts to small businesses, ensuring control, security, and automation.
Image credit: Sunriseforever · Pixabay Content License
In the digital age, fast and reliable notifications are crucial for small businesses. With low cost and high flexibility, building a private SMS Telegram Gateway using a VPS and SIM module is an ideal solution for sending OTP (One-Time Password) and alert messages to customers or employees. This guide walks you through deploying this system step by step, ensuring autonomy, security, and scalability.
Introduction to the Private SMS Telegram Gateway
The SMS Telegram Gateway system integrates traditional SMS protocols with direct messaging via Telegram. By connecting a SIM module (such as 4G/3G SIM USB, SIM modem, or Raspberry Pi SIM module) to a VPS, you can send and receive SMS messages from any device without relying on third-party SMS gateway services. This gives small businesses full control over their data, reduces costs, and increases reliability.
Telegram, with its open API and strong integration capabilities, allows you to send notifications directly to groups or specific users. When combined with a VPS that has sufficient RAM and stable internet connectivity, the system can handle hundreds of messages per minute, making it suitable for small and medium-sized enterprises.
Requirements and Necessary Equipment
To build this system, you will need:
- VPS (Cloud VPS) with ≥4GB RAM and stable internet connection. Refer to High-RAM Cloud VPS for Self-Hosted LLMs & API Gateways.
- SIM module supporting 4G/3G (e.g., SIM USB, SIM modem, or SIM module for Raspberry Pi).
- Input device (PC, server, or VPS) to run SIM control software.
- SIM control software such as pySim, pyserial, or Gammu.
- Telegram Bot API and Python or Node.js for message handling.
Implementation: Building the SMS and Telegram System
We will deploy the system in the following steps:
1. Install Gammu and Connect the SIM Module
On the VPS, install Gammu – an open-source tool to control SIM modules via COM or USB ports:
sudo apt update
sudo apt install gammu gammu-smsd
After installation, verify the SIM connection with the command:
gammu identify
If the connection is successful, Gammu will display network information, IMEI, and SIM status.
2. Configure Gammu SMSD to Send SMS
Create the configuration file /etc/gammu/gammu.conf:
[gammu]
port = /dev/ttyUSB0
connection = at
model =
sendsms = 0
Start the SMSD service:
sudo systemctl start gammu-smsd
sudo systemctl enable gammu-smsd
3. Integrate with Telegram Bot
Create a Telegram bot via BotFather and obtain the API token. Then write a Python script to send messages:
import requests
import json
TELEGRAM_BOT_TOKEN = "YOUR_BOT_TOKEN"
CHAT_ID = "YOUR_CHAT_ID"
def send_telegram_message(message):
url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
payload = {
"chat_id": CHAT_ID,
"text": message
}
response = requests.post(url, data=payload)
return response.status_code
# Send notification
send_telegram_message("Alert: System has an issue!")
4. Connect Gammu with Telegram
Use a webhook or automated script so that when an SMS is received, the system sends a notification via Telegram. For example, when an OTP is received, Gammu sends the SMS and simultaneously triggers a Python script to send a Telegram message.
Implementation: Automating OTP and Alert Sending
To send OTPs, you can create a simple web service using Python Flask or Node.js. When a user requests an OTP, the system will:
- Generate a random OTP.
- Send the OTP via the SIM module using Gammu.
- Send an alert notification via Telegram.
Here is a simple Python code snippet to send an OTP:
from random import randint
import gammu
def send_otp(phone_number):
otp = randint(100000, 999999)
message = f"Your OTP is: {otp}"
gammu.send_sms({
'Text': message,
'SMSC': {'Number': '+84900000000'},
'Number': phone_number
})
return otp
Testing and Verification
To test the system:
- Send an SMS to the SIM module and verify that the message is received.
- Send a test message via the Telegram bot to check connectivity.
- Perform an OTP send and verify that the code reaches the correct phone number.
Troubleshooting
- SIM not recognized: Check USB connection, try a different COM port, and install drivers.
- Cannot send SMS: Verify Gammu configuration, phone number, and SIM status (balance, signal).
- Telegram not receiving messages: Check bot token, chat ID, and internet connection.
Reference Resources
Assumptions: The system is deployed in a secure environment with no high-security requirements. No specific device or network information is provided, so the guide uses common, scalable tools.
High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-4E
10% VAT included
- CPU: 4 vCPU
- RAM: 8 GB
- SSD: 50 GB NVMe
