
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
node-telegram-keyboards
Advanced tools
Twilight.js telegram-keyboards is an asynchronous library that allows you to generate dynamic and static keyboards and allows you to save the finished keyboard template in json and return the keyboard back from the json templater

node-telegram-keyboards is an asynchronous library that allows you to generate dynamic and static keyboards and allows you to save the finished keyboard template in json and return the keyboard back from the json templater
Using npm:
$ npm i node-telegram-keyboards
import {KeyboardBuilder} from "node-telegram-keyboards";
import {KeyboardButtons} from "node-telegram-keyboards";
import {InlineKeyboardButtons} from "node-telegram-keyboards";
async function replyKeyboardStatic() {
const keyboard = await KeyboardBuilder.keyboard().static()
.buttons([
KeyboardButtons.text("example"),
KeyboardButtons.contact("example"),
KeyboardButtons.location("example"),
KeyboardButtons.poll("example", "quiz"),
KeyboardButtons.webApp("example", "https://example.site/")
])
.layout((data, template) => template.topToBottom())
.build();
}
async function replyKeyboardDynamic() {
const keyboard = await KeyboardBuilder.keyboard().dynamic()
.data([1, 2, 3, 4, 5])
.use(async (storage, data) => {
storage.counter = 0;
})
.map(async (element, storage, positionIndex) => {
if (positionIndex % 2 == 0) {
storage.counter = + positionIndex;
return KeyboardButtons.text(storage.counter);
}
storage.counter = + positionIndex;
return KeyboardButtons.text(element);
})
.layout((data, template) => template.topToBottom())
.build();
}
async function inlineKeyboardStatic() {
const inlineKeyboard = await KeyboardBuilder.inlineKeyboard().static()
.buttons([
InlineKeyboardButtons.url("example", "https://example.site/"),
InlineKeyboardButtons.callbackData("example", "exampleData"),
InlineKeyboardButtons.webApp("example", "https://example.site/"),
InlineKeyboardButtons.loginUrl("example", "https://example.site/"),
InlineKeyboardButtons.switchInlineQuery("example", "query"),
InlineKeyboardButtons.switchInlineQueryCurrentChat("example", "query"),
InlineKeyboardButtons.callbackGame("example", "callbackGame"),
InlineKeyboardButtons.pay("example")
])
.layout((data, template) => template.topToBottom())
.build();
}
async function inlineKeyboardDynamic() {
const inlineKeyboard = await KeyboardBuilder.inlineKeyboard().dynamic()
.data([1, 2, 3, 4, 5, 6, 7, 8])
.use(async (storage, data) => {
storage.counter = 0;
})
.map(async (element, storage, positionIndex) => {
if (positionIndex % 2 == 0) {
storage.counter = + positionIndex;
return InlineKeyboardButtons.callbackData(element, storage.counter);
}
storage.counter = + positionIndex;
return InlineKeyboardButtons.callbackData(element, positionIndex);
})
.layout((data, template) => template.topToBottom())
.build();
}
| Method | Description |
|---|---|
| static keyboard() | Returns a static or dynamic ReplyKeyboard keyboard selector |
| static inlineKeyboard() | Returns a static or dynamic InlineKeyboard keyboard selector |
| static assign(type, keyboards) | Connects all keyboards into one |
| static save(keyboard) | Converts ReplyKeyboard or InlineKeyboard objects to JSON object suitable for telegram |
| static async saveToJSON(keyboard, filename) | Converts and saves ReplyKeyboard or InlineKeyboard objects to a JSON file that can be used as ready-made keyboard template |
| static template(json) | Based on the keyboard template, builds a new ReplyKeyboard or InlineKeyboard object |
| static async templateFromJSON(pathToJSON) | Reads a JSON file and creates a new ReplyKeyboard or InlineKeyboard object based on the keyboard template |
Common methods that both keyboards have.
In static implementation:
| Method | Parameters | Description |
|---|---|---|
| buttons(buttons) | buttons: array, array of KeyboardButtons orInlineKeyboardButtonss | An array of buttons to which you need to pass KeyboardButtons orInlineKeyboardButtonss objects, depending on which keyboard you are building Keyboard or InlineKeyboard |
In dynamic implementation:
| Method | Parameters | Description |
|---|---|---|
| use(callbackfn) | async/sync () => array | It takes as input a callback function that is called once and, depending on what conditions it processes, should return an array of KeyboardButtons or InlineKeyboardButtons |
| data(array, start, end) | array: array, start: number, end: number | It takes an array of data as input, which it then converts to KeyboardButtons orInlineKeyboardButtons, the start and end parameters are needed to indicate from which position to take elements for buttons, by default the entire array is taken, they can be omitted |
| storage(callbackfn) | async/sync (storage: object, data: array) => storage | It accepts a callback function as input, which initializes the store, which is passed to the callback function in the map method, in this store you can pass data between KeyboardButtons orInlineKeyboardButtons |
| map(callbackfn) | async/sync (element: the type is equal to the type of the element retrieved from the data , storage: object, positionIndex: number) => KeyboardButtons orInlineKeyboardButtons | It accepts a callback function as input, which is called for each element from the data array and converts it to KeyboardButtons orInlineKeyboardButtons |
For all implementations:
| Method | Parameters | Description |
|---|---|---|
| layout(callbackfn) | async/sync (data: array, template: TemplateLayout) => array | It takes a callback function as input, which should return an array with markup, the markup looks like this, you specify how many buttons will be in a row and how many lines there will be. For example: [5] - 5 buttons will be placed in a row, [1, 1, 1, 1, 1] - there will be 5 buttons in 5 lines, [2, 3] - buttons will be located on two lines, on the first 2, on the second 3 respectively. *In the markup, you must specify the exact number of buttons or specify the markup calculation algorithm in the callback function, otherwise there will be an error |
| async build() | - | Returns a finished keyboard that can be sent to Telegram |
###InlineKeyboardButtonss
Node.js
FAQs
Twilight.js telegram-keyboards is an asynchronous library that allows you to generate dynamic and static keyboards and allows you to save the finished keyboard template in json and return the keyboard back from the json templater
The npm package node-telegram-keyboards receives a total of 5 weekly downloads. As such, node-telegram-keyboards popularity was classified as not popular.
We found that node-telegram-keyboards demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.