// guides

Telegram bot for beginners: get your chat ID and send messages with curl or Python

Create a bot with BotFather, find the chat id of a private chat, group or channel, send your first message with one curl command, then use a tested Python snippet that handles errors and rate limits. Plus 9 free Telegram alerts.

Updated 2026-10-19 · about 10 minutes

Rather not set it up yourself? Describe your task in one sentence and we'll build and test it for you, free →

Steps

  1. Create a bot with BotFather

    In Telegram, open @BotFather (the one with the blue check), send /newbot, then pick a display name and a username that ends in bot. BotFather replies with a token like 123456789:AAH.... That token is the only key you need.

  2. Check the token works

    Open https://api.telegram.org/botYOUR_TOKEN/getMe in a browser (keep the word bot right before the token). A good token returns "ok":true with your bot's username. A wrong token returns 401 Unauthorized; a cut-off token or missing bot prefix returns 404 Not Found.

  3. Find your chat id

    Open your bot, press Start and send it any message, then open https://api.telegram.org/botYOUR_TOKEN/getUpdates and look for "chat":{"id":...}. A private chat id is a positive number. In a group, add the bot and send /start@your_bot (bots only see commands and mentions in groups by default); the id is negative, and supergroups start with -100. For a channel, make the bot an admin that can post; you can then use @channelname for a public channel, or the -100... id from a post forwarded to getUpdates. Empty result? Send a fresh message and reload.

  4. Send your first message with curl

    From any terminal:

    curl -s -X POST "https://api.telegram.org/botYOUR_TOKEN/sendMessage" \
      -d chat_id=YOUR_CHAT_ID \
      -d text="Hello from my script"
    The reply starts with {"ok":true,"result":{"message_id":... and the message appears in your chat. On Windows PowerShell, use curl.exe instead of curl.

  5. Send from a script, then schedule it

    Use the Python script below in any job: a backup, a scraper, a price check. It escapes the text, retries once when Telegram says to slow down, and exits with an error you can see in logs. Run it on a schedule with cron, Task Scheduler or GitHub Actions; see run a Python script on a schedule.

The script

Save this as send_telegram.py. It uses only Python's standard library, so there is nothing to install.

#!/usr/bin/env python3
"""Send a Telegram message from a script. Standard library only."""
import html, json, os, sys, time, urllib.error, urllib.request

TOKEN = os.environ["TELEGRAM_BOT_TOKEN"]
CHAT_ID = os.environ["TELEGRAM_CHAT_ID"]
API = os.environ.get("TELEGRAM_API", "https://api.telegram.org")

def send(text, tries=3):
    body = json.dumps({"chat_id": CHAT_ID, "text": text[:4096], "parse_mode": "HTML",
                       "disable_web_page_preview": True}).encode()
    for attempt in range(tries):
        req = urllib.request.Request(f"{API}/bot{TOKEN}/sendMessage", data=body,
                                     headers={"Content-Type": "application/json"})
        try:
            with urllib.request.urlopen(req, timeout=20) as r:
                return json.load(r)["result"]["message_id"]
        except urllib.error.HTTPError as e:
            err = json.load(e)
            wait = err.get("parameters", {}).get("retry_after")
            if e.code == 429 and wait and attempt < tries - 1:
                time.sleep(wait)  # Telegram tells you how long to wait
                continue
            sys.exit(f"Telegram said {e.code}: {err.get('description')}")

title = sys.argv[1] if len(sys.argv) > 1 else "Hello from my script"
print("sent message", send(f"<b>{html.escape(title)}</b>"))

Run it with your token and chat id in the environment:

export TELEGRAM_BOT_TOKEN=123456789:AA...
export TELEGRAM_CHAT_ID=987654321
python3 send_telegram.py "Backup finished"

What we saw when we tested it (19 Oct 2026)

Common errors and what they mean

Good to know

9 free Telegram alerts you can set up next

Each one uses the same bot token and chat id you just found, and each comes with a free tested script.

  1. Any RSS feed, filtered by keyword: blogs, news, job boards, patch notes. Guide
  2. Reddit keyword mentions: your product, game or name, no Reddit API key. Guide
  3. New YouTube uploads: with or without Shorts. Guide
  4. Twitch go-live alerts: one message per stream. Guide
  5. Free games: Epic's weekly freebies plus Steam, GOG and itch.io giveaways. Guide
  6. Steam wishlist price drops: your target price or a new low. Guide
  7. GitHub releases: any public repo, pre-releases skipped. Guide
  8. Important emails: Gmail, Outlook or any IMAP, filtered by sender or subject. Guide
  9. A web page changed or is back in stock: with the lines that changed. Guide

Using Discord instead? Start with Discord webhooks for beginners and the 13 Discord webhook ideas.

FAQ

Is the Telegram Bot API free?

Yes. Creating bots with BotFather and sending messages through the Bot API costs nothing.

Can my bot message someone first?

No. A person has to open the bot and press Start (or add it to a group) before the bot can message them. That's why 'chat not found' is the most common first error.

Do I need a server to run a Telegram bot?

Not for sending alerts. A script that calls sendMessage and exits is enough, run by cron, Task Scheduler or GitHub Actions. You only need something always online if the bot must answer messages instantly.

How do I send to several chats?

Call sendMessage once per chat id, about one per second, or post to a channel that everyone joins.

What's the difference between the chat id and the bot username?

The username (like @my_alerts_bot) is how people find the bot. The chat id is the number for the conversation the bot posts into: you, a group or a channel.

Related guides

New guides

Want one built for your task?

Describe it in one sentence. We build it, test it and email it to you, usually within 24h. Free while we're in beta.

We'll only email you about your agent and TaskToAgent.