Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/unreleased/5229.87PBN4GFkuAaDhhgFwCYkY.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ pull_requests = [
{ uid = "5235", author_uid = "harshil21" },
{ uid = "5238", author_uid = "harshil21" },
{ uid = "5232", author_uid = "aelkheir" },
{ uid = "5232", author_uid = ["Poolitzer", "Phil9l", "harshil21", "aelkheir"] },
]
2 changes: 2 additions & 0 deletions docs/source/inclusions/bot_methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
- Used for answering the callback query
* - :meth:`~telegram.Bot.answer_inline_query`
- Used for answering the inline query
* - :meth:`~telegram.Bot.answer_guest_query`
- Used for replying to a received guest message
* - :meth:`~telegram.Bot.answer_pre_checkout_query`
- Used for answering a pre checkout query
* - :meth:`~telegram.Bot.answer_shipping_query`
Expand Down
1 change: 1 addition & 0 deletions docs/source/telegram.at-tree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ Available Types
telegram.replykeyboardmarkup
telegram.replykeyboardremove
telegram.replyparameters
telegram.sentguestmessage
telegram.sentwebappmessage
telegram.shareduser
telegram.story
Expand Down
6 changes: 6 additions & 0 deletions docs/source/telegram.sentguestmessage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SentGuestMessage
================

