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

telegram-inline-keyboard-builder

v2.0.1

Published

Universal inline keyboard builder for Telegram APIs

Readme

Logo npm version npm downloads license Telegram

Inline Keyboard Builder (v2) Universal inline keyboard builder for Telegram Bots.

Produces pure Telegram Bot API compliant JSON, usable with any library (Telegraf, node-telegram-bot-api, Pyrogram, Aiogram, Puregram, Telebot…).

Version 2 removes adapters and focuses on a single universal output: valid inline_keyboard JSON as expected by Telegram API.


🚀 Key Features - Fluent & chainable API - Library-agnostic (no adapters, no dependencies)

  • Produces pure Telegram inline keyboard JSON
  • Auto-wrap & row control - Works with any Telegram framework
  • Zero abstraction leak

Installation

npm install telegram-inline-keyboard-builder

importation

import { InlineKeyboardBuilder } from "telegram-inline-keyboard-builder"; 

🧠 Core Concept

Telegram inline keyboards follow one universal schema.

This builder:

  • generates the keyboard directly in Telegram format

  • lets you pass the result to any Telegram library

{ reply_markup: { inline_keyboard: [...] } } 
  • No adapters.
  • No wrappers.
  • No framework coupling.

🔧 Public API

Constructor

new InlineKeyboardBuilder({ buttonsPerRow = 2, autoWrapMaxChars = 0 }) 

//Chainable Methods

.addCallbackButton(text, callback_data, hide = false) 
.addUrlButton(text, url, hide = false) 
.addPayButton(text, options = {}) 
.addCustomButton(buttonObject) 
.addButtons(config) 
.setButtonsPerRow(n) 
.setAutoWrapMaxChars(n) 
.newRow() 

// build
.build() 

const keyboard = builder.build(); 

// Always returns:

{ reply_markup: { inline_keyboard: [...] } } 

Fully compliant with Telegram Bot API.

Usage Example (Telegraf)

import { Telegraf } from "telegraf";

import { InlineKeyboardBuilder } from "telegram-inline-keyboard-builder"; 

const bot = new Telegraf(process.env.BOT_TOKEN); 

bot.start(ctx => {
 const keyboard = new InlineKeyboardBuilder({ buttonsPerRow: 2, autoWrapMaxChars: 24 }) 
.addCallbackButton("✅ OK", "OK_ACTION")
.addUrlButton("🌍 Website", "https://example.com") 
.newRow() 
.addCallbackButton("❌ Cancel", "CANCEL_ACTION") 
.build(); 
ctx.reply("Welcome 👋\nChoose an action:", keyboard); }); 

bot.launch(); 

Usage Example (node-telegram-bot-api)

import TelegramBot from "node-telegram-bot-api"; 

import { InlineKeyboardBuilder } from "telegram-inline-keyboard-builder"; 

const bot = new TelegramBot(TOKEN, { polling: true }); 
bot.onText(/\/start/, msg => { 
const keyboard = new InlineKeyboardBuilder() 
.addCallbackButton("OK", "OK") 
.addUrlButton("Site", "https://example.com") 
.build(); 

bot.sendMessage(msg.chat.id, "Hello", keyboard); }); 

💳 Payment Buttons

⚠️ Telegram limitation

[!WARNING] Payment buttons must only be used with:

  • sendInvoice
  • replyWithInvoice

They must be hidden in normal messages.

.addPayButton("Pay now"); 

Using a visible payment button outside invoices will cause Telegram API errors.

🧯 Common Errors

Telegram API error

Make sure the keyboard object is passed directly:

const keyboard = new InlineKeyboardBuilder(1)
.addCallbackButton("Setting","show_setting")
.build()
// telegraf
ctx.reply("Text", keyboard);

// node telegram bot api
bot.sendMessage(chatId, "Text", keyboard); 

// CORRECT ✅

// OR if you want to include it in the options 

const keyboard = new InlineKeyboardBuilder(1)
.addCallbackButton("Setting","show_setting")
.build()

// telegraf
ctx.reply("Text", {
reply_markup: keyboard.reply_makup, // inline keyboard
parse_mode: "HTML",
// ...
});

// node telegram bot api
bot.sendMessage(chatId, "Text", {
reply_markup: keyboard.reply_makup, // inline keyboard
parse_mode: "HTML",
// ...
); 

Migration to V2

  • V1: The inline keyboard builder used adapters for each new API, resulting in code that was unmaintainable in case of updates.

  • V2: Here we simply construct an object valid for all types of APIs without adapting it.

💜 Support This Project (Crypto)

This project is maintained in my free time.
If it helped you, consider supporting it with a crypto donation ❤️
It helps me maintain and improve the project.

You can send donations to the following addresses:

| Crypto | Address | |--------|---------| | USDT (TRC20) | 0x607c1430601989d43c9CD2eeD9E516663e0BdD1F | | USDC (Polygon/ETH) | 0x607c1430601989d43c9CD2eeD9E516663e0BdD1F | | Ethereum (ETH) | 0x607c1430601989d43c9CD2eeD9E516663e0BdD1F | | Bitcoin (BTC) | bc1qmysepz6eerz2mqyx5dd0yy87c3gk6hccwla5x2 | | Tron (TRX) | TE9RiTaDpx7DGZzCMw7qds51nzszKiyeR8 | | TON | UQA1NPW4GqgIVa9R6lebN_0v64Q-Sz_nHrmK9LCk-FfdjVOH |

🔹 Optional QR Codes for quick mobile donation

USDT (TRC20)
USDT TRC20 QR

USDC
USDC QR

Ethereum (ETH)
ETH QR

Bitcoin (BTC)
BTC QR

Tron (TRX)
TRX QR

TON
TON QR

✍️ Contribution

Contributions are welcome ❤️ Please open an issue before proposing major changes.