From 78871b697e9f6a330b5984a0d69231ca0f5aaa13 Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Tue, 2 Jan 2018 13:30:29 +0100 Subject: [PATCH] client: return the message in send_file, too --- telethon/telegram_client.py | 39 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/telethon/telegram_client.py b/telethon/telegram_client.py index 70c2784c..730f7445 100644 --- a/telethon/telegram_client.py +++ b/telethon/telegram_client.py @@ -363,6 +363,22 @@ class TelegramClient(TelegramBareClient): drafts = [Draft._from_update(self, u) for u in response.updates] return drafts + @staticmethod + def _get_response_message(request, result): + # Telegram seems to send updateMessageID first, then updateNewMessage, + # however let's not rely on that just in case. + msg_id = None + for update in result.updates: + if isinstance(update, UpdateMessageID): + if update.random_id == request.random_id: + msg_id = update.id + break + + for update in result.updates: + if isinstance(update, (UpdateNewChannelMessage, UpdateNewMessage)): + if update.message.id == msg_id: + return update.message + def send_message(self, entity, message, @@ -415,21 +431,7 @@ class TelegramClient(TelegramBareClient): entities=result.entities ) - # Telegram seems to send updateMessageID first, then updateNewMessage, - # however let's not rely on that just in case. - msg_id = None - for update in result.updates: - if isinstance(update, UpdateMessageID): - if update.random_id == request.random_id: - msg_id = update.id - break - - for update in result.updates: - if isinstance(update, (UpdateNewChannelMessage, UpdateNewMessage)): - if update.message.id == msg_id: - return update.message - - return None # Should not happen + return self._get_response_message(request, result) def delete_messages(self, entity, message_ids, revoke=True): """ @@ -723,11 +725,14 @@ class TelegramClient(TelegramBareClient): # Once the media type is properly specified and the file uploaded, # send the media message to the desired entity. - self(SendMediaRequest( + request = SendMediaRequest( peer=self.get_input_entity(entity), media=media, reply_to_msg_id=self._get_reply_to(reply_to) - )) + ) + result = self(request) + + return self._get_response_message(request, result) def send_voice_note(self, entity, file, caption='', upload_progress=None, reply_to=None):