MTPyroger/pyrogram/client/methods/bots/request_callback_answer.py

76 lines
2.7 KiB
Python
Raw Normal View History

2020-03-21 14:43:32 +00:00
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2020 Dan <https://github.com/delivrance>
2018-06-23 10:29:40 +00:00
#
2020-03-21 14:43:32 +00:00
# This file is part of Pyrogram.
2018-06-23 10:29:40 +00:00
#
2020-03-21 14:43:32 +00:00
# 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.
2018-06-23 10:29:40 +00:00
#
2020-03-21 14:43:32 +00:00
# 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.
2018-06-23 10:29:40 +00:00
#
2020-03-21 14:43:32 +00:00
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
2018-06-23 10:29:40 +00:00
from typing import Union
2018-06-23 10:29:40 +00:00
from pyrogram.api import functions
from pyrogram.client.ext import BaseClient
class RequestCallbackAnswer(BaseClient):
Merge branch 'develop' into asyncio # Conflicts: # pyrogram/__init__.py # pyrogram/client/client.py # pyrogram/client/methods/bots/answer_callback_query.py # pyrogram/client/methods/bots/get_game_high_scores.py # pyrogram/client/methods/bots/get_inline_bot_results.py # pyrogram/client/methods/bots/request_callback_answer.py # pyrogram/client/methods/bots/send_game.py # pyrogram/client/methods/bots/send_inline_bot_result.py # pyrogram/client/methods/bots/set_game_score.py # pyrogram/client/methods/chats/delete_chat_photo.py # pyrogram/client/methods/chats/export_chat_invite_link.py # pyrogram/client/methods/chats/get_chat.py # pyrogram/client/methods/chats/get_chat_member.py # pyrogram/client/methods/chats/get_chat_members.py # pyrogram/client/methods/chats/get_chat_members_count.py # pyrogram/client/methods/chats/get_dialogs.py # pyrogram/client/methods/chats/iter_chat_members.py # pyrogram/client/methods/chats/iter_dialogs.py # pyrogram/client/methods/chats/join_chat.py # pyrogram/client/methods/chats/kick_chat_member.py # pyrogram/client/methods/chats/leave_chat.py # pyrogram/client/methods/chats/pin_chat_message.py # pyrogram/client/methods/chats/promote_chat_member.py # pyrogram/client/methods/chats/restrict_chat_member.py # pyrogram/client/methods/chats/set_chat_description.py # pyrogram/client/methods/chats/set_chat_photo.py # pyrogram/client/methods/chats/set_chat_title.py # pyrogram/client/methods/chats/unban_chat_member.py # pyrogram/client/methods/chats/unpin_chat_message.py # pyrogram/client/methods/contacts/add_contacts.py # pyrogram/client/methods/contacts/delete_contacts.py # pyrogram/client/methods/contacts/get_contacts.py # pyrogram/client/methods/messages/delete_messages.py # pyrogram/client/methods/messages/download_media.py # pyrogram/client/methods/messages/edit_message_caption.py # pyrogram/client/methods/messages/edit_message_media.py # pyrogram/client/methods/messages/edit_message_reply_markup.py # pyrogram/client/methods/messages/edit_message_text.py # pyrogram/client/methods/messages/forward_messages.py # pyrogram/client/methods/messages/get_history.py # pyrogram/client/methods/messages/get_messages.py # pyrogram/client/methods/messages/iter_history.py # pyrogram/client/methods/messages/send_animation.py # pyrogram/client/methods/messages/send_audio.py # pyrogram/client/methods/messages/send_cached_media.py # pyrogram/client/methods/messages/send_chat_action.py # pyrogram/client/methods/messages/send_contact.py # pyrogram/client/methods/messages/send_document.py # pyrogram/client/methods/messages/send_location.py # pyrogram/client/methods/messages/send_media_group.py # pyrogram/client/methods/messages/send_message.py # pyrogram/client/methods/messages/send_photo.py # pyrogram/client/methods/messages/send_sticker.py # pyrogram/client/methods/messages/send_venue.py # pyrogram/client/methods/messages/send_video.py # pyrogram/client/methods/messages/send_video_note.py # pyrogram/client/methods/messages/send_voice.py # pyrogram/client/methods/password/change_cloud_password.py # pyrogram/client/methods/password/enable_cloud_password.py # pyrogram/client/methods/password/remove_cloud_password.py # pyrogram/client/methods/users/delete_user_profile_photos.py # pyrogram/client/methods/users/get_user_profile_photos.py # pyrogram/client/methods/users/get_users.py # pyrogram/session/auth.py # pyrogram/session/session.py
2019-03-16 18:49:01 +00:00
async def request_callback_answer(
2019-03-16 18:23:23 +00:00
self,
chat_id: Union[int, str],
message_id: int,
callback_data: Union[str, bytes],
2019-05-09 03:55:44 +00:00
timeout: int = 10
2019-03-16 18:23:23 +00:00
):
"""Request a callback answer from bots.
2019-03-22 10:53:25 +00:00
This is the equivalent of clicking an inline button containing callback data.
2018-06-23 10:29:40 +00:00
Parameters:
2018-06-23 10:29:40 +00:00
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).
message_id (``int``):
The message id the inline keyboard is attached on.
callback_data (``str`` | ``bytes``):
2018-06-23 10:29:40 +00:00
Callback data associated with the inline button you want to get the answer from.
2019-05-09 03:55:44 +00:00
timeout (``int``, *optional*):
Timeout in seconds.
Returns:
The answer containing info useful for clients to display a notification at the top of the chat screen
or as an alert.
Raises:
TimeoutError: In case the bot fails to answer within 10 seconds.
2019-07-25 09:22:14 +00:00
Example:
.. code-block:: python
app.request_callback_answer(chat_id, message_id, "callback_data")
2018-06-23 10:29:40 +00:00
"""
# Telegram only wants bytes, but we are allowed to pass strings too.
data = bytes(callback_data, "utf-8") if isinstance(callback_data, str) else callback_data
2018-06-23 12:31:21 +00:00
return await self.send(
2018-06-23 10:29:40 +00:00
functions.messages.GetBotCallbackAnswer(
2019-05-25 00:02:37 +00:00
peer=await self.resolve_peer(chat_id),
2018-06-23 10:29:40 +00:00
msg_id=message_id,
data=data
),
retries=0,
2019-05-09 03:55:44 +00:00
timeout=timeout
2018-06-23 10:29:40 +00:00
)