@gramio/keyboards
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

@gramio/keyboards

Framework-agnostic Telegram bot keyboard (and inline query result) builder with many cool features!

Installation (if you don't use GramIO)

npm i @gramio/keyboards

See more in Documentation

Simple Keyboard

import { Keyboard } from "@gramio/keyboards";

const keyboard = new Keyboard()
    .text("first row")
    .row()
    .text("second row")
    .build(); // NOTE: In GramIO, you don't have to use the ".build" method

Usage with Frameworks

Send via GramIO

import { Bot, Keyboard } from "gramio"; // import from GramIO package!!

const bot = new Bot(process.env.TOKEN);

const data = ["Apple", "Realme", "Tesla", "Xiaomi"];

bot.on("message", (ctx) => {
    return ctx.reply("test", {
        reply_markup: new Keyboard()
            .columns(1)
            .text("simple keyboard")
            .add(...data.map((x) => Keyboard.text(x)))
            .filter(({ button }) => button.text !== "Tesla"),
    });
});

Send via Grammy

import { Keyboard } from "@gramio/keyboards";
import { Bot } from "grammy";

const bot = new Bot(process.env.TOKEN);

const data = ["Apple", "Realme", "Tesla", "Xiaomi"];

bot.on("message", (ctx) => {
    return ctx.reply("test", {
        reply_markup: new Keyboard()
            .columns(1)
            .text("simple keyboard")
            .add(...data.map((x) => Keyboard.text(x)))
            .filter(({ button }) => button.text !== "Tesla")
            .build(),
    });
});

bot.start();

Result

{
    "keyboard": [
        [
            {
                "text": "simple keyboard"
            }
        ],
        [
            {
                "text": "Apple"
            }
        ],
        [
            {
                "text": "Realme"
            }
        ],
        [
            {
                "text": "Xiaomi"
            }
        ]
    ],
    "one_time_keyboard": false,
    "is_persistent": false,
    "selective": false,
    "resize_keyboard": true
}

image

Package Sidebar

Install

npm i @gramio/keyboards

Weekly Downloads

10

Version

0.3.0

License

none

Unpacked Size

75.9 kB

Total Files

22

Last publish

Collaborators

  • skravets