DEV Community

Alex Spinov
Alex Spinov

Posted on

Telegram Bot API — The Most Developer-Friendly API I Have Ever Used

Why Telegram Bot API Is Special

Most APIs make you fight with OAuth, rate limits, and pagination. Telegram Bot API gives you a simple HTTP interface with instant webhooks, no OAuth, and generous limits.

Create a Bot in 60 Seconds

  1. Open Telegram, search for @botfather
  2. Send /newbot
  3. Choose a name and username
  4. Copy the API token

Done. No OAuth app registration, no redirect URIs, no client secrets.

Send a Message

import requests

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

def send_message(chat_id, text):
    r = requests.post(f"{BASE}/sendMessage", json={
        "chat_id": chat_id, "text": text, "parse_mode": "HTML"
    })
    return r.json()["ok"]

send_message("your_chat_id", "<b>Hello</b> from Python!")
Enter fullscreen mode Exit fullscreen mode

Get Updates (Polling)

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

# Simple bot loop
offset = 0
while True:
    updates = get_updates(offset)
    for u in updates:
        msg = u.get("message", {})
        text = msg.get("text", "")
        chat_id = msg["chat"]["id"]

        if text == "/start":
            send_message(chat_id, "Welcome! I am your bot.")
        elif text == "/help":
            send_message(chat_id, "Commands: /start, /help, /ping")
        elif text == "/ping":
            send_message(chat_id, "Pong!")

        offset = u["update_id"] + 1
Enter fullscreen mode Exit fullscreen mode

Send Files, Photos, Locations

# Send a photo
def send_photo(chat_id, photo_url, caption=""):
    requests.post(f"{BASE}/sendPhoto", json={
        "chat_id": chat_id, "photo": photo_url, "caption": caption
    })

# Send location
def send_location(chat_id, lat, lon):
    requests.post(f"{BASE}/sendLocation", json={
        "chat_id": chat_id, "latitude": lat, "longitude": lon
    })

# Send a document
def send_document(chat_id, file_url):
    requests.post(f"{BASE}/sendDocument", json={
        "chat_id": chat_id, "document": file_url
    })
Enter fullscreen mode Exit fullscreen mode

Inline Keyboards (Buttons)

def send_with_buttons(chat_id, text, buttons):
    keyboard = {"inline_keyboard": buttons}
    requests.post(f"{BASE}/sendMessage", json={
        "chat_id": chat_id, "text": text, "reply_markup": keyboard
    })

send_with_buttons("chat_id", "Choose an option:", [
    [{"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

Real Bot Ideas

  1. Server monitor — send alerts when CPU/memory spikes
  2. Daily digest — summarize news/data every morning
  3. Expense tracker — log expenses by sending messages
  4. Deployment notifier — alert on successful/failed deploys
  5. RSS reader — forward new articles from your favorite blogs

Why Not Discord/Slack?

Feature Telegram Discord Slack
Bot creation 60 seconds 5 minutes 10 minutes
OAuth needed No Yes Yes
Free API Unlimited Yes Limited
Message formatting HTML/Markdown Markdown Blocks
File upload limit 50MB 25MB (free) Varies
Webhook setup 1 API call Dashboard Dashboard

More API tutorials | GitHub


More from me: 10 Dev Tools I Use Daily | 77 Scrapers on a Schedule | 150+ Free APIs
NEW: I Ran an AI Agent for 16 Days — What Actually Works


Need web scraping or data extraction? I've built 77+ production scrapers. Email spinov001@gmail.com — quote in 2 hours. Or try my ready-made Apify actors — no code needed.

Top comments (3)

Collapse
 
nomad4tech profile image
nomad4tech

The worst one for me was WhatsApp - even through third-party wrappers, it was a pain to connect a bot

Collapse
 
0012303 profile image
Alex Spinov

I have not shipped a WhatsApp bot, so I will not pretend to compare from experience. But the shape you are describing is the tell: when third-party wrappers are the story, the API is not really the product — the business relationship is.

The Telegram thing that still surprises me is not the API design, it is that the token is issued by a bot, in a chat, in about thirty seconds, and works from a laptop with curl straight away. No review, no business verification, no sandbox tier that behaves differently from production. Most of the pain in bot platforms lives before the first request rather than inside it.

Collapse
 
workout097collab profile image
Vasyl

Great breakdown 👍
Telegram Bot API is definitely one of the most straightforward APIs to start with.