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

Published: (March 25, 2026 at 08:09 PM EDT)
3 min read
Source: Dev.to

Source: Dev.to

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.

Getting Started

  1. Open Telegram and 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.

Basic Python Example

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", "**Hello** from Python!")

Receiving Updates (Long 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

Sending Different Types of Content

# 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
    })

Inline Keyboard 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"}]
])

Common Use Cases

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

Feature Comparison

FeatureTelegramDiscordSlack
Bot creation60 seconds5 minutes10 minutes
OAuth neededNoYesYes
Free APIUnlimitedYesLimited
Message formattingHTML/MarkdownMarkdownBlocks
File upload limit50 MB25 MB (free)Varies
Webhook setup1 API callDashboardDashboard

More API tutorials | GitHub

0 views
Back to Blog

Related posts

Read more »