Configs2026年7月15日·1 分钟阅读

node-telegram-bot-api — Telegram Bot API Client for Node.js

A straightforward Node.js module for the Telegram Bot API with support for polling, webhooks, inline queries, and all bot methods.

Agent 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 17/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
CLI Tool
安装
Stage only
信任
信任等级:Established
入口
node-telegram-bot-api Overview
安全暂存命令
npx -y tokrepo@latest install 31c6c3b4-808e-11f1-9bc6-00163e2b0d79 --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

Introduction

node-telegram-bot-api is a Node.js library that provides a complete wrapper around the Telegram Bot API. It handles both polling and webhook modes for receiving updates, and exposes every Telegram Bot API method as a simple async function call, making it one of the most widely used Telegram bot libraries in the JavaScript ecosystem.

What node-telegram-bot-api Does

  • Wraps every Telegram Bot API method (sendMessage, sendPhoto, editMessageText, etc.)
  • Supports two update modes: long polling and webhook via Express or built-in server
  • Handles inline queries, callback queries, and inline keyboard interactions
  • Provides event-based message handling with regex pattern matching
  • Supports file uploads, downloads, and media group operations

Architecture Overview

The library creates an HTTP client that communicates with the Telegram Bot API servers. In polling mode, it continuously calls the getUpdates endpoint to fetch new messages. In webhook mode, it starts an HTTPS server (or integrates with Express) that Telegram pushes updates to. Incoming updates are parsed and emitted as typed events (message, callback_query, inline_query) that developers attach listeners to. File operations use multipart form uploads under the hood.

Self-Hosting & Configuration

  • Requires Node.js 12 or newer
  • Install via npm: npm install node-telegram-bot-api
  • Create a bot through Telegram's @BotFather and obtain the API token
  • Choose polling mode for development or webhook mode for production
  • For webhooks, you need a public HTTPS URL (use a reverse proxy like Nginx with TLS)

Key Features

  • Complete coverage of the Telegram Bot API including payments, games, and stickers
  • Regex-based message matching for command routing
  • Built-in webhook server with optional TLS support
  • Promise-based API for clean async/await usage
  • Lightweight with minimal dependencies

Comparison with Similar Tools

  • Telegraf — Higher-level framework with middleware, scenes, and session management; node-telegram-bot-api is more lightweight and lower-level
  • grammY — Modern TypeScript-first framework with plugin ecosystem; node-telegram-bot-api has a larger install base and simpler API
  • aiogram — Python async equivalent; node-telegram-bot-api serves the same role for Node.js
  • python-telegram-bot — Python counterpart with a similar design philosophy

FAQ

Q: Should I use polling or webhooks? A: Polling is simpler for development and works behind NATs. Webhooks are more efficient for production since Telegram pushes updates to you instead of you requesting them.

Q: How do I handle inline keyboards and callbacks? A: Send messages with an inline_keyboard in reply_markup, then listen for the callback_query event to handle button presses.

Q: Does it support TypeScript? A: Type definitions are available via @types/node-telegram-bot-api.

Q: What license is it under? A: MIT License.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产