Skip to content

Commit

Permalink
feat: add support for CopyTextButton and bump
Browse files Browse the repository at this point in the history
  • Loading branch information
kravetsone committed Nov 2, 2024
1 parent 7f06c02 commit 79b7068
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
Binary file modified bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions import_map.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"imports": {
"@gramio/types": "jsr:@gramio/types@^7.3.4"
}
"imports": {
"@gramio/types": "jsr:@gramio/types@^7.11.0"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gramio/keyboards",
"version": "0.4.0",
"version": "1.0.0",
"description": "Framework-agnostic Telegram bot keyboard builder with many cool features!",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down
27 changes: 22 additions & 5 deletions src/inline-keyboard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {
TelegramCallbackGame,
TelegramCopyTextButton,
TelegramInlineKeyboardButton,
TelegramInlineKeyboardMarkup,
TelegramLoginUrl,
Expand Down Expand Up @@ -42,9 +43,13 @@ declare namespace InlineKeyboardButton {
export interface PayButton extends AbstractInlineKeyboardButton {
pay: boolean;
}
export interface CopyTextButtonButton extends AbstractInlineKeyboardButton {
/** Description of the button that copies the specified text to the clipboard. */
copy_text: TelegramCopyTextButton;
}
}
interface TelegramInlineKeyboardMarkupFix {
//![INFO] Some hack for solve grammy union type problem
//![INFO] Some hack for solve union type problem with grammy
//TODO: maybe find better way?
inline_keyboard: (
| TelegramInlineKeyboardButton
Expand All @@ -55,6 +60,7 @@ interface TelegramInlineKeyboardMarkupFix {
| InlineKeyboardButton.SwitchInlineButton
| InlineKeyboardButton.SwitchInlineCurrentChatButton
| InlineKeyboardButton.SwitchInlineChosenChatButton
| InlineKeyboardButton.CopyTextButtonButton
| InlineKeyboardButton.UrlButton
| InlineKeyboardButton.WebAppButton
)[][];
Expand Down Expand Up @@ -291,8 +297,6 @@ export class InlineKeyboard extends BaseKeyboardConstructor<TelegramInlineKeyboa
}

/**
* **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.
Expand All @@ -311,8 +315,6 @@ export class InlineKeyboard extends BaseKeyboardConstructor<TelegramInlineKeyboa
}

/**
* **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.
Expand All @@ -327,6 +329,21 @@ export class InlineKeyboard extends BaseKeyboardConstructor<TelegramInlineKeyboa
};
}

copy(text: string, textToCopy: string | TelegramCopyTextButton) {
return this.add(InlineKeyboard.copy(text, textToCopy));
}

static copy(
text: string,
textToCopy: string | TelegramCopyTextButton,
): TelegramInlineKeyboardButton {
return {
text,
copy_text:
typeof textToCopy === "string" ? { text: textToCopy } : textToCopy,
};
}

/**
* Allows you to combine keyboards. Only keyboards are combined. You need to call the `.row()` method to line-break after combine.
*
Expand Down

0 comments on commit 79b7068

Please sign in to comment.