GramIO API Reference / @gramio/keyboards/dist / BaseKeyboardConstructor
Class: BaseKeyboardConstructor<T>
Defined in: keyboards/index.d.ts:44
Base-class for construct keyboard with useful helpers
Extended by
Type Parameters
| Type Parameter |
|---|
T |
Constructors
Constructor
new BaseKeyboardConstructor<
T>(featureFlags?):BaseKeyboardConstructor<T>
Defined in: keyboards/index.d.ts:48
Parameters
| Parameter | Type |
|---|---|
featureFlags? | KeyboardFeatureFlags |
Returns
BaseKeyboardConstructor<T>
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
currentRow | protected | T[] | keyboards/index.d.ts:46 |
featureFlags | protected | KeyboardFeatureFlags | keyboards/index.d.ts:47 |
rows | protected | T[][] | keyboards/index.d.ts:45 |
Accessors
keyboard
Get Signature
get
protectedkeyboard():T[][]
Defined in: keyboards/index.d.ts:52
Returns
T[][]
Methods
add()
add(...
buttons):this
Defined in: keyboards/index.d.ts:127
Allows you to add multiple buttons in raw format.
Parameters
| Parameter | Type |
|---|---|
...buttons | T[] |
Returns
this
Example
const labels = ["some", "buttons"];
new InlineKeyboard()
.add({ text: "raw button", callback_data: "payload" })
.add(InlineKeyboard.text("raw button by InlineKeyboard.text", "payload"))
.add(...labels.map((x) => InlineKeyboard.text(x, `${x}payload`)));addIf()
addIf(
condition, ...buttons):this
Defined in: keyboards/index.d.ts:147
Allows you to dynamically substitute buttons depending on something
Parameters
| Parameter | Type |
|---|---|
condition | boolean | (options) => boolean |
...buttons | T[] |
Returns
this
Example
const labels = ["some", "buttons"];
const isAdmin = true;
new InlineKeyboard()
.addIf(1 === 2, { text: "raw button", callback_data: "payload" })
.addIf(
isAdmin,
InlineKeyboard.text("raw button by InlineKeyboard.text", "payload")
)
.addIf(
({ index, rowIndex }) => rowIndex === index,
...labels.map((x) => InlineKeyboard.text(x, `${x}payload`))
);columns()
columns(
length?):this
Defined in: keyboards/index.d.ts:75
Allows you to limit the number of columns in the keyboard.
Parameters
| Parameter | Type |
|---|---|
length? | number |
Returns
this
Example
new InlineKeyboard()
.columns(1)
.text("first row", "payload")
.text("second row", "payload");
.text("third row", "payload");filter()
filter(
fn?):this
Defined in: keyboards/index.d.ts:99
A handler that helps filter keyboard buttons
Parameters
| Parameter | Type |
|---|---|
fn? | ButtonsIterator<T> |
Returns
this
Example
new InlineKeyboard()
.filter(({ button }) => button.callback_data !== "hidden")
.text("button", "pass")
.text("button", "hidden")
.text("button", "pass");matrix()
matrix(
rows,columns,fn):this
Defined in: keyboards/index.d.ts:167
Allows you to create a button matrix.
Parameters
| Parameter | Type |
|---|---|
rows | number |
columns | number |
fn | CreateButtonIterator<T> |
Returns
this
Example
import { randomInt } from "node:crypto";
const bomb = [randomInt(0, 9), randomInt(0, 9)] as const;
new InlineKeyboard().matrix(10, 10, ({ rowIndex, index }) =>
InlineKeyboard.text(
rowIndex === bomb[0] && index === bomb[1] ? "💣" : "ㅤ",
"payload"
)
);pattern()
pattern(
pattern?):this
Defined in: keyboards/index.d.ts:114
An array with the number of columns per row. Allows you to set a "template"
Parameters
| Parameter | Type |
|---|---|
pattern? | number[] |
Returns
this
Example
new InlineKeyboard()
.pattern([1, 3, 2])
.text("1", "payload")
.text("2", "payload")
.text("2", "payload")
.text("2", "payload")
.text("3", "payload")
.text("3", "payload");resetHelpers()
resetHelpers():
this
Defined in: keyboards/index.d.ts:168
Returns
this
row()
row():
this
Defined in: keyboards/index.d.ts:63
Adds a line break. Call this method to make sure that the next added buttons will be on a new row.
Returns
this
Example
new InlineKeyboard()
.text("first row", "payload")
.row()
.text("second row", "payload");wrap()
wrap(
fn?):this
Defined in: keyboards/index.d.ts:87
A custom handler that controls row wrapping.
Parameters
| Parameter | Type |
|---|---|
fn? | ButtonsIterator<T> |
Returns
this
Example
new InlineKeyboard()
.wrap(({ button }) => button.callback_data === "2")
.text("first row", "1")
.text("first row", "1");
.text("second row", "2");