diff --git a/lib/src/telegram/models/copy_text_button.dart b/lib/src/telegram/models/copy_text_button.dart index d5f7c93d..1a57e101 100644 --- a/lib/src/telegram/models/copy_text_button.dart +++ b/lib/src/telegram/models/copy_text_button.dart @@ -16,7 +16,7 @@ class CopyTextButton { } /// Creates the [CopyTextButton] from JSON map - factory CopyTextButton.fromJson(Map map) { - return CopyTextButton(text: map['text']); + factory CopyTextButton.fromJson(Map json) { + return CopyTextButton(text: json['text']); } } diff --git a/lib/src/telegram/models/inline_keyboard_button.dart b/lib/src/telegram/models/inline_keyboard_button.dart index 348cf211..806e27b6 100644 --- a/lib/src/telegram/models/inline_keyboard_button.dart +++ b/lib/src/telegram/models/inline_keyboard_button.dart @@ -87,6 +87,9 @@ class InlineKeyboardButton { json['switch_inline_query_chosen_chat'], ) : null, + copyText: json['copy_text'] != null + ? CopyTextButton.fromJson(json['copy_text']) + : null, ); } @@ -103,6 +106,7 @@ class InlineKeyboardButton { 'pay': pay, 'web_app': webApp?.toJson(), 'switch_inline_query_chosen_chat': switchInlineQueryChosenChat?.toJson(), + 'copy_text': copyText?.toJson(), }..removeWhere(_nullFilter); } } diff --git a/lib/src/televerse/markups/inline_keyboard.dart b/lib/src/televerse/markups/inline_keyboard.dart index 09aaceff..e3b5f9ac 100644 --- a/lib/src/televerse/markups/inline_keyboard.dart +++ b/lib/src/televerse/markups/inline_keyboard.dart @@ -206,4 +206,20 @@ class InlineKeyboard extends InlineKeyboardMarkup { ); return this; } + + /// Adds a button which when pressed copies an arbitrary text specified by [copyText] + InlineKeyboard copyText( + String text, { + required String copyText, + }) { + inlineKeyboard.last.add( + InlineKeyboardButton( + text: text, + copyText: CopyTextButton( + text: copyText, + ), + ), + ); + return this; + } } diff --git a/lib/src/televerse/markups/inline_menu.dart b/lib/src/televerse/markups/inline_menu.dart index a25a0e00..c1e9833c 100644 --- a/lib/src/televerse/markups/inline_menu.dart +++ b/lib/src/televerse/markups/inline_menu.dart @@ -156,6 +156,19 @@ class _InlineMenuPayButton extends _TMenuButton { } } +class _InlineMenuCopyTextButton extends _TMenuButton { + final String copyText; + const _InlineMenuCopyTextButton(super.text, this.copyText); + + @override + Map toJson() { + return { + 'text': text, + 'copy_text': CopyTextButton(text: copyText).toJson(), + }; + } +} + /// This object represents a Inline Keyboard with the action to be done. class InlineMenu implements InlineKeyboardMarkup, TeleverseMenu { @@ -336,6 +349,17 @@ class InlineMenu return this; } + /// Creates a button when tappd copies the arbitary text + InlineMenu copyText( + String text, { + required String copyText, + }) { + if (_buttons.isEmpty) _buttons.add([]); + _buttons.last.add(_InlineMenuCopyTextButton(text, copyText)); + inlineKeyboard = TeleverseMenu._makeInlineKeyboard(_buttons); + return this; + } + /// List of rows of the keyboard @override List> inlineKeyboard;