Zero-dependency cloud function to forward SMS messages to Telegram
Explore the repo »
Report Bug
·
Request Feature
This repository contains a zero-dependency cloud function that forwards incoming SMS messages received through SMSGate App webhooks to a specified Telegram chat. The entire implementation is a single Node.js file with no external packages.
- Node.js 18+ (required for native
fetch) - SMSGate App installed on your device in Local, Cloud, or Private mode
- A Telegram bot and its token — create one via BotFather
- A Telegram chat ID where messages will be forwarded
- Clone the repository
git clone https://github.com/android-sms-gateway/example-telegram-forwarder-fn.git
- No dependencies to install — the function uses only Node.js built-in APIs. Run
npm installonly if you add external packages. - Set up your environment variables (see Environment Variables)
- Deploy to your preferred cloud provider (AWS Lambda, Google Cloud Functions, etc.). The handler uses the standard
(event, context)FaaS signature. You may need to adapt the entry point — consult your provider's documentation. - Register a webhook in SMSGate App with the URL of your deployed function, appending
?apiKey=YOUR_API_KEYas a query parameter.
| Variable | Description |
|---|---|
API_KEY |
Random secret for webhook authentication, passed as the apiKey query parameter |
TELEGRAM_BOT_TOKEN |
Token of your Telegram bot (from BotFather) |
TELEGRAM_CHAT_ID |
ID of the Telegram chat where messages will be forwarded |
The function is triggered by incoming webhook events from SMSGate App. Upon receiving an SMS, it:
- Validates the
apiKeyquery parameter againstAPI_KEY(returns401 Unauthorizedon mismatch) - Parses the webhook JSON payload — expects
payload.phoneNumberandpayload.message - Escapes HTML special characters in the message body
- Sends a formatted message to Telegram via the Bot API (
sendMessage) with HTML parse mode - Returns
200 OKon success
A requests.http file is provided for manual testing with the REST Client extension for VS Code. It includes:
- Endpoints to verify your Telegram bot (
getMe,getUpdates,getWebhookInfo) - A sample POST request against a deployed Lambda URL with a realistic SMS webhook payload
For local testing with the REST Client extension: create a .env file (use .env.example as a template) — the $dotenv placeholders in requests.http read from it automatically. Then open requests.http and click Send Request above each block.
For cloud or hosted deployments, set these variables through your provider's environment configuration (e.g., AWS Lambda environment variables, Google Cloud Functions --set-env-vars) instead of a .env file.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue. Don't forget to give the project a star!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the Apache-2.0 License. See LICENSE for more information.
Project Link: https://github.com/android-sms-gateway/example-telegram-forwarder-fn