gitmyhub

node-telegram-bot-api

TypeScript ★ 9.2k updated 1d ago

Telegram Bot API for NodeJS

Node.js library for building Telegram bots in JavaScript or TypeScript, wraps Telegram's HTTP API so you can handle commands, send messages and media, and receive updates via polling or webhooks in a few lines of code.

JavaScriptTypeScriptNode.jsnpmsetup: easycomplexity 2/5

Telegram is a messaging app, and it lets developers create automated accounts called bots that can respond to messages, handle commands, and take actions inside Telegram chats and groups. This library, node-telegram-bot-api, is a Node.js package that gives JavaScript developers a straightforward way to build those bots without dealing with Telegram's raw HTTP API directly.

To get started, you install the package from npm, create a bot token using Telegram's official BotFather setup tool, then write code that listens for incoming messages and sends replies. The library manages the back-and-forth communication with Telegram's servers through a method called polling, where it periodically checks for new messages on your behalf. You can set up pattern matching to catch specific commands like "/echo" and extract the text that follows, or listen to all incoming messages at once and route them however your code needs.

The library maps closely to the official Telegram Bot API, which means you can send text, photos, documents, and other content types that Telegram supports. TypeScript developers can install an additional types package to get full type definitions for every method and response object. The documentation includes usage guides, a set of examples, tutorials, and a full API reference covering both the current release and any experimental features still in development.

Other developers have published related packages built on top of this library: a higher-level wrapper that adds more features, middleware for structuring bot logic, date and time picker components, captcha protection for groups, and a bridge that connects Telegram chats to IRC channels. There is also a Telegram channel and group where the maintainers post updates and where you can discuss issues.

The project is open source under the MIT License and accepts community contributions through its GitHub repository.

Where it fits