diff --git a/README.rst b/README.rst
index 67dbd3a5..b1015db2 100644
--- a/README.rst
+++ b/README.rst
@@ -12,12 +12,10 @@ Pyrogram |twitter|
@app.on_message(Filters.private)
def hello(client, message):
- client.send_message(
- message.chat.id, "Hello {}".format(message.from_user.first_name))
+ message.reply("Hello {}".format(message.from_user.first_name))
- app.start()
- app.idle()
+ app.run()
**Pyrogram** is a brand new Telegram_ Client Library written from the ground up in Python and C. It can be used for building
custom Telegram applications that interact with the MTProto API as both User and Bot.
diff --git a/docs/source/index.rst b/docs/source/index.rst
index 414e47dd..c52e239b 100644
--- a/docs/source/index.rst
+++ b/docs/source/index.rst
@@ -44,8 +44,7 @@ Welcome to Pyrogram
@app.on_message(Filters.private)
def hello(client, message):
- message.reply_text(
- "Hello {}".format(message.from_user.first_name))
+ message.reply("Hello {}".format(message.from_user.first_name))
app.run()
diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py
index 26aa84c8..133ab6c2 100644
--- a/pyrogram/client/filters/filters.py
+++ b/pyrogram/client/filters/filters.py
@@ -19,6 +19,7 @@
import re
from .filter import Filter
+from ..types.reply_markup import InlineKeyboardMarkup, ReplyKeyboardMarkup
def build(name: str, func: callable, **kwargs) -> type:
@@ -131,7 +132,11 @@ class Filters:
pinned_message = build("PinnedMessage", lambda _, m: bool(m.pinned_message))
"""Filter service messages for pinned messages."""
- # TODO: Add filters for reply markups
+ reply_keyboard = build("ReplyKeyboard", lambda _, m: isinstance(m.reply_markup, ReplyKeyboardMarkup))
+ """Filter messages containing reply keyboard markups"""
+
+ inline_keyboard = build("InlineKeyboard", lambda _, m: isinstance(m.reply_markup, InlineKeyboardMarkup))
+ """Filter messages containing inline keyboard markups"""
@staticmethod
def command(command: str or list,
diff --git a/pyrogram/client/methods/bots/__init__.py b/pyrogram/client/methods/bots/__init__.py
index 62e0eb61..2d89c2fb 100644
--- a/pyrogram/client/methods/bots/__init__.py
+++ b/pyrogram/client/methods/bots/__init__.py
@@ -16,12 +16,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see .
-from .callback_query import CallbackQuery
-from .inline import Inline
+from .answer_callback_query import AnswerCallbackQuery
+from .get_inline_bot_results import GetInlineBotResults
+from .request_callback_answer import RequestCallbackAnswer
+from .send_inline_bot_result import SendInlineBotResult
class Bots(
- CallbackQuery,
- Inline
+ AnswerCallbackQuery,
+ GetInlineBotResults,
+ RequestCallbackAnswer,
+ SendInlineBotResult
):
pass
diff --git a/pyrogram/client/methods/bots/callback_query/answer_callback_query.py b/pyrogram/client/methods/bots/answer_callback_query.py
similarity index 98%
rename from pyrogram/client/methods/bots/callback_query/answer_callback_query.py
rename to pyrogram/client/methods/bots/answer_callback_query.py
index be6fbc0c..2636b131 100644
--- a/pyrogram/client/methods/bots/callback_query/answer_callback_query.py
+++ b/pyrogram/client/methods/bots/answer_callback_query.py
@@ -17,7 +17,7 @@
# along with Pyrogram. If not, see .
from pyrogram.api import functions
-from ....ext import BaseClient
+from pyrogram.client.ext import BaseClient
class AnswerCallbackQuery(BaseClient):
diff --git a/pyrogram/client/methods/bots/callback_query/__init__.py b/pyrogram/client/methods/bots/callback_query/__init__.py
deleted file mode 100644
index 76575724..00000000
--- a/pyrogram/client/methods/bots/callback_query/__init__.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# Pyrogram - Telegram MTProto API Client Library for Python
-# Copyright (C) 2017-2018 Dan Tès
-#
-# This file is part of Pyrogram.
-#
-# Pyrogram is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License as published
-# by the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Pyrogram is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with Pyrogram. If not, see .
-
-from .answer_callback_query import AnswerCallbackQuery
-
-
-class CallbackQuery(
- AnswerCallbackQuery
-):
- pass
diff --git a/pyrogram/client/methods/bots/inline/get_inline_bot_results.py b/pyrogram/client/methods/bots/get_inline_bot_results.py
similarity index 98%
rename from pyrogram/client/methods/bots/inline/get_inline_bot_results.py
rename to pyrogram/client/methods/bots/get_inline_bot_results.py
index 86ab18b5..aa8995fa 100644
--- a/pyrogram/client/methods/bots/inline/get_inline_bot_results.py
+++ b/pyrogram/client/methods/bots/get_inline_bot_results.py
@@ -18,7 +18,7 @@
from pyrogram.api import functions, types
from pyrogram.api.errors import UnknownError
-from ....ext import BaseClient
+from pyrogram.client.ext import BaseClient
class GetInlineBotResults(BaseClient):
diff --git a/pyrogram/client/methods/bots/inline/__init__.py b/pyrogram/client/methods/bots/inline/__init__.py
deleted file mode 100644
index af88c57e..00000000
--- a/pyrogram/client/methods/bots/inline/__init__.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# Pyrogram - Telegram MTProto API Client Library for Python
-# Copyright (C) 2017-2018 Dan Tès
-#
-# This file is part of Pyrogram.
-#
-# Pyrogram is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License as published
-# by the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Pyrogram is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with Pyrogram. If not, see .
-
-from .get_inline_bot_results import GetInlineBotResults
-from .send_inline_bot_result import SendInlineBotResult
-
-
-class Inline(
- SendInlineBotResult,
- GetInlineBotResults
-):
- pass
diff --git a/pyrogram/client/methods/bots/request_callback_answer.py b/pyrogram/client/methods/bots/request_callback_answer.py
new file mode 100644
index 00000000..5bc31efd
--- /dev/null
+++ b/pyrogram/client/methods/bots/request_callback_answer.py
@@ -0,0 +1,51 @@
+# Pyrogram - Telegram MTProto API Client Library for Python
+# Copyright (C) 2017-2018 Dan Tès
+#
+# This file is part of Pyrogram.
+#
+# Pyrogram is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Pyrogram is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with Pyrogram. If not, see .
+
+from pyrogram.api import functions
+from pyrogram.client.ext import BaseClient
+
+
+class RequestCallbackAnswer(BaseClient):
+ def request_callback_answer(self,
+ chat_id: int or str,
+ message_id: int,
+ callback_data: str):
+ """Use this method to request a callback answer from bots. This is the equivalent of clicking an inline button
+ containing callback data. The answer contains info useful for clients to display a notification at the top of
+ the chat screen or as an alert.
+
+ Args:
+ chat_id (``int`` | ``str``):
+ Unique identifier (int) or username (str) of the target chat.
+ For your personal cloud (Saved Messages) you can simply use "me" or "self".
+ For a contact that exists in your Telegram address book you can use his phone number (str).
+ For a private channel/supergroup you can use its *t.me/joinchat/* link.
+
+ message_id (``int``):
+ The message id the inline keyboard is attached on.
+
+ callback_data (``str``):
+ Callback data associated with the inline button you want to get the answer from.
+ """
+ return self.send(
+ functions.messages.GetBotCallbackAnswer(
+ peer=self.resolve_peer(chat_id),
+ msg_id=message_id,
+ data=callback_data.encode()
+ )
+ )
diff --git a/pyrogram/client/methods/bots/inline/send_inline_bot_result.py b/pyrogram/client/methods/bots/send_inline_bot_result.py
similarity index 98%
rename from pyrogram/client/methods/bots/inline/send_inline_bot_result.py
rename to pyrogram/client/methods/bots/send_inline_bot_result.py
index 3ce58cd8..a052f6e7 100644
--- a/pyrogram/client/methods/bots/inline/send_inline_bot_result.py
+++ b/pyrogram/client/methods/bots/send_inline_bot_result.py
@@ -17,7 +17,7 @@
# along with Pyrogram. If not, see .
from pyrogram.api import functions
-from ....ext import BaseClient
+from pyrogram.client.ext import BaseClient
class SendInlineBotResult(BaseClient):
diff --git a/pyrogram/client/methods/messages/__init__.py b/pyrogram/client/methods/messages/__init__.py
index c2ff2400..e2c2462e 100644
--- a/pyrogram/client/methods/messages/__init__.py
+++ b/pyrogram/client/methods/messages/__init__.py
@@ -16,22 +16,50 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see .
-from .action import Action
+from .delete_messages import DeleteMessages
+from .edit_message_caption import EditMessageCaption
+from .edit_message_reply_markup import EditMessageReplyMarkup
+from .edit_message_text import EditMessageText
from .forward_messages import ForwardMessages
from .get_history import GetHistory
from .get_messages import GetMessages
-from .media import Media
+from .send_audio import SendAudio
+from .send_chat_action import SendChatAction
+from .send_contact import SendContact
+from .send_document import SendDocument
+from .send_gif import SendGIF
+from .send_location import SendLocation
+from .send_media_group import SendMediaGroup
from .send_message import SendMessage
-from .update import Update
+from .send_photo import SendPhoto
+from .send_sticker import SendSticker
+from .send_venue import SendVenue
+from .send_video import SendVideo
+from .send_video_note import SendVideoNote
+from .send_voice import SendVoice
class Messages(
+ DeleteMessages,
+ EditMessageCaption,
+ EditMessageReplyMarkup,
+ EditMessageText,
+ ForwardMessages,
GetHistory,
GetMessages,
- Action,
- Media,
- Update,
- ForwardMessages,
- SendMessage
+ SendAudio,
+ SendChatAction,
+ SendContact,
+ SendDocument,
+ SendGIF,
+ SendLocation,
+ SendMediaGroup,
+ SendMessage,
+ SendPhoto,
+ SendSticker,
+ SendVenue,
+ SendVideo,
+ SendVideoNote,
+ SendVoice
):
pass
diff --git a/pyrogram/client/methods/messages/action/__init__.py b/pyrogram/client/methods/messages/action/__init__.py
deleted file mode 100644
index 639405f2..00000000
--- a/pyrogram/client/methods/messages/action/__init__.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# Pyrogram - Telegram MTProto API Client Library for Python
-# Copyright (C) 2017-2018 Dan Tès
-#
-# This file is part of Pyrogram.
-#
-# Pyrogram is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License as published
-# by the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Pyrogram is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with Pyrogram. If not, see .
-
-from .send_chat_action import SendChatAction
-
-
-class Action(
- SendChatAction
-):
- pass
diff --git a/pyrogram/client/methods/messages/update/delete_messages.py b/pyrogram/client/methods/messages/delete_messages.py
similarity index 98%
rename from pyrogram/client/methods/messages/update/delete_messages.py
rename to pyrogram/client/methods/messages/delete_messages.py
index 2853ce25..7fa43d4e 100644
--- a/pyrogram/client/methods/messages/update/delete_messages.py
+++ b/pyrogram/client/methods/messages/delete_messages.py
@@ -17,7 +17,7 @@
# along with Pyrogram. If not, see .
from pyrogram.api import functions, types
-from ....ext import BaseClient
+from pyrogram.client.ext import BaseClient
class DeleteMessages(BaseClient):
diff --git a/pyrogram/client/methods/messages/update/edit_message_caption.py b/pyrogram/client/methods/messages/edit_message_caption.py
similarity index 98%
rename from pyrogram/client/methods/messages/update/edit_message_caption.py
rename to pyrogram/client/methods/messages/edit_message_caption.py
index e2bade97..720a1d84 100644
--- a/pyrogram/client/methods/messages/update/edit_message_caption.py
+++ b/pyrogram/client/methods/messages/edit_message_caption.py
@@ -17,7 +17,7 @@
# along with Pyrogram. If not, see .
from pyrogram.api import functions, types
-from ....ext import BaseClient, utils
+from pyrogram.client.ext import BaseClient, utils
class EditMessageCaption(BaseClient):
diff --git a/pyrogram/client/methods/messages/update/edit_message_reply_markup.py b/pyrogram/client/methods/messages/edit_message_reply_markup.py
similarity index 98%
rename from pyrogram/client/methods/messages/update/edit_message_reply_markup.py
rename to pyrogram/client/methods/messages/edit_message_reply_markup.py
index ec7c7638..b67a95f7 100644
--- a/pyrogram/client/methods/messages/update/edit_message_reply_markup.py
+++ b/pyrogram/client/methods/messages/edit_message_reply_markup.py
@@ -17,7 +17,7 @@
# along with Pyrogram. If not, see .
from pyrogram.api import functions, types
-from ....ext import BaseClient, utils
+from pyrogram.client.ext import BaseClient, utils
class EditMessageReplyMarkup(BaseClient):
diff --git a/pyrogram/client/methods/messages/update/edit_message_text.py b/pyrogram/client/methods/messages/edit_message_text.py
similarity index 98%
rename from pyrogram/client/methods/messages/update/edit_message_text.py
rename to pyrogram/client/methods/messages/edit_message_text.py
index 6fa50e71..fb238d14 100644
--- a/pyrogram/client/methods/messages/update/edit_message_text.py
+++ b/pyrogram/client/methods/messages/edit_message_text.py
@@ -17,7 +17,7 @@
# along with Pyrogram. If not, see .
from pyrogram.api import functions, types
-from ....ext import BaseClient, utils
+from pyrogram.client.ext import BaseClient, utils
class EditMessageText(BaseClient):
diff --git a/pyrogram/client/methods/messages/media/__init__.py b/pyrogram/client/methods/messages/media/__init__.py
deleted file mode 100644
index b0e287c5..00000000
--- a/pyrogram/client/methods/messages/media/__init__.py
+++ /dev/null
@@ -1,47 +0,0 @@
-# Pyrogram - Telegram MTProto API Client Library for Python
-# Copyright (C) 2017-2018 Dan Tès
-#
-# This file is part of Pyrogram.
-#
-# Pyrogram is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License as published
-# by the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Pyrogram is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with Pyrogram. If not, see .
-
-from .send_audio import SendAudio
-from .send_contact import SendContact
-from .send_document import SendDocument
-from .send_gif import SendGIF
-from .send_location import SendLocation
-from .send_media_group import SendMediaGroup
-from .send_photo import SendPhoto
-from .send_sticker import SendSticker
-from .send_venue import SendVenue
-from .send_video import SendVideo
-from .send_video_note import SendVideoNote
-from .send_voice import SendVoice
-
-
-class Media(
- SendContact,
- SendVenue,
- SendLocation,
- SendMediaGroup,
- SendVideoNote,
- SendVoice,
- SendVideo,
- SendGIF,
- SendSticker,
- SendDocument,
- SendAudio,
- SendPhoto
-):
- pass
diff --git a/pyrogram/client/methods/messages/media/send_audio.py b/pyrogram/client/methods/messages/send_audio.py
similarity index 99%
rename from pyrogram/client/methods/messages/media/send_audio.py
rename to pyrogram/client/methods/messages/send_audio.py
index 00ccbe4d..e00115a1 100644
--- a/pyrogram/client/methods/messages/media/send_audio.py
+++ b/pyrogram/client/methods/messages/send_audio.py
@@ -23,7 +23,7 @@ import struct
from pyrogram.api import functions, types
from pyrogram.api.errors import FileIdInvalid, FilePartMissing
-from ....ext import BaseClient, utils
+from pyrogram.client.ext import BaseClient, utils
class SendAudio(BaseClient):
diff --git a/pyrogram/client/methods/messages/action/send_chat_action.py b/pyrogram/client/methods/messages/send_chat_action.py
similarity index 98%
rename from pyrogram/client/methods/messages/action/send_chat_action.py
rename to pyrogram/client/methods/messages/send_chat_action.py
index b770f60e..1382af0d 100644
--- a/pyrogram/client/methods/messages/action/send_chat_action.py
+++ b/pyrogram/client/methods/messages/send_chat_action.py
@@ -17,7 +17,7 @@
# along with Pyrogram. If not, see .
from pyrogram.api import functions
-from ....ext import BaseClient, ChatAction
+from pyrogram.client.ext import BaseClient, ChatAction
class SendChatAction(BaseClient):
diff --git a/pyrogram/client/methods/messages/media/send_contact.py b/pyrogram/client/methods/messages/send_contact.py
similarity index 98%
rename from pyrogram/client/methods/messages/media/send_contact.py
rename to pyrogram/client/methods/messages/send_contact.py
index 2965fb5a..7b7b3368 100644
--- a/pyrogram/client/methods/messages/media/send_contact.py
+++ b/pyrogram/client/methods/messages/send_contact.py
@@ -17,7 +17,7 @@
# along with Pyrogram. If not, see .
from pyrogram.api import functions, types
-from ....ext import BaseClient, utils
+from pyrogram.client.ext import BaseClient, utils
class SendContact(BaseClient):
diff --git a/pyrogram/client/methods/messages/media/send_document.py b/pyrogram/client/methods/messages/send_document.py
similarity index 99%
rename from pyrogram/client/methods/messages/media/send_document.py
rename to pyrogram/client/methods/messages/send_document.py
index f32f78c6..2a88c286 100644
--- a/pyrogram/client/methods/messages/media/send_document.py
+++ b/pyrogram/client/methods/messages/send_document.py
@@ -23,7 +23,7 @@ import struct
from pyrogram.api import functions, types
from pyrogram.api.errors import FileIdInvalid, FilePartMissing
-from ....ext import BaseClient, utils
+from pyrogram.client.ext import BaseClient, utils
class SendDocument(BaseClient):
diff --git a/pyrogram/client/methods/messages/media/send_gif.py b/pyrogram/client/methods/messages/send_gif.py
similarity index 99%
rename from pyrogram/client/methods/messages/media/send_gif.py
rename to pyrogram/client/methods/messages/send_gif.py
index 5c19a19b..d843f72b 100644
--- a/pyrogram/client/methods/messages/media/send_gif.py
+++ b/pyrogram/client/methods/messages/send_gif.py
@@ -23,7 +23,7 @@ import struct
from pyrogram.api import functions, types
from pyrogram.api.errors import FileIdInvalid, FilePartMissing
-from ....ext import BaseClient, utils
+from pyrogram.client.ext import BaseClient, utils
class SendGIF(BaseClient):
diff --git a/pyrogram/client/methods/messages/media/send_location.py b/pyrogram/client/methods/messages/send_location.py
similarity index 98%
rename from pyrogram/client/methods/messages/media/send_location.py
rename to pyrogram/client/methods/messages/send_location.py
index 0a1a1776..042f67bc 100644
--- a/pyrogram/client/methods/messages/media/send_location.py
+++ b/pyrogram/client/methods/messages/send_location.py
@@ -17,7 +17,7 @@
# along with Pyrogram. If not, see .
from pyrogram.api import functions, types
-from ....ext import BaseClient, utils
+from pyrogram.client.ext import BaseClient, utils
class SendLocation(BaseClient):
diff --git a/pyrogram/client/methods/messages/media/send_media_group.py b/pyrogram/client/methods/messages/send_media_group.py
similarity index 99%
rename from pyrogram/client/methods/messages/media/send_media_group.py
rename to pyrogram/client/methods/messages/send_media_group.py
index f0af01be..188ed70f 100644
--- a/pyrogram/client/methods/messages/media/send_media_group.py
+++ b/pyrogram/client/methods/messages/send_media_group.py
@@ -24,7 +24,7 @@ import struct
from pyrogram.api import functions, types
from pyrogram.api.errors import FileIdInvalid
from pyrogram.client import types as pyrogram_types
-from ....ext import BaseClient, utils
+from pyrogram.client.ext import BaseClient, utils
class SendMediaGroup(BaseClient):
diff --git a/pyrogram/client/methods/messages/media/send_photo.py b/pyrogram/client/methods/messages/send_photo.py
similarity index 99%
rename from pyrogram/client/methods/messages/media/send_photo.py
rename to pyrogram/client/methods/messages/send_photo.py
index e066deef..c4f81ece 100644
--- a/pyrogram/client/methods/messages/media/send_photo.py
+++ b/pyrogram/client/methods/messages/send_photo.py
@@ -22,7 +22,7 @@ import struct
from pyrogram.api import functions, types
from pyrogram.api.errors import FileIdInvalid, FilePartMissing
-from ....ext import BaseClient, utils
+from pyrogram.client.ext import BaseClient, utils
class SendPhoto(BaseClient):
diff --git a/pyrogram/client/methods/messages/media/send_sticker.py b/pyrogram/client/methods/messages/send_sticker.py
similarity index 99%
rename from pyrogram/client/methods/messages/media/send_sticker.py
rename to pyrogram/client/methods/messages/send_sticker.py
index 7d559d1c..d2e806bb 100644
--- a/pyrogram/client/methods/messages/media/send_sticker.py
+++ b/pyrogram/client/methods/messages/send_sticker.py
@@ -22,7 +22,7 @@ import struct
from pyrogram.api import functions, types
from pyrogram.api.errors import FileIdInvalid, FilePartMissing
-from ....ext import BaseClient, utils
+from pyrogram.client.ext import BaseClient, utils
class SendSticker(BaseClient):
diff --git a/pyrogram/client/methods/messages/media/send_venue.py b/pyrogram/client/methods/messages/send_venue.py
similarity index 98%
rename from pyrogram/client/methods/messages/media/send_venue.py
rename to pyrogram/client/methods/messages/send_venue.py
index dcb3639d..a08b1139 100644
--- a/pyrogram/client/methods/messages/media/send_venue.py
+++ b/pyrogram/client/methods/messages/send_venue.py
@@ -17,7 +17,7 @@
# along with Pyrogram. If not, see .
from pyrogram.api import functions, types
-from ....ext import BaseClient, utils
+from pyrogram.client.ext import BaseClient, utils
class SendVenue(BaseClient):
diff --git a/pyrogram/client/methods/messages/media/send_video.py b/pyrogram/client/methods/messages/send_video.py
similarity index 99%
rename from pyrogram/client/methods/messages/media/send_video.py
rename to pyrogram/client/methods/messages/send_video.py
index f7c7d66d..ca6eadd2 100644
--- a/pyrogram/client/methods/messages/media/send_video.py
+++ b/pyrogram/client/methods/messages/send_video.py
@@ -23,7 +23,7 @@ import struct
from pyrogram.api import functions, types
from pyrogram.api.errors import FileIdInvalid, FilePartMissing
-from ....ext import BaseClient, utils
+from pyrogram.client.ext import BaseClient, utils
class SendVideo(BaseClient):
diff --git a/pyrogram/client/methods/messages/media/send_video_note.py b/pyrogram/client/methods/messages/send_video_note.py
similarity index 99%
rename from pyrogram/client/methods/messages/media/send_video_note.py
rename to pyrogram/client/methods/messages/send_video_note.py
index 6eb2c252..429ef124 100644
--- a/pyrogram/client/methods/messages/media/send_video_note.py
+++ b/pyrogram/client/methods/messages/send_video_note.py
@@ -23,7 +23,7 @@ import struct
from pyrogram.api import functions, types
from pyrogram.api.errors import FileIdInvalid, FilePartMissing
-from ....ext import BaseClient, utils
+from pyrogram.client.ext import BaseClient, utils
class SendVideoNote(BaseClient):
diff --git a/pyrogram/client/methods/messages/media/send_voice.py b/pyrogram/client/methods/messages/send_voice.py
similarity index 99%
rename from pyrogram/client/methods/messages/media/send_voice.py
rename to pyrogram/client/methods/messages/send_voice.py
index 114ee073..f60bb577 100644
--- a/pyrogram/client/methods/messages/media/send_voice.py
+++ b/pyrogram/client/methods/messages/send_voice.py
@@ -23,7 +23,7 @@ import struct
from pyrogram.api import functions, types
from pyrogram.api.errors import FileIdInvalid, FilePartMissing
-from ....ext import BaseClient, utils
+from pyrogram.client.ext import BaseClient, utils
class SendVoice(BaseClient):
diff --git a/pyrogram/client/methods/messages/update/__init__.py b/pyrogram/client/methods/messages/update/__init__.py
deleted file mode 100644
index cc913e23..00000000
--- a/pyrogram/client/methods/messages/update/__init__.py
+++ /dev/null
@@ -1,31 +0,0 @@
-# Pyrogram - Telegram MTProto API Client Library for Python
-# Copyright (C) 2017-2018 Dan Tès
-#
-# This file is part of Pyrogram.
-#
-# Pyrogram is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License as published
-# by the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Pyrogram is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with Pyrogram. If not, see .
-
-from .delete_messages import DeleteMessages
-from .edit_message_caption import EditMessageCaption
-from .edit_message_reply_markup import EditMessageReplyMarkup
-from .edit_message_text import EditMessageText
-
-
-class Update(
- DeleteMessages,
- EditMessageReplyMarkup,
- EditMessageCaption,
- EditMessageText
-):
- pass
diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py
index 9b712c1f..7a4e2ceb 100644
--- a/pyrogram/client/types/message.py
+++ b/pyrogram/client/types/message.py
@@ -17,6 +17,7 @@
# along with Pyrogram. If not, see .
from pyrogram.api.core import Object
+from .reply_markup import InlineKeyboardMarkup, ReplyKeyboardMarkup
class Message(Object):
@@ -310,14 +311,14 @@ class Message(Object):
self.command = command
self.reply_markup = reply_markup
- async def reply_text(self,
- text: str,
- quote: bool = None,
- parse_mode: str = "",
- disable_web_page_preview: bool = None,
- disable_notification: bool = None,
- reply_to_message_id: int = None,
- reply_markup=None):
+ async def reply(self,
+ text: str,
+ quote: bool = None,
+ parse_mode: str = "",
+ disable_web_page_preview: bool = None,
+ disable_notification: bool = None,
+ reply_to_message_id: int = None,
+ reply_markup=None):
"""Use this method as a shortcut for:
.. code-block:: python
@@ -460,3 +461,115 @@ class Message(Object):
)
return True
+
+ async def click(self, x: int or str, y: int = None, quote: bool = None):
+ """Use this method to click a button attached to the message.
+ It's a shortcut for:
+
+ - Clicking inline buttons:
+
+ .. code-block:: python
+
+ client.request_callback_answer(
+ chat_id=message.chat.id,
+ message_id=message.message_id,
+ callback_data=message.reply_markup[i][j].callback_data
+ )
+
+ - Clicking normal buttons:
+
+ .. code-block:: python
+
+ client.send_message(
+ chat_id=message.chat.id,
+ text=message.reply_markup[i][j].text
+ )
+
+ This method can be used in three different ways:
+
+ 1. Pass one integer argument only (e.g.: ``.click(2)``, to click a button at index 2).
+ Buttons are counted left to right, starting from the top.
+
+ 2. Pass two integer arguments (e.g.: ``.click(1, 0)``, to click a button at position (1, 0)).
+ The origin (0, 0) is top-left.
+
+ 3. Pass one string argument only (e.g.: ``.click("Settings")``, to click a button by using its label).
+ Only the first matching button will be pressed.
+
+ Args:
+ x (``int`` | ``str``):
+ Used as integer index, integer abscissa (in pair with y) or as string label.
+
+ y (``int``, *optional*):
+ Used as ordinate only (in pair with x).
+
+ quote (``bool``, *optional*):
+ Useful for normal buttons only, where pressing it will result in a new message sent.
+ If ``True``, the message will be sent as a reply to this message.
+ Defaults to ``True`` in group chats and ``False`` in private chats.
+
+ Returns:
+ - The result of *request_callback_answer()* in case of inline callback button clicks.
+ - The result of *reply()* in case of normal button clicks.
+ - A string in case the inline button is an URL, switch_inline_query or switch_inline_query_current_chat
+ button.
+
+ Raises:
+ :class:`Error `
+ ``ValueError``: If the provided index or position is out of range or the button label was not found.
+ """
+ if isinstance(self.reply_markup, ReplyKeyboardMarkup):
+ if quote is None:
+ quote = self.chat.type != "private"
+
+ return await self.reply(x, quote=quote)
+ elif isinstance(self.reply_markup, InlineKeyboardMarkup):
+ if isinstance(x, int) and y is None:
+ try:
+ button = [
+ button
+ for row in self.reply_markup.inline_keyboard
+ for button in row
+ ][x]
+ except IndexError:
+ raise ValueError("The button at index {} doesn't exist".format(x)) from None
+ elif isinstance(x, int) and isinstance(y, int):
+ try:
+ button = self.reply_markup.inline_keyboard[y][x]
+ except IndexError:
+ raise ValueError("The button at position ({}, {}) doesn't exist".format(x, y)) from None
+ elif isinstance(x, str):
+ x = x.encode("utf-16", "surrogatepass").decode("utf-16")
+
+ try:
+ button = [
+ button
+ for row in self.reply_markup.inline_keyboard
+ for button in row
+ if x == button.text
+ ][0]
+ except IndexError:
+ raise ValueError(
+ "The button with label '{}' doesn't exists".format(
+ x.encode("unicode_escape").decode()
+ )
+ ) from None
+ else:
+ raise ValueError("Invalid arguments")
+
+ if button.callback_data:
+ return await self._client.request_callback_answer(
+ chat_id=self.chat.id,
+ message_id=self.message_id,
+ data=button.callback_data
+ )
+ elif button.url:
+ return button.url
+ elif button.switch_inline_query:
+ return button.switch_inline_query
+ elif button.switch_inline_query_current_chat:
+ return button.switch_inline_query_current_chat
+ else:
+ raise ValueError("This button is not supported yet")
+ else:
+ raise ValueError("The message doesn't contain any keyboard")