npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@effect-ak/tg-bot-client

v1.12.0

Published

Type-safe HTTP client for Telegram Bot API

Readme

@effect-ak/tg-bot-client

NPM Version NPM Downloads

Type-safe HTTP client for the Telegram Bot API. One execute method covers every API method, files are encoded to FormData automatically, errors are typed. Native fetch, zero runtime dependencies — runs on Node.js 18+, Bun, Deno, Cloudflare Workers, browsers.

Types come from @effect-ak/tg-bot-api; the bot framework @effect-ak/tg-bot is built on this client.

Installation

npm install @effect-ak/tg-bot-client

The Bot API types are re-exported under a subpath, so this is the only package you need:

import { makeTgBotClient } from "@effect-ak/tg-bot-client"
import type { Message, Update } from "@effect-ak/tg-bot-client/api"

Quick Start

import { makeTgBotClient } from "@effect-ak/tg-bot-client"

const client = makeTgBotClient({ bot_token: "YOUR_BOT_TOKEN" })

// Method names are snake_case, exactly as in the official docs
const message = await client.execute("send_message", {
  chat_id: 123456789,
  text: "Hello!"
})

API Surface

makeTgBotClient({ bot_token, base_url?, timeout? }): TgBotClient

interface TgBotClient {
  execute(method, params, options?): Promise<Result>            // throws TgBotClientError
  executeSafe(method, params, options?): Promise<ClientResult>  // never throws
  getFile({ fileId }): Promise<TgFile>                          // download by file_id
  getFileSafe({ fileId }): Promise<ClientResult<TgFile>>
}

type ClientResult<T> = { ok: true; data: T } | { ok: false; error: ClientErrorReason }
type ClientErrorReason =
  | { _tag: "NotOkResponse"; errorCode?: number; details?: string }  // Telegram said ok:false
  | { _tag: "RequestTimeout"; timeoutMs: number }
  | { _tag: "NotJsonResponse" | "UnexpectedResponse" | "ClientInternalError" | "UnableToGetFile"; ... }
  • Method and parameter names match https://core.telegram.org/bots/api in snake_case (send_message, edit_message_text, answer_callback_query). Both are autocompleted; return types are inferred.
  • Files: pass { file_content: Uint8Array, file_name: string } wherever the API accepts InputFile — the client switches to multipart automatically. Or pass a file_id / URL string.
  • Message effects: message_effect_id accepts an emoji key of MESSAGE_EFFECTS ("🔥" | "👍" | "👎" | "❤️" | "🎉" | "💩") and is mapped to the real id.
  • Errors: execute throws TgBotClientError (error.reason is the tagged union above); executeSafe returns the union — pick one style and stick to it.
  • Options: { timeout } per call; base_url for a self-hosted Bot API server.

Examples

// Safe variant
const result = await client.executeSafe("get_chat", { chat_id: 1 })
if (!result.ok) console.error(result.error._tag)

// Upload a file
await client.execute("send_document", {
  chat_id,
  document: { file_content: new TextEncoder().encode("hi"), file_name: "hi.txt" },
  caption: "Generated on the fly"
})

// Download a file
const file = await client.getFile({ fileId })
file.content // ArrayBuffer

Documentation

  • Guide: tg-bot-sdk.website/client/usage
  • Bot API reference (one page per method): https://tg-bot-sdk.website/api/
  • For LLMs / coding agents: https://tg-bot-sdk.website/llms.txt

License

MIT