New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@gramio/keyboards

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gramio/keyboards - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

dist/base-keyboard-constructor.d.ts

3

dist/index.d.ts
import "reflect-metadata";
export * from "./keyboard";
export * from "./inline-keyboard";
export * from "./remove-keyboard";
export * from "./force-reply";
export * from "./base-keyboard-constructor";

@@ -20,1 +20,4 @@ "use strict";

__exportStar(require("./inline-keyboard"), exports);
__exportStar(require("./remove-keyboard"), exports);
__exportStar(require("./force-reply"), exports);
__exportStar(require("./base-keyboard-constructor"), exports);

@@ -1,2 +0,3 @@

import { TelegramCallbackGame, TelegramInlineKeyboardMarkup, TelegramLoginUrl, TelegramSwitchInlineQueryChosenChat } from "@gramio/types";
import { TelegramCallbackGame, TelegramInlineKeyboardButton, TelegramInlineKeyboardMarkup, TelegramLoginUrl, TelegramSwitchInlineQueryChosenChat } from "@gramio/types";
import { BaseKeyboardConstructor } from "./base-keyboard-constructor";
/**

@@ -7,10 +8,12 @@ * **InlineKeyboardMarkup** builder

*/
export declare class InlineKeyboard {
private rows;
private currentRow;
export declare class InlineKeyboard extends BaseKeyboardConstructor<TelegramInlineKeyboardButton> {
/**
* Text button with data to be sent in a [callback query](https://core.telegram.org/bots/api/#callbackquery) to the bot when button is pressed, 1-64 bytes
*/
text(text: string, payload: Record<string, unknown>): this;
text(text: string, payload?: string | Record<string, unknown>): this;
/**
* Text button with data to be sent in a [callback query](https://core.telegram.org/bots/api/#callbackquery) to the bot when button is pressed, 1-64 bytes
*/
static text(text: string, payload?: string | Record<string, unknown>): TelegramInlineKeyboardButton;
/**
* HTTP or tg:// URL to be opened when the button is pressed. Links `tg://user?id=<user_id>` can be used to mention a user by their identifier without using a username, if this is allowed by their privacy settings.

@@ -20,2 +23,6 @@ */

/**
* HTTP or tg:// URL to be opened when the button is pressed. Links `tg://user?id=<user_id>` can be used to mention a user by their identifier without using a username, if this is allowed by their privacy settings.
*/
static url(text: string, url: string): TelegramInlineKeyboardButton;
/**
* Description of the [Web App](https://core.telegram.org/bots/webapps) that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method [answerWebAppQuery](https://core.telegram.org/bots/api/#answerwebappquery). Available only in private chats between a user and the bot.

@@ -25,6 +32,14 @@ */

/**
* Description of the [Web App](https://core.telegram.org/bots/webapps) that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method [answerWebAppQuery](https://core.telegram.org/bots/api/#answerwebappquery). Available only in private chats between a user and the bot.
*/
static webApp(text: string, url: string): TelegramInlineKeyboardButton;
/**
* An HTTPS URL used to automatically authorize the user. Can be used as a replacement for the [Telegram Login Widget](https://core.telegram.org/widgets/login).
*/
login(text: string, url: string | TelegramLoginUrl): void;
login(text: string, url: string | TelegramLoginUrl): this;
/**
* An HTTPS URL used to automatically authorize the user. Can be used as a replacement for the [Telegram Login Widget](https://core.telegram.org/widgets/login).
*/
static login(text: string, url: string | TelegramLoginUrl): TelegramInlineKeyboardButton;
/**
* Send a [Pay button](https://core.telegram.org/bots/api/#payments).

@@ -36,2 +51,8 @@ *

/**
* Send a [Pay button](https://core.telegram.org/bots/api/#payments).
*
* **NOTE:** This type of button **must** always be the first button in the first row and can only be used in invoice messages.
*/
static pay(text: string): TelegramInlineKeyboardButton;
/**
* If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field.

@@ -43,2 +64,8 @@ *

/**
* If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field.
*
* By default empty, in which case just the bot's username will be inserted.
*/
static switchToChat(text: string, query?: string): TelegramInlineKeyboardButton;
/**
* Pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field

@@ -48,2 +75,6 @@ */

/**
* Pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field
*/
static switchToChosenChat(text: string, query?: string | TelegramSwitchInlineQueryChosenChat): TelegramInlineKeyboardButton;
/**
* Pressing the button will insert the bot's username and the specified inline query in the current chat's input field. May be empty, in which case only the bot's username will be inserted.

@@ -55,2 +86,8 @@ *

/**
* Pressing the button will insert the bot's username and the specified inline query in the current chat's input field. May be empty, in which case only the bot's username will be inserted.
*
* This offers a quick way for the user to open your bot in inline mode in the same chat - good for selecting something from multiple options.
*/
static switchToCurrentChat(text: string, query?: string): TelegramInlineKeyboardButton;
/**
* **NOTE:** TelegramCallbackGame is empty and keyboard is not working yet

@@ -63,4 +100,11 @@ *

game(text: string, gameOptions?: TelegramCallbackGame): this;
private addButton;
/**
* **NOTE:** TelegramCallbackGame is empty and keyboard is not working yet
*
* Description of the game that will be launched when the user presses the button.
*
* **NOTE:** This type of button **must** always be the first button in the first row.
*/
static game(text: string, gameOptions?: TelegramCallbackGame): TelegramInlineKeyboardButton;
/**
* Return {@link TelegramInlineKeyboardMarkup} as JSON

@@ -67,0 +111,0 @@ */

123

dist/inline-keyboard.js

@@ -8,5 +8,7 @@ "use strict";

};
var InlineKeyboard_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InlineKeyboard = void 0;
const inspectable_1 = require("inspectable");
const base_keyboard_constructor_1 = require("./base-keyboard-constructor");
/**

@@ -17,5 +19,3 @@ * **InlineKeyboardMarkup** builder

*/
let InlineKeyboard = class InlineKeyboard {
rows = [];
currentRow = [];
let InlineKeyboard = InlineKeyboard_1 = class InlineKeyboard extends base_keyboard_constructor_1.BaseKeyboardConstructor {
/**

@@ -25,7 +25,12 @@ * Text button with data to be sent in a [callback query](https://core.telegram.org/bots/api/#callbackquery) to the bot when button is pressed, 1-64 bytes

text(text, payload) {
this.addButton({
return this.add(InlineKeyboard_1.text(text, payload));
}
/**
* Text button with data to be sent in a [callback query](https://core.telegram.org/bots/api/#callbackquery) to the bot when button is pressed, 1-64 bytes
*/
static text(text, payload) {
return {
text,
callback_data: typeof payload === "object" ? JSON.stringify(payload) : payload,
});
return this;
};
}

@@ -36,7 +41,12 @@ /**

url(text, url) {
this.addButton({
return this.add(InlineKeyboard_1.url(text, url));
}
/**
* HTTP or tg:// URL to be opened when the button is pressed. Links `tg://user?id=<user_id>` can be used to mention a user by their identifier without using a username, if this is allowed by their privacy settings.
*/
static url(text, url) {
return {
text,
url,
});
return this;
};
}

