@gramio/keyboards
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -1,3 +0,8 @@ | ||
import { TelegramCallbackGame, TelegramInlineKeyboardButton, TelegramLoginUrl, TelegramSwitchInlineQueryChosenChat } from "@gramio/types"; | ||
import { TelegramCallbackGame, TelegramInlineKeyboardButton, TelegramInlineKeyboardMarkup, TelegramLoginUrl, TelegramSwitchInlineQueryChosenChat } from "@gramio/types"; | ||
import { BaseKeyboardConstructor } from "./base-keyboard-constructor"; | ||
interface TelegramInlineKeyboardMarkupFix { | ||
inline_keyboard: (TelegramInlineKeyboardButton & { | ||
pay: boolean; | ||
})[][]; | ||
} | ||
/** | ||
@@ -163,9 +168,25 @@ * **InlineKeyboardMarkup** builder | ||
/** | ||
* Allows you to combine keyboards. Only keyboards are combined. You need to call the `.row()` method to line-break after combine. | ||
* | ||
* @example | ||
* ```ts | ||
* new InlineKeyboard() | ||
* .combine(new InlineKeyboard().text("some", "payload")) | ||
* .row() | ||
* .combine( | ||
* new InlineKeyboard() | ||
* .text("test", "payload") | ||
* .row() | ||
* .text("second row???", "payload"), | ||
* ) | ||
* ``` | ||
*/ | ||
combine(keyboard: TelegramInlineKeyboardButton[][] | TelegramInlineKeyboardMarkup | { | ||
toJSON: () => TelegramInlineKeyboardMarkup; | ||
}): this; | ||
/** | ||
* Return {@link TelegramInlineKeyboardMarkup} as JSON | ||
*/ | ||
toJSON(): { | ||
inline_keyboard: (TelegramInlineKeyboardButton & { | ||
pay: boolean; | ||
})[][]; | ||
}; | ||
toJSON(): TelegramInlineKeyboardMarkupFix; | ||
} | ||
export {}; |
@@ -237,2 +237,26 @@ "use strict"; | ||
/** | ||
* Allows you to combine keyboards. Only keyboards are combined. You need to call the `.row()` method to line-break after combine. | ||
* | ||
* @example | ||
* ```ts | ||
* new InlineKeyboard() | ||
* .combine(new InlineKeyboard().text("some", "payload")) | ||
* .row() | ||
* .combine( | ||
* new InlineKeyboard() | ||
* .text("test", "payload") | ||
* .row() | ||
* .text("second row???", "payload"), | ||
* ) | ||
* ``` | ||
*/ | ||
combine(keyboard) { | ||
const json = "toJSON" in keyboard ? keyboard.toJSON() : keyboard; | ||
const buttons = Array.isArray(json) ? json : json.inline_keyboard; | ||
for (const row of buttons) { | ||
this.row().add(...row); | ||
} | ||
return this; | ||
} | ||
/** | ||
* Return {@link TelegramInlineKeyboardMarkup} as JSON | ||
@@ -242,3 +266,4 @@ */ | ||
return { | ||
inline_keyboard: this.keyboard, | ||
inline_keyboard: this | ||
.keyboard, | ||
}; | ||
@@ -245,0 +270,0 @@ } |
@@ -164,2 +164,16 @@ import type { TelegramKeyboardButton, TelegramKeyboardButtonPollType, TelegramKeyboardButtonRequestChat, TelegramKeyboardButtonRequestUsers, TelegramReplyKeyboardMarkup } from "@gramio/types"; | ||
/** | ||
* Allows you to combine keyboards. Only keyboards are combined. You need to call the `.row()` method to line-break after combine. | ||
* | ||
* @example | ||
* ```ts | ||
* new Keyboard() | ||
* .combine(new Keyboard().text("first")) | ||
* .row() | ||
* .combine(new Keyboard().text("second").row().text("third")) | ||
* ``` | ||
*/ | ||
combine(keyboard: TelegramKeyboardButton[][] | TelegramReplyKeyboardMarkup | { | ||
toJSON: () => TelegramReplyKeyboardMarkup; | ||
}): this; | ||
/** | ||
* Return {@link TelegramReplyKeyboardMarkup} as JSON | ||
@@ -166,0 +180,0 @@ */ |
@@ -243,2 +243,22 @@ "use strict"; | ||
/** | ||
* Allows you to combine keyboards. Only keyboards are combined. You need to call the `.row()` method to line-break after combine. | ||
* | ||
* @example | ||
* ```ts | ||
* new Keyboard() | ||
* .combine(new Keyboard().text("first")) | ||
* .row() | ||
* .combine(new Keyboard().text("second").row().text("third")) | ||
* ``` | ||
*/ | ||
combine(keyboard) { | ||
const json = "toJSON" in keyboard ? keyboard.toJSON() : keyboard; | ||
const buttons = Array.isArray(json) ? json : json.keyboard; | ||
for (const row of buttons) { | ||
if (row.length) | ||
this.row().add(...row); | ||
} | ||
return this; | ||
} | ||
/** | ||
* Return {@link TelegramReplyKeyboardMarkup} as JSON | ||
@@ -245,0 +265,0 @@ */ |
{ | ||
"name": "@gramio/keyboards", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Framework-agnostic Telegram bot keyboard builder with many cool features!", | ||
@@ -24,2 +24,3 @@ "main": "dist/index.js", | ||
"@types/bun": "^1.0.4", | ||
"grammy": "^1.20.3", | ||
"inspectable": "^2.1.0", | ||
@@ -26,0 +27,0 @@ "reflect-metadata": "^0.2.1" |
67029
1572
5