π Deploy a Telegram Bot for FREE Using Google Apps Script (GAS)
Want to deploy a Telegram bot for free, without servers, VPS, or DevOps headaches?
Google Apps Script (GAS) is one of the simplest ways to do itβespecially for text-based bots, MVPs, and learning projects.
This guide walks you through a complete, production-ready setup using webhooks.
π§ What Is Google Apps Script?
Google Apps Script is a serverless JavaScript runtime by Google, designed to automate Google productsβbut it can also act as a lightweight backend.
Key benefits:
- β Free
- β No server management
- β HTTPS by default
- β Easy webhook support
π€ What Youβll Build
A Telegram bot that:
- Receives messages via webhook
- Processes them in GAS
- Replies instantly using Telegram Bot API
Architecture:
Telegram β Webhook β GAS Web App β Telegram API
π Prerequisites
- Telegram account
- A bot token from @botfather on Telegram
- Google account
πͺ Step 1: Create a Telegram Bot
- Open Telegram
- Search for @botfather
- Run
/start - Run
/newbot - Set:
- Bot name
- Bot username
- Copy the Bot Token (keep it secret)
πͺ Step 2: Create Google Apps Script Project
- Go to https://script.google.com
- Click New Project
- Rename it (e.g.
telegram-bot-gas)
πͺ Step 3: Add Bot Code (Webhook Handler)
Paste this minimal working bot:
const TOKEN = "YOUR_BOT_TOKEN";
const TELEGRAM_API = `https://api.telegram.org/bot${TOKEN}`;
function doPost(e) {
const update = JSON.parse(e.postData.contents);
if (update.message) {
const chatId = update.message.chat.id;
const text = update.message.text || "";
sendMessage(chatId, `You said: ${text}`);
}
return ContentService.createTextOutput("OK");
}
function sendMessage(chatId, text) {
const payload = {
chat_id: chatId,
text: text
};
UrlFetchApp.fetch(`${TELEGRAM_API}/sendMessage`, {
method: "post",
contentType: "application/json",
payload: JSON.stringify(payload)
});
}
π Tip: For production, store the token in Script Properties instead of hardcoding.
πͺ Step 4: Deploy as a Web App
- Click Deploy β New deployment
- Type: Web app
- Execute as: Me
- Who has access: Anyone
- Click Deploy
- Copy the Web App URL
Example:
https://script.google.com/macros/s/AKfycbxxxxx/exec
πͺ Step 5: Set Telegram Webhook
Open this URL in your browser (replace values):
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=<WEB_APP_URL>
If successful, youβll see:
{"ok":true,"result":true}
π Your bot is now live.
πͺ Step 6: Test Your Bot
- Open Telegram
- Send a message to your bot
- You should get an instant reply
β¨ Adding Commands (Optional)
if (text === "/start") {
sendMessage(chatId, "Welcome to my GAS bot!");
}
β Important Limitations of GAS
Before scaling, understand these constraints:
| Limitation | Details |
|---|---|
| Execution time | ~30s (free) |
| Cold starts | 1β5s delay after idle |
| No background jobs | Webhook-only execution |
| No streaming | Bad for large media |
| No npm packages | Pure JS only |
| Limited storage | Sheets / Properties |
β
Best for text bots, MVPs, automation
β Not for AI bots, media-heavy bots, high traffic
π’ When GAS Is a Good Choice
Use GAS if:
- You want 100% free hosting
- Bot is text-based
- Traffic is low to medium
- You want fast setup
- Youβre building a prototype
π΅ When to Switch Platforms
Move away from GAS if you need:
- Media streaming
- Databases
- AI inference
- High concurrency
Better free alternatives:
- Cloudflare Workers
- Fly.io
- Supabase (DB)
π§Ύ Final Thoughts
Google Apps Script is one of the fastest ways to deploy a Telegram bot for free.
Think of it as:
A powerful serverless glue, not a full backend.
For learning, MVPs, and simple botsβitβs perfect.
If you want:
- A production-grade GAS bot template
- Inline keyboards
- Sheets as a database
- Migration guide to Cloudflare Workers
Comment below π



Top comments (1)
script.google.com/u/1/home/?pageId...
web.telegram.org/a/?account=2