@@ -47,7 +57,12 @@ /**

webApp(text, url) {
this.addButton({
return this.add(InlineKeyboard_1.webApp(text, url));
}
/**
* Description of the [Web App](https://core.telegram.org/bots/webapps) that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method [answerWebAppQuery](https://core.telegram.org/bots/api/#answerwebappquery). Available only in private chats between a user and the bot.
*/
static webApp(text, url) {
return {
text,
web_app: { url },
});
return this;
};
}

@@ -58,6 +73,12 @@ /**

login(text, url) {
this.addButton({
return this.add(InlineKeyboard_1.login(text, url));
}
/**
* An HTTPS URL used to automatically authorize the user. Can be used as a replacement for the [Telegram Login Widget](https://core.telegram.org/widgets/login).
*/
static login(text, url) {
return {
text,
login_url: typeof url === "string" ? { url } : url,
});
};
}

@@ -70,7 +91,16 @@ /**

pay(text) {
this.addButton({
if (this.rows.length || this.currentRow.length)
throw new Error("This type of button **must** always be the first button in the first row and can only be used in invoice messages.");
return this.add(InlineKeyboard_1.pay(text));
}
/**
* Send a [Pay button](https://core.telegram.org/bots/api/#payments).
*
* **NOTE:** This type of button **must** always be the first button in the first row and can only be used in invoice messages.
*/
static pay(text) {
return {
text,
pay: true,
});
return this;
};
}

