@apicity/telegram
v0.4.2
Published
Telegram Bot API provider for sending text, photo, video, and audio messages.
Maintainers
Readme
@apicity/telegram
Telegram Bot API provider for sending text, photo, video, and audio messages.
Runtime dependencies:
zod@^3.24.0— request schemas attached to every POST endpoint as.schema
Installation
npm install @apicity/telegram
# or
pnpm add @apicity/telegramQuick Start
import { createTelegram } from "@apicity/telegram";
const telegram = createTelegram({ botToken: process.env.TELEGRAM_BOT_KEY! });Setup
This package uses a Telegram Bot API token. In this repo,
TELEGRAM_BOT_KEY resolves from 1Password for @apicitylogbot.
import { createTelegram } from "@apicity/telegram";
const telegram = createTelegram({
botToken: process.env.TELEGRAM_BOT_KEY!,
});
await telegram.sendMessage({
chat_id: "@your_channel_or_chat_id",
text: "hello from @apicity/telegram",
});
const photo = new Blob(["image bytes"], { type: "image/png" });
await telegram.sendPhoto({
chat_id: "@your_channel_or_chat_id",
photo,
caption: "uploaded from @apicitylogbot",
});Notes
chat_idcan be a numeric chat id or a username such as@channelname.photo,video,audio,thumbnail, andcoveraccept a Telegramfile_id, an HTTP URL, anattach://...reference, or aBlob.- Blob payloads are sent as
multipart/form-data; string payloads useapplication/json.
API Reference
4 endpoints across 4 groups. Each method mirrors an upstream URL path.
sendAudio
POST https://api.telegram.org/bot{token}/sendAudio
const res = await telegram.sendAudio({ /* ... */ });Source: packages/provider/telegram/src/telegram.ts
sendMessage
POST https://api.telegram.org/bot{token}/sendMessage
const res = await telegram.sendMessage({ /* ... */ });Source: packages/provider/telegram/src/telegram.ts
sendPhoto
POST https://api.telegram.org/bot{token}/sendPhoto
const res = await telegram.sendPhoto({ /* ... */ });Source: packages/provider/telegram/src/telegram.ts
sendVideo
POST https://api.telegram.org/bot{token}/sendVideo
const res = await telegram.sendVideo({ /* ... */ });Source: packages/provider/telegram/src/telegram.ts
Part of the apicity monorepo.
License
MIT — see LICENSE.
