DEV Community

Alex Spinov
Alex Spinov

Posted on

Telegram Has a Free Bot API — Send Messages, Build Bots, and Automate Chats Without Any Cost

Telegram's Bot API is completely free — no subscription, no rate limit anxiety, no hidden costs. Create a bot in 30 seconds, get a token, and start sending messages, building menus, handling payments, and processing files.

Over 400 million people use Telegram monthly. Your bot gets access to all of them for $0.

Create Your Bot (30 Seconds)

  1. Open Telegram, search for @botfather
  2. Send /newbot
  3. Choose a name and username
  4. Copy your bot token (looks like 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11)

That's it. You're ready to code.

1. Send a Message

curl "https://api.telegram.org/bot<YOUR_TOKEN>/sendMessage" \
  -d "chat_id=YOUR_CHAT_ID" \
  -d "text=Hello from my bot!"
Enter fullscreen mode Exit fullscreen mode

To find your chat_id, send any message to your bot, then call:

curl "https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates"
Enter fullscreen mode Exit fullscreen mode

2. Send Photos, Documents, and Media

# Send a photo
curl "https://api.telegram.org/bot<YOUR_TOKEN>/sendPhoto" \
  -F "chat_id=YOUR_CHAT_ID" \
  -F "photo=@/path/to/image.jpg" \
  -F "caption=Check this out!"

# Send a document
curl "https://api.telegram.org/bot<YOUR_TOKEN>/sendDocument" \
  -F "chat_id=YOUR_CHAT_ID" \
  -F "document=@/path/to/report.pdf"
Enter fullscreen mode Exit fullscreen mode

3. Python Bot — Echo + Commands

import requests

TOKEN = "YOUR_BOT_TOKEN"
BASE = f"https://api.telegram.org/bot{TOKEN}"

def get_updates(offset=None):
    params = {"timeout": 30}
    if offset:
        params["offset"] = offset
    return requests.get(f"{BASE}/getUpdates", params=params).json()

def send_message(chat_id, text):
    requests.post(f"{BASE}/sendMessage", json={
        "chat_id": chat_id,
        "text": text,
        "parse_mode": "Markdown"
    })

def main():
    offset = None
    while True:
        updates = get_updates(offset)
        for update in updates.get("result", []):
            offset = update["update_id"] + 1
            msg = update.get("message", {})
            text = msg.get("text", "")
            chat_id = msg["chat"]["id"]

            if text == "/start":
                send_message(chat_id, "Welcome! Send me any message.")
            elif text == "/help":
                send_message(chat_id, "Commands: /start, /help, /time")
            elif text == "/time":
                from datetime import datetime
                send_message(chat_id, f"Server time: {datetime.now()}")
            else:
                send_message(chat_id, f"You said: *{text}*")

main()
Enter fullscreen mode Exit fullscreen mode

4. Node.js Bot — Webhook Style

const TOKEN = "YOUR_BOT_TOKEN";
const BASE = `https://api.telegram.org/bot${TOKEN}`;

async function sendMessage(chatId, text) {
  await fetch(`${BASE}/sendMessage`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ chat_id: chatId, text, parse_mode: "Markdown" }),
  });
}

// Express webhook handler
app.post("/webhook", async (req, res) => {
  const { message } = req.body;
  if (message?.text) {
    await sendMessage(message.chat.id, `Echo: ${message.text}`);
  }
  res.sendStatus(200);
});
Enter fullscreen mode Exit fullscreen mode

5. Inline Keyboards (Interactive Buttons)

curl "https://api.telegram.org/bot<YOUR_TOKEN>/sendMessage" \
  -H "Content-Type: application/json" \
  -d '{
    "chat_id": "YOUR_CHAT_ID",
    "text": "Choose an option:",
    "reply_markup": {
      "inline_keyboard": [
        [{"text": "Option A", "callback_data": "a"}],
        [{"text": "Option B", "callback_data": "b"}],
        [{"text": "Visit Website", "url": "https://example.com"}]
      ]
    }
  }'
Enter fullscreen mode Exit fullscreen mode

Rate Limits

Action Limit
Messages to same chat 1/second
Messages to different chats 30/second
Group messages 20/minute per group
File upload 50 MB max
Bulk notifications 30 messages/second

For most bots, you'll never hit these limits.

What You Can Build

  • Notification bot — server alerts, price drops, weather updates
  • Customer support bot — auto-replies, FAQ, ticket creation
  • Content bot — daily quotes, news digest, RSS reader
  • E-commerce bot — product catalog, orders, payments (Telegram Payments API)
  • Monitoring dashboard — send charts and reports to a channel
  • Group moderation bot — auto-kick spammers, welcome messages

More Free API Articles


Need Web Data? Try These Tools

If you're building apps that need web scraping or data extraction, check out my ready-made tools on Apify Store — scrapers for Reddit, YouTube, Google News, Trustpilot, and 80+ more. No coding needed, just run and get your data.

Need a custom scraping solution? Email me at spinov001@gmail.com


More Free APIs You Should Know About

Need custom data scraping? Email me or check my Apify actors.

Top comments (0)