Skip to main content

Channels

Telegram

Message Telegram from your app with telegram() — a bot token and a chat id, zero config.


import { telegram } from "postboi"

await telegram({ to: "987654321", message: "Deploy finished" })
import { telegram } from "postboi"

await telegram({ to: "987654321", message: "Deploy finished" })

Setup

Create a bot with @BotFather and give Postboi its token:

# .env
TELEGRAM_BOT_TOKEN=123456:ABC-…
# .env
TELEGRAM_BOT_TOKEN=123456:ABC-…

Commit a default chat id as chat.default.to in postboi.config.ts and the to can be omitted:

export default config({
	chat: { provider: "telegram", default: { to: "987654321" } },
})
export default config({
	chat: { provider: "telegram", default: { to: "987654321" } },
})

A chat id is a registered identity, not an address

A bot cannot message someone who hasn’t started a chat with it first, and you address people by chat_id — a number you capture from an inbound update, not something you can know in advance. That’s the same shape as a push subscription token, so it needs somewhere to be stored. Slack, Discord and Teams have no equivalent problem: there, the URL is the destination.

Titles

title renders bold, with the body safely below it — Postboi sends HTML parse mode with everything escaped, so a message containing <, & or an underscore never breaks the formatting or gets mangled by Markdown rules:

await telegram({ title: "Deploy <ok>", message: "migrated table user_accounts & friends" })
await telegram({ title: "Deploy <ok>", message: "migrated table user_accounts & friends" })

Development posts for real

Unlike SMS, Telegram is not intercepted in development. With no TELEGRAM_BOT_TOKEN configured, messages are captured by the dev inbox (or logged) instead of erroring.

Worth knowing

  • Telegram reports failures with ok: false and an HTTP 200, so don’t check status yourself — the normalised error already accounts for it.
  • In a multi-channel send(), the chat leg posts to whichever platform chat.provider names in your config. Your own code just calls telegram().