@@ -83,7 +113,14 @@ /**

switchToChat(text, query = "") {
this.addButton({
return this.add(InlineKeyboard_1.switchToChat(text, query));
}
/**
* If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field.
*
* By default empty, in which case just the bot's username will be inserted.
*/
static switchToChat(text, query = "") {
return {
text,
switch_inline_query: query,
});
return this;
};
}

@@ -94,7 +131,12 @@ /**

switchToChosenChat(text, query = "") {
this.addButton({
return this.add(InlineKeyboard_1.switchToChosenChat(text, query));
}
/**
* Pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field
*/
static switchToChosenChat(text, query = "") {
return {
text,
switch_inline_query_chosen_chat: typeof query === "string" ? { query } : query,
});
return this;
};
}

@@ -107,6 +149,13 @@ /**

switchToCurrentChat(text, query = "") {
this.addButton({ text, switch_inline_query_current_chat: query });
return this;
return this.add(InlineKeyboard_1.switchToCurrentChat(text, query));
}
/**
* Pressing the button will insert the bot's username and the specified inline query in the current chat's input field. May be empty, in which case only the bot's username will be inserted.
*
* This offers a quick way for the user to open your bot in inline mode in the same chat - good for selecting something from multiple options.
*/
static switchToCurrentChat(text, query = "") {
return { text, switch_inline_query_current_chat: query };
}
/**
* **NOTE:** TelegramCallbackGame is empty and keyboard is not working yet

@@ -119,11 +168,19 @@ *

game(text, gameOptions = {}) {
this.addButton({
if (this.rows.length || this.currentRow.length)
throw new Error("This type of button **must** always be the first button in the first row.");
return this.add(InlineKeyboard_1.game(text, gameOptions));
}
/**
* **NOTE:** TelegramCallbackGame is empty and keyboard is not working yet
*
* Description of the game that will be launched when the user presses the button.
*
* **NOTE:** This type of button **must** always be the first button in the first row.
*/
static game(text, gameOptions = {}) {
return {
text,
callback_game: gameOptions,
});
return this;
};
}
addButton(button) {
this.currentRow.push(button);
}
/**

@@ -134,3 +191,3 @@ * Return {@link TelegramInlineKeyboardMarkup} as JSON

return {
inline_keyboard: [...this.rows, this.currentRow],
inline_keyboard: this.keyboard,
};

@@ -140,3 +197,3 @@ }

exports.InlineKeyboard = InlineKeyboard;
exports.InlineKeyboard = InlineKeyboard = __decorate([
exports.InlineKeyboard = InlineKeyboard = InlineKeyboard_1 = __decorate([
(0, inspectable_1.Inspectable)({

@@ -143,0 +200,0 @@ serialize: (keyboard) => keyboard.toJSON(),

@@ -1,3 +0,3 @@

import type { TelegramKeyboardButtonPollType, TelegramKeyboardButtonRequestChat, TelegramKeyboardButtonRequestUsers, TelegramReplyKeyboardMarkup } from "@gramio/types";
import "reflect-metadata";
import type { TelegramKeyboardButton, TelegramKeyboardButtonPollType, TelegramKeyboardButtonRequestChat, TelegramKeyboardButtonRequestUsers, TelegramReplyKeyboardMarkup } from "@gramio/types";
import { BaseKeyboardConstructor } from "./base-keyboard-constructor";
/**

@@ -8,5 +8,3 @@ * **ReplyKeyboardMarkup** builder

*/
export declare class Keyboard {
private rows;
private currentRow;
export declare class Keyboard extends BaseKeyboardConstructor<TelegramKeyboardButton> {
options: {

@@ -24,10 +22,26 @@ isOneTime: boolean;

/**
* Text of the button. It will be sent as a message when the button is pressed
*/
static text(text: string): TelegramKeyboardButton;
/**
* If specified, pressing the button will open a list of suitable users. Identifiers of selected users will be sent to the bot in a “users\_shared” service message. Available in private chats only.
*/
requestUsers(text: string, requestId: number, options: Omit<TelegramKeyboardButtonRequestUsers, "request_id">): this;
requestUsers(text: string, requestId: number, options?: Omit<TelegramKeyboardButtonRequestUsers, "request_id">): this;
/**
* If specified, pressing the button will open a list of suitable users. Identifiers of selected users will be sent to the bot in a “users\_shared” service message. Available in private chats only.
*/
static requestUsers(text: string, requestId: number, options?: Omit<TelegramKeyboardButtonRequestUsers, "request_id">): TelegramKeyboardButton;
/**
* If specified, pressing the button will open a list of suitable chats. Tapping on a chat will send its identifier to the bot in a “chat\_shared” service message. Available in private chats only.
*/
requestChat(text: string, requestId: number, options?: Omit<TelegramKeyboardButtonRequestChat, "request_id">): this;
requestChat(text: string, requestId: number, options?: Omit<TelegramKeyboardButtonRequestChat, "request_id" | "chat_is_channel"> & {
chat_is_channel?: boolean;
}): this;
/**
* If specified, pressing the button will open a list of suitable chats. Tapping on a chat will send its identifier to the bot in a “chat\_shared” service message. Available in private chats only.
*/
static requestChat(text: string, requestId: number, options?: Omit<TelegramKeyboardButtonRequestChat, "request_id" | "chat_is_channel"> & {
chat_is_channel?: boolean;
}): TelegramKeyboardButton;
/**
* If *True*, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only.

@@ -37,2 +51,6 @@ */

/**
* If *True*, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only.
*/
static requestContact(text: string): TelegramKeyboardButton;
/**
* If *True*, the user's current location will be sent when the button is pressed. Available in private chats only.

@@ -42,6 +60,18 @@ */

/**
* If *True*, the user's current location will be sent when the button is pressed. Available in private chats only.
*/
static requestLocation(text: string): TelegramKeyboardButton;
/**
* If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only.
*
* If *quiz* is passed, the user will be allowed to create only polls in the quiz mode. If *regular* is passed, only regular polls will be allowed. Otherwise, the user will be allowed to create a poll of any type.
*/
requestPoll(text: string, type?: TelegramKeyboardButtonPollType["type"]): this;
/**
* If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only.
*
* If *quiz* is passed, the user will be allowed to create only polls in the quiz mode. If *regular* is passed, only regular polls will be allowed. Otherwise, the user will be allowed to create a poll of any type.
*/
static requestPoll(text: string, type?: TelegramKeyboardButtonPollType["type"]): TelegramKeyboardButton;
/**
* If specified, the described [Web App](https://core.telegram.org/bots/webapps) will be launched when the button is pressed. The Web App will be able to send a “web\_app\_data” service message. Available in private chats only.

@@ -51,2 +81,6 @@ */

/**
* If specified, the described [Web App](https://core.telegram.org/bots/webapps) will be launched when the button is pressed. The Web App will be able to send a “web\_app\_data” service message. Available in private chats only.
*/
static webApp(text: string, url: string): TelegramKeyboardButton;
/**
* Requests clients to hide the keyboard as soon as it's been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat - the user can press a special button in the input field to see the custom keyboard again. Defaults to *false*.

@@ -56,3 +90,3 @@ */

/**
* *Optional*. Requests clients to always show the keyboard when the regular keyboard is hidden. Defaults to *false*, in which case the custom keyboard can be hidden and opened with a keyboard icon.
* Requests clients to always show the keyboard when the regular keyboard is hidden. Defaults to *false*, in which case the custom keyboard can be hidden and opened with a keyboard icon.
*/

@@ -65,2 +99,4 @@ persistent(isEnabled?: boolean): this;

/**
* !**Note** Keyboard is resized by default! For disable it you can use `.resized(false)`
*
* Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to *false*, in which case the custom keyboard is always of the same height as the app's standard keyboard.

@@ -75,3 +111,2 @@ */

selective(isEnabled?: boolean): this;
private addButton;
/**

@@ -78,0 +113,0 @@ * Return {@link TelegramReplyKeyboardMarkup} as JSON

@@ -8,6 +8,7 @@ "use strict";

};
var Keyboard_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Keyboard = void 0;
const inspectable_1 = require("inspectable");
require("reflect-metadata");
const base_keyboard_constructor_1 = require("./base-keyboard-constructor");
/**

@@ -18,9 +19,7 @@ * **ReplyKeyboardMarkup** builder

*/
let Keyboard = class Keyboard {
rows = [];
currentRow = [];
let Keyboard = Keyboard_1 = class Keyboard extends base_keyboard_constructor_1.BaseKeyboardConstructor {
options = {
isOneTime: false,
isPersistent: false,
isResized: false,
isResized: true,
isSelective: false,

@@ -33,10 +32,21 @@ placeholder: undefined,

text(text) {
this.addButton({ text });
return this;
return this.add(Keyboard_1.text(text));
}
/**
* Text of the button. It will be sent as a message when the button is pressed
*/
static text(text) {
return { text };
}
/**
* If specified, pressing the button will open a list of suitable users. Identifiers of selected users will be sent to the bot in a “users\_shared” service message. Available in private chats only.
*/
requestUsers(text, requestId, options) {
this.addButton({
requestUsers(text, requestId, options = {}) {
return this.add(Keyboard_1.requestUsers(text, requestId, options));
}
/**
* If specified, pressing the button will open a list of suitable users. Identifiers of selected users will be sent to the bot in a “users\_shared” service message. Available in private chats only.
*/
static requestUsers(text, requestId, options = {}) {
return {
text,

@@ -47,4 +57,3 @@ request_users: {

},
});
return this;
};
}

@@ -55,3 +64,9 @@ /**

requestChat(text, requestId, options) {
this.addButton({
return this.add(Keyboard_1.requestChat(text, requestId, options));
}
/**
* If specified, pressing the button will open a list of suitable chats. Tapping on a chat will send its identifier to the bot in a “chat\_shared” service message. Available in private chats only.
*/
static requestChat(text, requestId, options) {
return {
text,

@@ -64,4 +79,3 @@ request_chat: {

},
});
return this;
};
}

@@ -72,7 +86,12 @@ /**

requestContact(text) {
this.addButton({
return this.add(Keyboard_1.requestContact(text));
}
/**
* If *True*, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only.
*/
static requestContact(text) {
return {
text,
request_contact: true,
});
return this;
};
}

@@ -83,13 +102,28 @@ /**

requestLocation(text) {
this.addButton({
return this.add(Keyboard_1.requestLocation(text));
}
/**
* If *True*, the user's current location will be sent when the button is pressed. Available in private chats only.
*/
static requestLocation(text) {
return {
text,
request_location: true,
});
return this;
};
}
/**
* If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only.
*
* If *quiz* is passed, the user will be allowed to create only polls in the quiz mode. If *regular* is passed, only regular polls will be allowed. Otherwise, the user will be allowed to create a poll of any type.
*/
requestPoll(text, type) {
this.addButton({
return this.add(Keyboard_1.requestPoll(text, type));
}
/**
* If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only.
*
* If *quiz* is passed, the user will be allowed to create only polls in the quiz mode. If *regular* is passed, only regular polls will be allowed. Otherwise, the user will be allowed to create a poll of any type.
*/
static requestPoll(text, type) {
return {
text,

@@ -99,4 +133,3 @@ request_poll: {

},
});
return this;
};
}

@@ -107,3 +140,9 @@ /**

webApp(text, url) {
this.addButton({
return this.add(Keyboard_1.webApp(text, url));
}
/**
* If specified, the described [Web App](https://core.telegram.org/bots/webapps) will be launched when the button is pressed. The Web App will be able to send a “web\_app\_data” service message. Available in private chats only.
*/
static webApp(text, url) {
return {
text,

@@ -113,4 +152,3 @@ web_app: {

},
});
return this;
};
}

