How to hit the Telegram Bots API

Every Telegram Bot API call is https://api.telegram.org/bot<token>/<method>. Responses are {"ok": true, "result": …} or {"ok": false, "description": …}.

Authentication

Message @BotFather in Telegram, send /newbot, and it gives you a token like 123456:ABC-DEF…. It goes in the URL, so treat the whole URL as secret. In the examples it's written {{TELEGRAM_BOT_TOKEN}}.

A bot can only message someone who has messaged it first. To find your chat id, message your bot, then run get updates.

Full reference: https://core.telegram.org/bots/api

Check your bot

The bot's id, name, and username — confirms the token works.

curl https://api.telegram.org/bot{{TELEGRAM_BOT_TOKEN}}/getMe
Run in PostTaco

Send a message

parse_mode can be MarkdownV2 or HTML.

curl -X POST https://api.telegram.org/bot{{TELEGRAM_BOT_TOKEN}}/sendMessage \
  -H "Content-Type: application/json" \
  -d '{"chat_id": "{{CHAT_ID}}", "text": "Hello from <b>PostTaco</b>", "parse_mode": "HTML"}'
Run in PostTaco

Get updates

Messages sent to your bot since the last call. Each has message.chat.id. Doesn't work while a webhook is set.

curl "https://api.telegram.org/bot{{TELEGRAM_BOT_TOKEN}}/getUpdates?limit=10"
Run in PostTaco

Set a webhook

Telegram POSTs every update to your HTTPS URL instead. deleteWebhook undoes it.

curl -X POST https://api.telegram.org/bot{{TELEGRAM_BOT_TOKEN}}/setWebhook \
  -H "Content-Type: application/json" \
  -d '{"url": "{{WEBHOOK_URL}}"}'
Run in PostTaco