diff --git a/telethon/client/buttons.py b/telethon/client/buttons.py index 210c17f5..49947dbf 100644 --- a/telethon/client/buttons.py +++ b/telethon/client/buttons.py @@ -4,7 +4,18 @@ from .. import utils, events class ButtonMethods(UpdateMethods): - def _build_reply_markup(self, buttons, inline_only=False): + def build_reply_markup(self, buttons, inline_only=False): + """ + Builds a :tl`ReplyInlineMarkup` or :tl:`ReplyKeyboardMarkup` for + the given buttons, or does nothing if either no buttons are + provided or the provided argument is already a reply markup. + + This will add any event handlers defined in the + buttons and delete old ones not to call them twice, + so you should probably call this method manually for + serious bots instead re-adding handlers every time you + send a message. Magic can only go so far. + """ if buttons is None: return None diff --git a/telethon/client/messages.py b/telethon/client/messages.py index 62b6ef10..eaf57f25 100644 --- a/telethon/client/messages.py +++ b/telethon/client/messages.py @@ -435,7 +435,7 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods): if buttons is None: markup = message.reply_markup else: - markup = self._build_reply_markup(buttons) + markup = self.build_reply_markup(buttons) if silent is None: silent = message.silent @@ -463,7 +463,7 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods): reply_to_msg_id=utils.get_message_id(reply_to), clear_draft=clear_draft, silent=silent, - reply_markup=self._build_reply_markup(buttons) + reply_markup=self.build_reply_markup(buttons) ) result = await self(request) @@ -630,7 +630,7 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods): no_webpage=not link_preview, entities=msg_entities, media=media, - reply_markup=self._build_reply_markup(buttons) + reply_markup=self.build_reply_markup(buttons) ) msg = self._get_response_message(request, await self(request), entity) self._cache_media(msg, file, file_handle) diff --git a/telethon/client/uploads.py b/telethon/client/uploads.py index f7daaf7b..09577ecb 100644 --- a/telethon/client/uploads.py +++ b/telethon/client/uploads.py @@ -167,7 +167,7 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods): voice_note=voice_note, video_note=video_note ) - markup = self._build_reply_markup(buttons) + markup = self.build_reply_markup(buttons) request = functions.messages.SendMediaRequest( entity, media, reply_to_msg_id=reply_to, message=caption, entities=msg_entities, reply_markup=markup, silent=silent diff --git a/telethon/tl/custom/inline.py b/telethon/tl/custom/inline.py index c953ad32..9ee244b9 100644 --- a/telethon/tl/custom/inline.py +++ b/telethon/tl/custom/inline.py @@ -253,7 +253,7 @@ class InlineBuilder: if sum(1 for x in (text, geo, contact, game) if x) != 1: raise ValueError('Can only use one of text, geo, contact or game') - markup = self._client._build_reply_markup(buttons, inline_only=True) + markup = self._client.build_reply_markup(buttons, inline_only=True) if text: text, msg_entities = await self._client._parse_message_text( text, parse_mode