@@ -125,3 +163,3 @@ /**

/**
* *Optional*. Requests clients to always show the keyboard when the regular keyboard is hidden. Defaults to *false*, in which case the custom keyboard can be hidden and opened with a keyboard icon.
* Requests clients to always show the keyboard when the regular keyboard is hidden. Defaults to *false*, in which case the custom keyboard can be hidden and opened with a keyboard icon.
*/

@@ -140,2 +178,4 @@ persistent(isEnabled = true) {

/**
* !**Note** Keyboard is resized by default! For disable it you can use `.resized(false)`
*
* Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to *false*, in which case the custom keyboard is always of the same height as the app's standard keyboard.

@@ -156,5 +196,2 @@ */

}
addButton(button) {
this.currentRow.push(button);
}
/**

@@ -165,6 +202,7 @@ * Return {@link TelegramReplyKeyboardMarkup} as JSON

return {
keyboard: [...this.rows, this.currentRow],
keyboard: this.keyboard,
one_time_keyboard: this.options.isOneTime,
is_persistent: this.options.isPersistent,
input_field_placeholder: this.options.placeholder,
selective: this.options.isSelective,
resize_keyboard: this.options.isResized,

@@ -175,3 +213,3 @@ };

exports.Keyboard = Keyboard;
exports.Keyboard = Keyboard = __decorate([
exports.Keyboard = Keyboard = Keyboard_1 = __decorate([
(0, inspectable_1.Inspectable)({

@@ -178,0 +216,0 @@ serialize: (keyboard) => keyboard.toJSON(),

@@ -16,3 +16,3 @@ import { TelegramReplyKeyboardRemove } from "@gramio/types";

*/
selective(isEnabled?: boolean): void;
selective(isEnabled?: boolean): this;
/**

@@ -19,0 +19,0 @@ * Return {@link TelegramReplyKeyboardRemove} as JSON

@@ -27,2 +27,3 @@ "use strict";

this.options.isSelective = isEnabled;
return this;
}

@@ -29,0 +30,0 @@ /**

{
"name": "@gramio/keyboards",
"version": "0.0.5",
"version": "0.0.6",
"description": "Framework-agnostic Telegram bot keyboard builder with many cool features!",
"main": "dist/index.js",
"homepage": "https://github.com/gramiojs/types",
"readme": "https://github.com/gramiojs/types",
"scripts": {

@@ -15,11 +18,13 @@ "prepublishOnly": "tsc"

"keyboard-builder",
"telegram-bot-api"
"telegram-bot-api",
"grammy"
],
"devDependencies": {
"@gramio/types": "^7.0.7",
"@types/bun": "latest",
"inspectable": "^2.1.0"
"@gramio/types": "^7.0.9",
"@types/bun": "^1.0.4",
"inspectable": "^2.1.0",
"reflect-metadata": "^0.2.1"
},
"peerDependencies": {
"@gramio/types": "^7.0.7",
"@gramio/types": "^7.0.9",
"inspectable": "^2.1.0",

@@ -26,0 +31,0 @@ "typescript": "^5.3.3",

# @gramio/keyboards
WIP
Framework-agnostic Telegram bot keyboard builder with many cool features!
### Installation
```bash
npm i @gramio/keyboards
```
### See more in Documentation (Documentation is not deployed yet)
## Usage ([with frameworks](#usage-with-frameworks))
### Simple Keyboard
```ts
import { Keyboard } from "@gramio/keyboards";
const keyboard = new Keyboard()
.text("first row")
.row()
.text("second row")
.toJSON(); // NOTE: In gramio, you don't have to use the ".toJSON" method
```
## Usage with Frameworks
### Send via GramIO
GramIO is not ready yet...
### Send via [Grammy](https://grammy.dev/)
```ts
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")
.toJSON(),
});
});
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](https://github.com/gramiojs/keyboards/assets/57632712/e65e2b0a-40f0-43ae-9887-04360e6dbeab)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc