Telegram Bot API for Node.js
Node.js module for Telegram Bot API.
Talk with @botfather on Telegram to create your bot.
This module is updated with Telegram API version 4.2. Except with Telegram Passport.
API reference
Older Versions
Examples
There's a examples
directory on GitHub. Take a look ;)
Before run any example code, please install deps with npm i
and run npm run build
to transpile TS code to JS in dist folder.
News
- Removed experimental feature
SmartMenu
- Implemented menus builded with js generators
- Changes Polling
- Moved .startPolling() from Bot instance to Polling
Install
npm install api-telegram-bot
Start coding
const Bot Polling = ;// or using commonjs imports// const { Bot } = require("api-telegram-bot"); const TOKEN = "BOT_TOKEN";const bot = TOKEN;// polling constructor accepts some options as second parameter, see docsconst polling = bot; // subscribe to all message types (texts, photos, videos, and others)bot; // subscribe only to text messagesbot; // NOTE: message actions are provided only for message updates (text, photo, ...)bot;
Enable debug log
Start your application with DEBUG env variable containing 'api-telegram-bot' value. Reference to debug package
$ DEBUG=api-telegram-bot npm start
To see debug logs from webhook or polling:
$ DEBUG=api-telegram-bot:polling npm start
$ DEBUG=api-telegram-bot:webhook npm start
Reply Markup Builders
Reply Keyboard Markup
const KeyboardBuilder = ; const TOKEN = 'BOT_TOKEN';const CONTACT_ID = 'CONTACT_ID';const bot = TOKEN; const keyboard = ; bot;
Inline Keyboard
; ;; ; .newRow .button .button .newRow .button .keyboard; bot.sendMessageCONTACT_ID, "Confirm?", ;
See the message sent by code above: