Skip to content

Overview

@gramio/keyboards is built-in GramIO plugin. You can also use it outside of this framework because it is framework-agnostic.

See also API Reference.

Installation (not required for GramIO users)

bash
npm install @gramio/keyboards
bash
yarn add @gramio/keyboards
bash
pnpm add @gramio/keyboards
bash
bun install @gramio/keyboards

Usage

ts
import { 
Keyboard
} from "gramio";
const
keyboard
= new
Keyboard
().
text
("first row").
row
().
text
("second row");
ts
import { 
Keyboard
} from "@gramio/keyboards";
const
keyboard
= new
Keyboard
()
.
text
("first row")
.
row
()
.
text
("second row")
.
build
();

Usage with Frameworks

Send via GramIO

ts
import { 
Bot
,
Keyboard
} from "gramio";
const
data
= ["Apple", "Realme", "Tesla", "Xiaomi"];
const
bot
= new
Bot
(
process
.
env
.
TOKEN
!)
.
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"),
}); }) .
onStart
(
console
.
log
);
bot
.
start
();

Send via Grammy

ts
import { 
Keyboard
} from "@gramio/keyboards";
import {
Bot
} from "grammy";
const
data
= ["Apple", "Realme", "Tesla", "Xiaomi"];
const
bot
= new
Bot
(
process
.
env
.
TOKEN
!);
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

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

image