.. autoclass:: telegram.SentGuestMessage
:members:
:show-inheritance:
2 changes: 2 additions & 0 deletions src/telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
"RevenueWithdrawalStateSucceeded",
"SecureData",
"SecureValue",
"SentGuestMessage",
"SentWebAppMessage",
"SharedUser",
"ShippingAddress",
Expand Down Expand Up @@ -617,6 +618,7 @@
from ._reply import ExternalReplyInfo, ReplyParameters, TextQuote
from ._replykeyboardmarkup import ReplyKeyboardMarkup
from ._replykeyboardremove import ReplyKeyboardRemove
from ._sentguestmessage import SentGuestMessage
from ._sentwebappmessage import SentWebAppMessage
from ._shared import ChatShared, SharedUser, UsersShared
from ._story import Story
Expand Down
48 changes: 48 additions & 0 deletions src/telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
from telegram._preparedkeyboardbutton import PreparedKeyboardButton
from telegram._reaction import ReactionType, ReactionTypeCustomEmoji, ReactionTypeEmoji
from telegram._reply import ReplyParameters
from telegram._sentguestmessage import SentGuestMessage
from telegram._sentwebappmessage import SentWebAppMessage
from telegram._story import Story
from telegram._telegramobject import TelegramObject
Expand Down Expand Up @@ -5860,6 +5861,51 @@ async def answer_web_app_query(

return SentWebAppMessage.de_json(api_result, self)

async def answer_guest_query(
self,
guest_query_id: str,
result: "InlineQueryResult",
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict | None = None,
) -> SentGuestMessage:
"""Use this method to reply to a received guest message.

.. versionadded:: NEXT.VERSION

Args:
guest_query_id (:obj:`str`): Unique identifier for the query to be answered.
result (:class:`telegram.InlineQueryResult`): An object describing the message to be
sent.

Returns:
:class:`telegram.SentGuestMessage`: On success, a
:class:`telegram.SentGuestMessage` is returned.

Raises:
:class:`telegram.error.TelegramError`

"""
data: JSONDict = {
"guest_query_id": guest_query_id,
"result": self._insert_defaults_for_ilq_results(result),
}

api_result = await self._post(
"answerGuestQuery",
data,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
)

return SentGuestMessage.de_json(api_result, self)

async def restrict_chat_member(
self,
chat_id: str | int,
Expand Down Expand Up @@ -12813,6 +12859,8 @@ def to_dict(self, recursive: bool = True) -> JSONDict: # noqa: ARG002
"""Alias for :meth:`answer_pre_checkout_query`"""
answerWebAppQuery = answer_web_app_query
"""Alias for :meth:`answer_web_app_query`"""
answerGuestQuery = answer_guest_query
"""Alias for :meth:`answer_guest_query`"""
restrictChatMember = restrict_chat_member
"""Alias for :meth:`restrict_chat_member`"""
promoteChatMember = promote_chat_member
Expand Down
82 changes: 82 additions & 0 deletions src/telegram/_message.py
Comment thread
aelkheir marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
GiveawayCompleted,
GiveawayCreated,
GiveawayWinners,
InlineQueryResult,
InputMedia,
InputMediaAudio,
InputMediaDocument,
Expand All @@ -123,6 +124,7 @@
MessageId,
MessageOrigin,
ReactionType,
SentGuestMessage,
SuggestedPostApprovalFailed,
SuggestedPostApproved,
SuggestedPostDeclined,
Expand Down Expand Up @@ -710,6 +712,21 @@ class Message(MaybeInaccessibleMessage):
managed_bot_created (:class:`telegram.ManagedBotCreated`, optional): Service message: user
created a bot that will be managed by the current bot.

.. versionadded:: NEXT.VERSION
guest_bot_caller_user (:class:`telegram.User`, optional): For a message sent by a guest
bot, this is the user whose original message triggered the bot's response.

.. versionadded:: NEXT.VERSION
guest_bot_caller_chat (:class:`telegram.Chat`, optional): For a message sent by a guest
bot, this is the chat whose original message triggered the bot's response.

.. versionadded:: NEXT.VERSION
guest_query_id (:obj:`str`, optional): The unique identifier for the guest query. Use this
identifier with the method :meth:`telegram.Bot.answer_guest_query` to send a response
message. If non-empty, the message belongs to the chat where the guest bot was
summoned, which may not coincide with other existing bot chats sharing the same
identifier.

.. versionadded:: NEXT.VERSION
live_photo (:class:`telegram.LivePhoto`, optional): Message is a live photo, information
about the live photo. For backward compatibility, when this field is set, the photo
Expand Down Expand Up @@ -1147,6 +1164,21 @@ class Message(MaybeInaccessibleMessage):
managed_bot_created (:class:`telegram.ManagedBotCreated`): Optional. Service message: user
created a bot that will be managed by the current bot.

.. versionadded:: NEXT.VERSION
guest_bot_caller_user (:class:`telegram.User`): Optional. For a message sent by a guest
bot, this is the user whose original message triggered the bot's response.

.. versionadded:: NEXT.VERSION
guest_bot_caller_chat (:class:`telegram.Chat`): Optional. For a message sent by a guest
bot, this is the chat whose original message triggered the bot's response.

.. versionadded:: NEXT.VERSION
guest_query_id (:obj:`str`): Optional. The unique identifier for the guest query. Use this
identifier with the method :meth:`telegram.Bot.answer_guest_query` to send a response
message. If non-empty, the message belongs to the chat where the guest bot was
summoned, which may not coincide with other existing bot chats sharing the same
identifier.

.. versionadded:: NEXT.VERSION
live_photo (:class:`telegram.LivePhoto`): Optional. Message is a live photo, information
about the live photo. For backward compatibility, when this field is set, the photo
Expand Down Expand Up @@ -1214,6 +1246,9 @@ class Message(MaybeInaccessibleMessage):
"giveaway_created",
"giveaway_winners",
"group_chat_created",
"guest_bot_caller_chat",
"guest_bot_caller_user",
"guest_query_id",
"has_media_spoiler",
"has_protected_content",
"invoice",
Expand Down Expand Up @@ -1394,6 +1429,9 @@ def __init__(
poll_option_deleted: PollOptionDeleted | None = None,
reply_to_poll_option_id: str | None = None,
managed_bot_created: ManagedBotCreated | None = None,
guest_bot_caller_user: User | None = None,
guest_bot_caller_chat: Chat | None = None,
guest_query_id: str | None = None,
live_photo: LivePhoto | None = None,
*,
api_kwargs: JSONDict | None = None,
Expand Down Expand Up @@ -1529,6 +1567,9 @@ def __init__(
self.poll_option_deleted: PollOptionDeleted | None = poll_option_deleted
self.reply_to_poll_option_id: str | None = reply_to_poll_option_id
self.managed_bot_created: ManagedBotCreated | None = managed_bot_created
self.guest_bot_caller_user: User | None = guest_bot_caller_user
self.guest_bot_caller_chat: Chat | None = guest_bot_caller_chat
self.guest_query_id: str | None = guest_query_id
self.live_photo: LivePhoto | None = live_photo

self._effective_attachment = DEFAULT_NONE
Expand Down Expand Up @@ -1759,6 +1800,12 @@ def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "Message":
data["managed_bot_created"] = de_json_optional(
data.get("managed_bot_created"), ManagedBotCreated, bot
)
data["guest_bot_caller_user"] = de_json_optional(
data.get("guest_bot_caller_user"), User, bot
)
data["guest_bot_caller_chat"] = de_json_optional(
data.get("guest_bot_caller_chat"), Chat, bot
)
data["live_photo"] = de_json_optional(data.get("live_photo"), LivePhoto, bot)

api_kwargs = {}
Expand Down Expand Up @@ -5370,6 +5417,41 @@ async def delete_reaction(
api_kwargs=api_kwargs,
)

async def answer_guest_query(
self,
result: "InlineQueryResult",
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict | None = None,
) -> "SentGuestMessage":
"""Shortcut for::

await bot.answer_guest_query(
self.guest_query_id,
*args, **kwargs,
)

For the documentation of the arguments, please see :meth:`telegram.Bot.answer_guest_query`.

.. versionadded:: NEXT.VERSION

Returns:
:class:`telegram.SentGuestMessage`: On success, a
:class:`telegram.SentGuestMessage` is returned.
"""
return await self.get_bot().answer_guest_query(
guest_query_id=self.guest_query_id,
result=result,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
)

def parse_entity(self, entity: MessageEntity) -> str:
"""Returns the text from a given :class:`telegram.MessageEntity`.

Expand Down
54 changes: 54 additions & 0 deletions src/telegram/_sentguestmessage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2026
# Leandro Toledo de Souza <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Sent Guest Message."""

from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict


class SentGuestMessage(TelegramObject):
"""Describes an inline message sent by a guest bot.

Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`inline_message_id` are equal.

.. versionadded:: NEXT.VERSION

Args:
inline_message_id (:obj:`str`): Identifier of the sent inline message.

Attributes:
inline_message_id (:obj:`str`): Identifier of the sent inline message.
"""

__slots__ = ("inline_message_id",)

def __init__(
self,
inline_message_id: str,
*,
api_kwargs: JSONDict | None = None,
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.inline_message_id: str = inline_message_id

self._id_attrs = (self.inline_message_id,)

self._freeze()
Loading
Loading