This commit is contained in:
@@ -0,0 +1,337 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 InlineKeyboardButton."""
|
||||
|
||||
from typing import TYPE_CHECKING, Final, Optional, Union
|
||||
|
||||
from telegram import constants
|
||||
from telegram._copytextbutton import CopyTextButton
|
||||
from telegram._games.callbackgame import CallbackGame
|
||||
from telegram._loginurl import LoginUrl
|
||||
from telegram._switchinlinequerychosenchat import SwitchInlineQueryChosenChat
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
from telegram._webappinfo import WebAppInfo
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot
|
||||
|
||||
|
||||
class InlineKeyboardButton(TelegramObject):
|
||||
"""This object represents one button of an inline keyboard.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`text`, :attr:`url`, :attr:`login_url`, :attr:`callback_data`,
|
||||
:attr:`switch_inline_query`, :attr:`switch_inline_query_current_chat`, :attr:`callback_game`,
|
||||
:attr:`web_app` and :attr:`pay` are equal.
|
||||
|
||||
Note:
|
||||
* Exactly one of the optional fields must be used to specify type of the button.
|
||||
* Mind that :attr:`callback_game` is not
|
||||
working as expected. Putting a game short name in it might, but is not guaranteed to
|
||||
work.
|
||||
* If your bot allows for arbitrary callback data, in keyboards returned in a response
|
||||
from telegram, :attr:`callback_data` may be an instance of
|
||||
:class:`telegram.ext.InvalidCallbackData`. This will be the case, if the data
|
||||
associated with the button was already deleted.
|
||||
|
||||
.. versionadded:: 13.6
|
||||
|
||||
* Since Bot API 5.5, it's now allowed to mention users by their ID in inline keyboards.
|
||||
This will only work in Telegram versions released after December 7, 2021.
|
||||
Older clients will display *unsupported message*.
|
||||
|
||||
Warning:
|
||||
* If your bot allows your arbitrary callback data, buttons whose callback data is a
|
||||
non-hashable object will become unhashable. Trying to evaluate ``hash(button)`` will
|
||||
result in a :class:`TypeError`.
|
||||
|
||||
.. versionchanged:: 13.6
|
||||
|
||||
* After Bot API 6.1, only ``HTTPS`` links will be allowed in :paramref:`login_url`.
|
||||
|
||||
Examples:
|
||||
* :any:`Inline Keyboard 1 <examples.inlinekeyboard>`
|
||||
* :any:`Inline Keyboard 2 <examples.inlinekeyboard2>`
|
||||
|
||||
.. seealso:: :class:`telegram.InlineKeyboardMarkup`
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
:attr:`web_app` is considered as well when comparing objects of this type in terms of
|
||||
equality.
|
||||
|
||||
Args:
|
||||
text (:obj:`str`): Label text on the button.
|
||||
url (:obj:`str`, optional): HTTP or tg:// url to be opened when the button is pressed.
|
||||
Links ``tg://user?id=<user_id>`` can be used to mention a user by
|
||||
their ID without using a username, if this is allowed by their privacy settings.
|
||||
|
||||
.. versionchanged:: 13.9
|
||||
You can now mention a user using ``tg://user?id=<user_id>``.
|
||||
login_url (:class:`telegram.LoginUrl`, optional): An ``HTTPS`` URL used to automatically
|
||||
authorize the user. Can be used as a replacement for the Telegram Login Widget.
|
||||
|
||||
Caution:
|
||||
Only ``HTTPS`` links are allowed after Bot API 6.1.
|
||||
callback_data (:obj:`str` | :obj:`object`, optional): Data to be sent in a callback query
|
||||
to the bot when the button is pressed, UTF-8
|
||||
:tg-const:`telegram.InlineKeyboardButton.MIN_CALLBACK_DATA`-
|
||||
:tg-const:`telegram.InlineKeyboardButton.MAX_CALLBACK_DATA` bytes.
|
||||
If the bot instance allows arbitrary callback data, anything can be passed.
|
||||
|
||||
Tip:
|
||||
The value entered here will be available in :attr:`telegram.CallbackQuery.data`.
|
||||
|
||||
.. seealso:: :wiki:`Arbitrary callback_data <Arbitrary-callback_data>`
|
||||
|
||||
web_app (:class:`telegram.WebAppInfo`, optional): Description of the `Web App
|
||||
<https://core.telegram.org/bots/webapps>`_ that will be launched when the user presses
|
||||
the button. The Web App will be able to send an arbitrary message on behalf of the user
|
||||
using the method :meth:`~telegram.Bot.answer_web_app_query`. Available only in
|
||||
private chats between a user and the bot. Not supported for messages sent on behalf of
|
||||
a Telegram Business account.
|
||||
|
||||
.. versionadded:: 20.0
|
||||
switch_inline_query (:obj:`str`, optional): If set, pressing the button will prompt the
|
||||
user to select one of their chats, open that chat and insert the bot's username and the
|
||||
specified inline query in the input field. May be empty, in which case just the bot's
|
||||
username will be inserted. Not supported for messages sent on behalf of a Telegram
|
||||
Business account.
|
||||
|
||||
Tip:
|
||||
This is similar to the parameter :paramref:`switch_inline_query_chosen_chat`,
|
||||
but gives no control over which chats can be selected.
|
||||
switch_inline_query_current_chat (:obj:`str`, optional): If set, pressing the button will
|
||||
insert the bot's username and the specified inline query in the current chat's input
|
||||
field. May be empty, in which case only the bot's username will be inserted.
|
||||
|
||||
This offers a quick way for the user to open your bot in inline mode in the same chat
|
||||
- good for selecting something from multiple options. Not supported in channels and for
|
||||
messages sent on behalf of a Telegram Business account.
|
||||
copy_text (:class:`telegram.CopyTextButton`, optional): Description of the button that
|
||||
copies the specified text to the clipboard.
|
||||
|
||||
.. versionadded:: 21.7
|
||||
callback_game (:class:`telegram.CallbackGame`, optional): Description of the game that will
|
||||
be launched when the user presses the button
|
||||
|
||||
Note:
|
||||
This type of button **must** always be the first button in the first row.
|
||||
pay (:obj:`bool`, optional): Specify :obj:`True`, to send a Pay button.
|
||||
Substrings ``“⭐️”`` and ``“XTR”`` in the buttons's text will be replaced with a
|
||||
Telegram Star icon.
|
||||
|
||||
Note:
|
||||
This type of button **must** always be the first button in the first row and can
|
||||
only be used in invoice messages.
|
||||
switch_inline_query_chosen_chat (:class:`telegram.SwitchInlineQueryChosenChat`, optional):
|
||||
If set, pressing the button will prompt the user to select one of their chats of the
|
||||
specified type, open that chat and insert the bot's username and the specified inline
|
||||
query in the input field. Not supported for messages sent on behalf of a Telegram
|
||||
Business account.
|
||||
|
||||
.. versionadded:: 20.3
|
||||
|
||||
Tip:
|
||||
This is similar to :paramref:`switch_inline_query`, but gives more control on
|
||||
which chats can be selected.
|
||||
|
||||
Caution:
|
||||
The PTB team has discovered that this field works correctly only if your Telegram
|
||||
client is released after April 20th 2023.
|
||||
|
||||
Attributes:
|
||||
text (:obj:`str`): Label text on the button.
|
||||
url (:obj:`str`): Optional. HTTP or tg:// url to be opened when the button is pressed.
|
||||
Links ``tg://user?id=<user_id>`` can be used to mention a user by
|
||||
their ID without using a username, if this is allowed by their privacy settings.
|
||||
|
||||
.. versionchanged:: 13.9
|
||||
You can now mention a user using ``tg://user?id=<user_id>``.
|
||||
login_url (:class:`telegram.LoginUrl`): Optional. An ``HTTPS`` URL used to automatically
|
||||
authorize the user. Can be used as a replacement for the Telegram Login Widget.
|
||||
|
||||
Caution:
|
||||
Only ``HTTPS`` links are allowed after Bot API 6.1.
|
||||
callback_data (:obj:`str` | :obj:`object`): Optional. Data to be sent in a callback query
|
||||
to the bot when the button is pressed, UTF-8
|
||||
:tg-const:`telegram.InlineKeyboardButton.MIN_CALLBACK_DATA`-
|
||||
:tg-const:`telegram.InlineKeyboardButton.MAX_CALLBACK_DATA` bytes.
|
||||
web_app (:class:`telegram.WebAppInfo`): Optional. Description of the `Web App
|
||||
<https://core.telegram.org/bots/webapps>`_ that will be launched when the user presses
|
||||
the button. The Web App will be able to send an arbitrary message on behalf of the user
|
||||
using the method :meth:`~telegram.Bot.answer_web_app_query`. Available only in
|
||||
private chats between a user and the bot. Not supported for messages sent on behalf of
|
||||
a Telegram Business account.
|
||||
|
||||
.. versionadded:: 20.0
|
||||
switch_inline_query (:obj:`str`): Optional. If set, pressing the button will prompt the
|
||||
user to select one of their chats, open that chat and insert the bot's username and the
|
||||
specified inline query in the input field. May be empty, in which case just the bot's
|
||||
username will be inserted. Not supported for messages sent on behalf of a Telegram
|
||||
Business account.
|
||||
|
||||
Tip:
|
||||
This is similar to the parameter :paramref:`switch_inline_query_chosen_chat`,
|
||||
but gives no control over which chats can be selected.
|
||||
switch_inline_query_current_chat (:obj:`str`): Optional. If set, pressing the button will
|
||||
insert the bot's username and the specified inline query in the current chat's input
|
||||
field. May be empty, in which case only the bot's username will be inserted.
|
||||
|
||||
This offers a quick way for the user to open your bot in inline mode in the same chat
|
||||
- good for selecting something from multiple options. Not supported in channels and for
|
||||
messages sent on behalf of a Telegram Business account.
|
||||
copy_text (:class:`telegram.CopyTextButton`): Optional. Description of the button that
|
||||
copies the specified text to the clipboard.
|
||||
|
||||
.. versionadded:: 21.7
|
||||
callback_game (:class:`telegram.CallbackGame`): Optional. Description of the game that will
|
||||
be launched when the user presses the button.
|
||||
|
||||
Note:
|
||||
This type of button **must** always be the first button in the first row.
|
||||
pay (:obj:`bool`): Optional. Specify :obj:`True`, to send a Pay button.
|
||||
Substrings ``“⭐️”`` and ``“XTR”`` in the buttons's text will be replaced with a
|
||||
Telegram Star icon.
|
||||
|
||||
Note:
|
||||
This type of button **must** always be the first button in the first row and can
|
||||
only be used in invoice messages.
|
||||
switch_inline_query_chosen_chat (:class:`telegram.SwitchInlineQueryChosenChat`): Optional.
|
||||
If set, pressing the button will prompt the user to select one of their chats of the
|
||||
specified type, open that chat and insert the bot's username and the specified inline
|
||||
query in the input field. Not supported for messages sent on behalf of a Telegram
|
||||
Business account.
|
||||
|
||||
.. versionadded:: 20.3
|
||||
|
||||
Tip:
|
||||
This is similar to :attr:`switch_inline_query`, but gives more control on
|
||||
which chats can be selected.
|
||||
|
||||
Caution:
|
||||
The PTB team has discovered that this field works correctly only if your Telegram
|
||||
client is released after April 20th 2023.
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"callback_data",
|
||||
"callback_game",
|
||||
"copy_text",
|
||||
"login_url",
|
||||
"pay",
|
||||
"switch_inline_query",
|
||||
"switch_inline_query_chosen_chat",
|
||||
"switch_inline_query_current_chat",
|
||||
"text",
|
||||
"url",
|
||||
"web_app",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
text: str,
|
||||
url: Optional[str] = None,
|
||||
callback_data: Optional[Union[str, object]] = None,
|
||||
switch_inline_query: Optional[str] = None,
|
||||
switch_inline_query_current_chat: Optional[str] = None,
|
||||
callback_game: Optional[CallbackGame] = None,
|
||||
pay: Optional[bool] = None,
|
||||
login_url: Optional[LoginUrl] = None,
|
||||
web_app: Optional[WebAppInfo] = None,
|
||||
switch_inline_query_chosen_chat: Optional[SwitchInlineQueryChosenChat] = None,
|
||||
copy_text: Optional[CopyTextButton] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
# Required
|
||||
self.text: str = text
|
||||
|
||||
# Optionals
|
||||
self.url: Optional[str] = url
|
||||
self.login_url: Optional[LoginUrl] = login_url
|
||||
self.callback_data: Optional[Union[str, object]] = callback_data
|
||||
self.switch_inline_query: Optional[str] = switch_inline_query
|
||||
self.switch_inline_query_current_chat: Optional[str] = switch_inline_query_current_chat
|
||||
self.callback_game: Optional[CallbackGame] = callback_game
|
||||
self.pay: Optional[bool] = pay
|
||||
self.web_app: Optional[WebAppInfo] = web_app
|
||||
self.switch_inline_query_chosen_chat: Optional[SwitchInlineQueryChosenChat] = (
|
||||
switch_inline_query_chosen_chat
|
||||
)
|
||||
self.copy_text: Optional[CopyTextButton] = copy_text
|
||||
self._id_attrs = ()
|
||||
self._set_id_attrs()
|
||||
|
||||
self._freeze()
|
||||
|
||||
def _set_id_attrs(self) -> None:
|
||||
self._id_attrs = (
|
||||
self.text,
|
||||
self.url,
|
||||
self.login_url,
|
||||
self.callback_data,
|
||||
self.web_app,
|
||||
self.switch_inline_query,
|
||||
self.switch_inline_query_current_chat,
|
||||
self.callback_game,
|
||||
self.pay,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "InlineKeyboardButton":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["login_url"] = de_json_optional(data.get("login_url"), LoginUrl, bot)
|
||||
data["web_app"] = de_json_optional(data.get("web_app"), WebAppInfo, bot)
|
||||
data["callback_game"] = de_json_optional(data.get("callback_game"), CallbackGame, bot)
|
||||
data["switch_inline_query_chosen_chat"] = de_json_optional(
|
||||
data.get("switch_inline_query_chosen_chat"), SwitchInlineQueryChosenChat, bot
|
||||
)
|
||||
data["copy_text"] = de_json_optional(data.get("copy_text"), CopyTextButton, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
def update_callback_data(self, callback_data: Union[str, object]) -> None:
|
||||
"""
|
||||
Sets :attr:`callback_data` to the passed object. Intended to be used by
|
||||
:class:`telegram.ext.CallbackDataCache`.
|
||||
|
||||
.. versionadded:: 13.6
|
||||
|
||||
Args:
|
||||
callback_data (:class:`object`): The new callback data.
|
||||
"""
|
||||
with self._unfrozen():
|
||||
self.callback_data = callback_data
|
||||
self._set_id_attrs()
|
||||
|
||||
MIN_CALLBACK_DATA: Final[int] = constants.InlineKeyboardButtonLimit.MIN_CALLBACK_DATA
|
||||
""":const:`telegram.constants.InlineKeyboardButtonLimit.MIN_CALLBACK_DATA`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MAX_CALLBACK_DATA: Final[int] = constants.InlineKeyboardButtonLimit.MAX_CALLBACK_DATA
|
||||
""":const:`telegram.constants.InlineKeyboardButtonLimit.MAX_CALLBACK_DATA`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
@@ -0,0 +1,161 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 InlineKeyboardMarkup."""
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inlinekeyboardbutton import InlineKeyboardButton
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.markup import check_keyboard_type
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot
|
||||
|
||||
|
||||
class InlineKeyboardMarkup(TelegramObject):
|
||||
"""
|
||||
This object represents an inline keyboard that appears right next to the message it belongs to.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their size of :attr:`inline_keyboard` and all the buttons are equal.
|
||||
|
||||
.. figure:: https://core.telegram.org/file/464001863/110f3/I47qTXAD9Z4.120010/e0\
|
||||
ea04f66357b640ec
|
||||
:align: center
|
||||
|
||||
An inline keyboard on a message
|
||||
|
||||
.. seealso::
|
||||
Another kind of keyboard would be the :class:`telegram.ReplyKeyboardMarkup`.
|
||||
|
||||
Examples:
|
||||
* :any:`Inline Keyboard 1 <examples.inlinekeyboard>`
|
||||
* :any:`Inline Keyboard 2 <examples.inlinekeyboard2>`
|
||||
|
||||
Args:
|
||||
inline_keyboard (Sequence[Sequence[:class:`telegram.InlineKeyboardButton`]]): Sequence of
|
||||
button rows, each represented by a sequence of :class:`~telegram.InlineKeyboardButton`
|
||||
objects.
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
|
||||
Attributes:
|
||||
inline_keyboard (tuple[tuple[:class:`telegram.InlineKeyboardButton`]]): Tuple of
|
||||
button rows, each represented by a tuple of :class:`~telegram.InlineKeyboardButton`
|
||||
objects.
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|tupleclassattrs|
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ("inline_keyboard",)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
inline_keyboard: Sequence[Sequence[InlineKeyboardButton]],
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
if not check_keyboard_type(inline_keyboard):
|
||||
raise ValueError(
|
||||
"The parameter `inline_keyboard` should be a sequence of sequences of "
|
||||
"InlineKeyboardButtons"
|
||||
)
|
||||
# Required
|
||||
self.inline_keyboard: tuple[tuple[InlineKeyboardButton, ...], ...] = tuple(
|
||||
tuple(row) for row in inline_keyboard
|
||||
)
|
||||
|
||||
self._id_attrs = (self.inline_keyboard,)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "InlineKeyboardMarkup":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
|
||||
keyboard = []
|
||||
for row in data["inline_keyboard"]:
|
||||
tmp = []
|
||||
for col in row:
|
||||
btn = InlineKeyboardButton.de_json(col, bot)
|
||||
if btn:
|
||||
tmp.append(btn)
|
||||
keyboard.append(tmp)
|
||||
|
||||
return cls(keyboard)
|
||||
|
||||
@classmethod
|
||||
def from_button(cls, button: InlineKeyboardButton, **kwargs: object) -> "InlineKeyboardMarkup":
|
||||
"""Shortcut for::
|
||||
|
||||
InlineKeyboardMarkup([[button]], **kwargs)
|
||||
|
||||
Return an InlineKeyboardMarkup from a single InlineKeyboardButton
|
||||
|
||||
Args:
|
||||
button (:class:`telegram.InlineKeyboardButton`): The button to use in the markup
|
||||
|
||||
"""
|
||||
return cls([[button]], **kwargs) # type: ignore[arg-type]
|
||||
|
||||
@classmethod
|
||||
def from_row(
|
||||
cls, button_row: Sequence[InlineKeyboardButton], **kwargs: object
|
||||
) -> "InlineKeyboardMarkup":
|
||||
"""Shortcut for::
|
||||
|
||||
InlineKeyboardMarkup([button_row], **kwargs)
|
||||
|
||||
Return an InlineKeyboardMarkup from a single row of InlineKeyboardButtons
|
||||
|
||||
Args:
|
||||
button_row (Sequence[:class:`telegram.InlineKeyboardButton`]): The button to use
|
||||
in the markup
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceargs|
|
||||
|
||||
"""
|
||||
return cls([button_row], **kwargs) # type: ignore[arg-type]
|
||||
|
||||
@classmethod
|
||||
def from_column(
|
||||
cls, button_column: Sequence[InlineKeyboardButton], **kwargs: object
|
||||
) -> "InlineKeyboardMarkup":
|
||||
"""Shortcut for::
|
||||
|
||||
InlineKeyboardMarkup([[button] for button in button_column], **kwargs)
|
||||
|
||||
Return an InlineKeyboardMarkup from a single column of InlineKeyboardButtons
|
||||
|
||||
Args:
|
||||
button_column (Sequence[:class:`telegram.InlineKeyboardButton`]): The button to use
|
||||
in the markup
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceargs|
|
||||
|
||||
"""
|
||||
button_grid = [[button] for button in button_column]
|
||||
return cls(button_grid, **kwargs) # type: ignore[arg-type]
|
||||
@@ -0,0 +1,220 @@
|
||||
#!/usr/bin/env python
|
||||
# pylint: disable=too-many-arguments
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 InlineQuery."""
|
||||
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Callable, Final, Optional, Union
|
||||
|
||||
from telegram import constants
|
||||
from telegram._files.location import Location
|
||||
from telegram._inline.inlinequeryresultsbutton import InlineQueryResultsButton
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput, TimePeriod
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot, InlineQueryResult
|
||||
|
||||
|
||||
class InlineQuery(TelegramObject):
|
||||
"""
|
||||
This object represents an incoming inline query. When the user sends an empty query, your bot
|
||||
could return some default or trending results.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`id` is equal.
|
||||
|
||||
.. figure:: https://core.telegram.org/file/464001466/10e4a/r4FKyQ7gw5g.134366/f2\
|
||||
606a53d683374703
|
||||
:align: center
|
||||
|
||||
Inline queries on Telegram
|
||||
|
||||
.. seealso::
|
||||
The :class:`telegram.InlineQueryResult` classes represent the media the user can choose
|
||||
from (see above figure).
|
||||
|
||||
Note:
|
||||
In Python :keyword:`from` is a reserved word. Use :paramref:`from_user` instead.
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
The following are now keyword-only arguments in Bot methods:
|
||||
``{read, write, connect, pool}_timeout``, :paramref:`answer.api_kwargs`,
|
||||
``auto_pagination``. Use a named argument for those,
|
||||
and notice that some positional arguments changed position as a result.
|
||||
|
||||
.. versionchanged:: 22.0
|
||||
Removed constants ``MIN_START_PARAMETER_LENGTH`` and ``MAX_START_PARAMETER_LENGTH``.
|
||||
Use :attr:`telegram.constants.InlineQueryResultsButtonLimit.MIN_START_PARAMETER_LENGTH` and
|
||||
:attr:`telegram.constants.InlineQueryResultsButtonLimit.MAX_START_PARAMETER_LENGTH`
|
||||
instead.
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this query.
|
||||
from_user (:class:`telegram.User`): Sender.
|
||||
query (:obj:`str`): Text of the query (up to
|
||||
:tg-const:`telegram.InlineQuery.MAX_QUERY_LENGTH` characters).
|
||||
offset (:obj:`str`): Offset of the results to be returned, can be controlled by the bot.
|
||||
chat_type (:obj:`str`, optional): Type of the chat, from which the inline query was sent.
|
||||
Can be either :tg-const:`telegram.Chat.SENDER` for a private chat with the inline query
|
||||
sender, :tg-const:`telegram.Chat.PRIVATE`, :tg-const:`telegram.Chat.GROUP`,
|
||||
:tg-const:`telegram.Chat.SUPERGROUP` or :tg-const:`telegram.Chat.CHANNEL`. The chat
|
||||
type should be always known for requests sent from official clients and most
|
||||
third-party clients, unless the request was sent from a secret chat.
|
||||
|
||||
.. versionadded:: 13.5
|
||||
location (:class:`telegram.Location`, optional): Sender location, only for bots that
|
||||
request user location.
|
||||
|
||||
Attributes:
|
||||
id (:obj:`str`): Unique identifier for this query.
|
||||
from_user (:class:`telegram.User`): Sender.
|
||||
query (:obj:`str`): Text of the query (up to
|
||||
:tg-const:`telegram.InlineQuery.MAX_QUERY_LENGTH` characters).
|
||||
offset (:obj:`str`): Offset of the results to be returned, can be controlled by the bot.
|
||||
chat_type (:obj:`str`): Optional. Type of the chat, from which the inline query was sent.
|
||||
Can be either :tg-const:`telegram.Chat.SENDER` for a private chat with the inline query
|
||||
sender, :tg-const:`telegram.Chat.PRIVATE`, :tg-const:`telegram.Chat.GROUP`,
|
||||
:tg-const:`telegram.Chat.SUPERGROUP` or :tg-const:`telegram.Chat.CHANNEL`. The chat
|
||||
type should be always known for requests sent from official clients and most
|
||||
third-party clients, unless the request was sent from a secret chat.
|
||||
|
||||
.. versionadded:: 13.5
|
||||
location (:class:`telegram.Location`): Optional. Sender location, only for bots that
|
||||
request user location.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ("chat_type", "from_user", "id", "location", "offset", "query")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
from_user: User,
|
||||
query: str,
|
||||
offset: str,
|
||||
location: Optional[Location] = None,
|
||||
chat_type: Optional[str] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
# Required
|
||||
self.id: str = id
|
||||
self.from_user: User = from_user
|
||||
self.query: str = query
|
||||
self.offset: str = offset
|
||||
|
||||
# Optional
|
||||
self.location: Optional[Location] = location
|
||||
self.chat_type: Optional[str] = chat_type
|
||||
|
||||
self._id_attrs = (self.id,)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "InlineQuery":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["from_user"] = de_json_optional(data.pop("from", None), User, bot)
|
||||
data["location"] = de_json_optional(data.get("location"), Location, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
async def answer(
|
||||
self,
|
||||
results: Union[
|
||||
Sequence["InlineQueryResult"], Callable[[int], Optional[Sequence["InlineQueryResult"]]]
|
||||
],
|
||||
cache_time: Optional[TimePeriod] = None,
|
||||
is_personal: Optional[bool] = None,
|
||||
next_offset: Optional[str] = None,
|
||||
button: Optional[InlineQueryResultsButton] = None,
|
||||
*,
|
||||
current_offset: Optional[str] = None,
|
||||
auto_pagination: bool = False,
|
||||
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: Optional[JSONDict] = None,
|
||||
) -> bool:
|
||||
"""Shortcut for::
|
||||
|
||||
await bot.answer_inline_query(
|
||||
update.inline_query.id,
|
||||
*args,
|
||||
current_offset=self.offset if auto_pagination else None,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
For the documentation of the arguments, please see
|
||||
:meth:`telegram.Bot.answer_inline_query`.
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
Raises :class:`ValueError` instead of :class:`TypeError`.
|
||||
|
||||
Keyword Args:
|
||||
auto_pagination (:obj:`bool`, optional): If set to :obj:`True`, :attr:`offset` will be
|
||||
passed as
|
||||
:paramref:`current_offset <telegram.Bot.answer_inline_query.current_offset>` to
|
||||
:meth:`telegram.Bot.answer_inline_query`.
|
||||
Defaults to :obj:`False`.
|
||||
|
||||
Raises:
|
||||
ValueError: If both :paramref:`~telegram.Bot.answer_inline_query.current_offset` and
|
||||
:paramref:`auto_pagination` are supplied.
|
||||
"""
|
||||
if current_offset and auto_pagination:
|
||||
raise ValueError("current_offset and auto_pagination are mutually exclusive!")
|
||||
return await self.get_bot().answer_inline_query(
|
||||
inline_query_id=self.id,
|
||||
current_offset=self.offset if auto_pagination else current_offset,
|
||||
results=results,
|
||||
cache_time=cache_time,
|
||||
is_personal=is_personal,
|
||||
next_offset=next_offset,
|
||||
button=button,
|
||||
read_timeout=read_timeout,
|
||||
write_timeout=write_timeout,
|
||||
connect_timeout=connect_timeout,
|
||||
pool_timeout=pool_timeout,
|
||||
api_kwargs=api_kwargs,
|
||||
)
|
||||
|
||||
MAX_RESULTS: Final[int] = constants.InlineQueryLimit.RESULTS
|
||||
""":const:`telegram.constants.InlineQueryLimit.RESULTS`
|
||||
|
||||
.. versionadded:: 13.2
|
||||
"""
|
||||
MAX_OFFSET_LENGTH: Final[int] = constants.InlineQueryLimit.MAX_OFFSET_LENGTH
|
||||
""":const:`telegram.constants.InlineQueryLimit.MAX_OFFSET_LENGTH`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MAX_QUERY_LENGTH: Final[int] = constants.InlineQueryLimit.MAX_QUERY_LENGTH
|
||||
""":const:`telegram.constants.InlineQueryLimit.MAX_QUERY_LENGTH`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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/].
|
||||
# pylint: disable=redefined-builtin
|
||||
"""This module contains the classes that represent Telegram InlineQueryResult."""
|
||||
|
||||
from typing import Final, Optional
|
||||
|
||||
from telegram import constants
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
|
||||
class InlineQueryResult(TelegramObject):
|
||||
"""Baseclass for the InlineQueryResult* classes.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`id` is equal.
|
||||
|
||||
Note:
|
||||
All URLs passed in inline query results will be available to end users and therefore must
|
||||
be assumed to be *public*.
|
||||
|
||||
Examples:
|
||||
:any:`Inline Bot <examples.inlinebot>`
|
||||
|
||||
Args:
|
||||
type (:obj:`str`): Type of the result.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): Type of the result.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ("id", "type")
|
||||
|
||||
def __init__(self, type: str, id: str, *, api_kwargs: Optional[JSONDict] = None):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
|
||||
# Required
|
||||
self.type: str = enum.get_member(constants.InlineQueryResultType, type, type)
|
||||
self.id: str = str(id)
|
||||
|
||||
self._id_attrs = (self.id,)
|
||||
|
||||
self._freeze()
|
||||
|
||||
MIN_ID_LENGTH: Final[int] = constants.InlineQueryResultLimit.MIN_ID_LENGTH
|
||||
""":const:`telegram.constants.InlineQueryResultLimit.MIN_ID_LENGTH`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MAX_ID_LENGTH: Final[int] = constants.InlineQueryResultLimit.MAX_ID_LENGTH
|
||||
""":const:`telegram.constants.InlineQueryResultLimit.MAX_ID_LENGTH`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
@@ -0,0 +1,129 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultArticle."""
|
||||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._utils.types import JSONDict
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultArticle(InlineQueryResult):
|
||||
"""This object represents a Telegram InlineQueryResultArticle.
|
||||
|
||||
Examples:
|
||||
:any:`Inline Bot <examples.inlinebot>`
|
||||
|
||||
.. versionchanged:: 20.5
|
||||
Removed the deprecated arguments and attributes ``thumb_*``.
|
||||
|
||||
.. versionchanged:: 21.11
|
||||
Removed the deprecated argument and attribute ``hide_url``.
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
title (:obj:`str`): Title of the result.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Content of the message to
|
||||
be sent.
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
url (:obj:`str`, optional): URL of the result.
|
||||
|
||||
Tip:
|
||||
Pass an empty string as URL if you don't want the URL to be shown in the message.
|
||||
description (:obj:`str`, optional): Short description of the result.
|
||||
thumbnail_url (:obj:`str`, optional): Url of the thumbnail for the result.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_width (:obj:`int`, optional): Thumbnail width.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_height (:obj:`int`, optional): Thumbnail height.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.ARTICLE`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
title (:obj:`str`): Title of the result.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Content of the message to
|
||||
be sent.
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
url (:obj:`str`): Optional. URL of the result.
|
||||
description (:obj:`str`): Optional. Short description of the result.
|
||||
thumbnail_url (:obj:`str`): Optional. Url of the thumbnail for the result.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_width (:obj:`int`): Optional. Thumbnail width.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_height (:obj:`int`): Optional. Thumbnail height.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"description",
|
||||
"input_message_content",
|
||||
"reply_markup",
|
||||
"thumbnail_height",
|
||||
"thumbnail_url",
|
||||
"thumbnail_width",
|
||||
"title",
|
||||
"url",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
title: str,
|
||||
input_message_content: "InputMessageContent",
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
url: Optional[str] = None,
|
||||
description: Optional[str] = None,
|
||||
thumbnail_url: Optional[str] = None,
|
||||
thumbnail_width: Optional[int] = None,
|
||||
thumbnail_height: Optional[int] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.ARTICLE, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.title: str = title
|
||||
self.input_message_content: InputMessageContent = input_message_content
|
||||
|
||||
# Optional
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.url: Optional[str] = url
|
||||
self.description: Optional[str] = description
|
||||
self.thumbnail_url: Optional[str] = thumbnail_url
|
||||
self.thumbnail_width: Optional[int] = thumbnail_width
|
||||
self.thumbnail_height: Optional[int] = thumbnail_height
|
||||
@@ -0,0 +1,144 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultAudio."""
|
||||
import datetime as dtm
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional, Union
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg, to_timedelta
|
||||
from telegram._utils.datetime import get_timedelta_value
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput, TimePeriod
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultAudio(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to an mp3 audio file. By default, this audio file will be sent by the user.
|
||||
Alternatively, you can use :attr:`input_message_content` to send a message with the specified
|
||||
content instead of the audio.
|
||||
|
||||
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
audio_url (:obj:`str`): A valid URL for the audio file.
|
||||
title (:obj:`str`): Title.
|
||||
performer (:obj:`str`, optional): Performer.
|
||||
audio_duration (:obj:`int` | :class:`datetime.timedelta`, optional): Audio duration
|
||||
in seconds.
|
||||
|
||||
.. versionchanged:: v22.2
|
||||
|time-period-input|
|
||||
caption (:obj:`str`, optional): Caption,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
|
||||
parsing.
|
||||
parse_mode (:obj:`str`, optional): |parse_mode|
|
||||
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the audio.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.AUDIO`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
audio_url (:obj:`str`): A valid URL for the audio file.
|
||||
title (:obj:`str`): Title.
|
||||
performer (:obj:`str`): Optional. Performer.
|
||||
audio_duration (:obj:`int` | :class:`datetime.timedelta`): Optional. Audio duration
|
||||
in seconds.
|
||||
|
||||
.. deprecated:: v22.2
|
||||
|time-period-int-deprecated|
|
||||
caption (:obj:`str`): Optional. Caption,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
|
||||
parsing.
|
||||
parse_mode (:obj:`str`): Optional. |parse_mode|
|
||||
caption_entities (tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the audio.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"_audio_duration",
|
||||
"audio_url",
|
||||
"caption",
|
||||
"caption_entities",
|
||||
"input_message_content",
|
||||
"parse_mode",
|
||||
"performer",
|
||||
"reply_markup",
|
||||
"title",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
audio_url: str,
|
||||
title: str,
|
||||
performer: Optional[str] = None,
|
||||
audio_duration: Optional[TimePeriod] = None,
|
||||
caption: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
parse_mode: ODVInput[str] = DEFAULT_NONE,
|
||||
caption_entities: Optional[Sequence[MessageEntity]] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.AUDIO, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.audio_url: str = audio_url
|
||||
self.title: str = title
|
||||
|
||||
# Optionals
|
||||
self.performer: Optional[str] = performer
|
||||
self._audio_duration: Optional[dtm.timedelta] = to_timedelta(audio_duration)
|
||||
self.caption: Optional[str] = caption
|
||||
self.parse_mode: ODVInput[str] = parse_mode
|
||||
self.caption_entities: tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
|
||||
@property
|
||||
def audio_duration(self) -> Optional[Union[int, dtm.timedelta]]:
|
||||
return get_timedelta_value(self._audio_duration, attribute="audio_duration")
|
||||
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultCachedAudio."""
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedAudio(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to an mp3 audio file stored on the Telegram servers. By default, this audio
|
||||
file will be sent by the user. Alternatively, you can use :attr:`input_message_content` to
|
||||
send a message with the specified content instead of the audio.
|
||||
|
||||
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
audio_file_id (:obj:`str`): A valid file identifier for the audio file.
|
||||
caption (:obj:`str`, optional): Caption,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
|
||||
parsing.
|
||||
parse_mode (:obj:`str`, optional): |parse_mode|
|
||||
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the audio.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.AUDIO`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
audio_file_id (:obj:`str`): A valid file identifier for the audio file.
|
||||
caption (:obj:`str`): Optional. Caption,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
|
||||
parsing.
|
||||
parse_mode (:obj:`str`): Optional. |parse_mode|
|
||||
caption_entities (tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the audio.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"audio_file_id",
|
||||
"caption",
|
||||
"caption_entities",
|
||||
"input_message_content",
|
||||
"parse_mode",
|
||||
"reply_markup",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
audio_file_id: str,
|
||||
caption: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
parse_mode: ODVInput[str] = DEFAULT_NONE,
|
||||
caption_entities: Optional[Sequence[MessageEntity]] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.AUDIO, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.audio_file_id: str = audio_file_id
|
||||
|
||||
# Optionals
|
||||
self.caption: Optional[str] = caption
|
||||
self.parse_mode: ODVInput[str] = parse_mode
|
||||
self.caption_entities: tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
@@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultCachedDocument."""
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedDocument(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a file stored on the Telegram servers. By default, this file will be sent
|
||||
by the user with an optional caption. Alternatively, you can use :attr:`input_message_content`
|
||||
to send a message with the specified content instead of the file.
|
||||
|
||||
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
title (:obj:`str`): Title for the result.
|
||||
document_file_id (:obj:`str`): A valid file identifier for the file.
|
||||
description (:obj:`str`, optional): Short description of the result.
|
||||
caption (:obj:`str`, optional): Caption of the document to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
|
||||
after entities parsing.
|
||||
parse_mode (:obj:`str`, optional): |parse_mode|
|
||||
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the file.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.DOCUMENT`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
title (:obj:`str`): Title for the result.
|
||||
document_file_id (:obj:`str`): A valid file identifier for the file.
|
||||
description (:obj:`str`): Optional. Short description of the result.
|
||||
caption (:obj:`str`): Optional. Caption of the document to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
|
||||
after entities parsing.
|
||||
parse_mode (:obj:`str`): Optional. |parse_mode|
|
||||
caption_entities (tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the file.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"caption",
|
||||
"caption_entities",
|
||||
"description",
|
||||
"document_file_id",
|
||||
"input_message_content",
|
||||
"parse_mode",
|
||||
"reply_markup",
|
||||
"title",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
title: str,
|
||||
document_file_id: str,
|
||||
description: Optional[str] = None,
|
||||
caption: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
parse_mode: ODVInput[str] = DEFAULT_NONE,
|
||||
caption_entities: Optional[Sequence[MessageEntity]] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.DOCUMENT, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.title: str = title
|
||||
self.document_file_id: str = document_file_id
|
||||
|
||||
# Optionals
|
||||
self.description: Optional[str] = description
|
||||
self.caption: Optional[str] = caption
|
||||
self.parse_mode: ODVInput[str] = parse_mode
|
||||
self.caption_entities: tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultCachedGif."""
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedGif(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to an animated GIF file stored on the Telegram servers. By default, this
|
||||
animated GIF file will be sent by the user with an optional caption. Alternatively, you can
|
||||
use :attr:`input_message_content` to send a message with specified content instead of
|
||||
the animation.
|
||||
|
||||
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
gif_file_id (:obj:`str`): A valid file identifier for the GIF file.
|
||||
title (:obj:`str`, optional): Title for the result.
|
||||
caption (:obj:`str`, optional): Caption of the GIF file to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
|
||||
after entities parsing.
|
||||
parse_mode (:obj:`str`, optional): |parse_mode|
|
||||
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the gif.
|
||||
show_caption_above_media (:obj:`bool`, optional): Pass |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.GIF`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
gif_file_id (:obj:`str`): A valid file identifier for the GIF file.
|
||||
title (:obj:`str`): Optional. Title for the result.
|
||||
caption (:obj:`str`): Optional. Caption of the GIF file to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
|
||||
after entities parsing.
|
||||
parse_mode (:obj:`str`): Optional. |parse_mode|
|
||||
caption_entities (tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the gif.
|
||||
show_caption_above_media (:obj:`bool`): Optional. |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"caption",
|
||||
"caption_entities",
|
||||
"gif_file_id",
|
||||
"input_message_content",
|
||||
"parse_mode",
|
||||
"reply_markup",
|
||||
"show_caption_above_media",
|
||||
"title",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
gif_file_id: str,
|
||||
title: Optional[str] = None,
|
||||
caption: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
parse_mode: ODVInput[str] = DEFAULT_NONE,
|
||||
caption_entities: Optional[Sequence[MessageEntity]] = None,
|
||||
show_caption_above_media: Optional[bool] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.GIF, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.gif_file_id: str = gif_file_id
|
||||
|
||||
# Optionals
|
||||
self.title: Optional[str] = title
|
||||
self.caption: Optional[str] = caption
|
||||
self.parse_mode: ODVInput[str] = parse_mode
|
||||
self.caption_entities: tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
self.show_caption_above_media: Optional[bool] = show_caption_above_media
|
||||
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultMpeg4Gif."""
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the
|
||||
Telegram servers. By default, this animated MPEG-4 file will be sent by the user with an
|
||||
optional caption. Alternatively, you can use :attr:`input_message_content` to send a message
|
||||
with the specified content instead of the animation.
|
||||
|
||||
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
mpeg4_file_id (:obj:`str`): A valid file identifier for the MP4 file.
|
||||
title (:obj:`str`, optional): Title for the result.
|
||||
caption (:obj:`str`, optional): Caption of the MPEG-4 file to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
|
||||
after entities parsing.
|
||||
parse_mode (:obj:`str`, optional): |parse_mode|
|
||||
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the MPEG-4 file.
|
||||
show_caption_above_media (:obj:`bool`, optional): Pass |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.MPEG4GIF`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
mpeg4_file_id (:obj:`str`): A valid file identifier for the MP4 file.
|
||||
title (:obj:`str`): Optional. Title for the result.
|
||||
caption (:obj:`str`): Optional. Caption of the MPEG-4 file to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
|
||||
after entities parsing.
|
||||
parse_mode (:obj:`str`): Optional. |parse_mode|
|
||||
caption_entities (tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the MPEG-4 file.
|
||||
show_caption_above_media (:obj:`bool`): Optional. |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"caption",
|
||||
"caption_entities",
|
||||
"input_message_content",
|
||||
"mpeg4_file_id",
|
||||
"parse_mode",
|
||||
"reply_markup",
|
||||
"show_caption_above_media",
|
||||
"title",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
mpeg4_file_id: str,
|
||||
title: Optional[str] = None,
|
||||
caption: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
parse_mode: ODVInput[str] = DEFAULT_NONE,
|
||||
caption_entities: Optional[Sequence[MessageEntity]] = None,
|
||||
show_caption_above_media: Optional[bool] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.MPEG4GIF, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.mpeg4_file_id: str = mpeg4_file_id
|
||||
|
||||
# Optionals
|
||||
self.title: Optional[str] = title
|
||||
self.caption: Optional[str] = caption
|
||||
self.parse_mode: ODVInput[str] = parse_mode
|
||||
self.caption_entities: tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
self.show_caption_above_media: Optional[bool] = show_caption_above_media
|
||||
@@ -0,0 +1,136 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultPhoto"""
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedPhoto(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a photo stored on the Telegram servers. By default, this photo will be
|
||||
sent by the user with an optional caption. Alternatively, you can use
|
||||
:attr:`input_message_content` to send a message with the specified content instead
|
||||
of the photo.
|
||||
|
||||
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
photo_file_id (:obj:`str`): A valid file identifier of the photo.
|
||||
title (:obj:`str`, optional): Title for the result.
|
||||
description (:obj:`str`, optional): Short description of the result.
|
||||
caption (:obj:`str`, optional): Caption of the photo to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
|
||||
entities parsing.
|
||||
parse_mode (:obj:`str`, optional): |parse_mode|
|
||||
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the photo.
|
||||
show_caption_above_media (:obj:`bool`, optional): Pass |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.PHOTO`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
photo_file_id (:obj:`str`): A valid file identifier of the photo.
|
||||
title (:obj:`str`): Optional. Title for the result.
|
||||
description (:obj:`str`): Optional. Short description of the result.
|
||||
caption (:obj:`str`): Optional. Caption of the photo to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
|
||||
entities parsing.
|
||||
parse_mode (:obj:`str`): Optional. |parse_mode|
|
||||
caption_entities (tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the photo.
|
||||
show_caption_above_media (:obj:`bool`): Optional. |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"caption",
|
||||
"caption_entities",
|
||||
"description",
|
||||
"input_message_content",
|
||||
"parse_mode",
|
||||
"photo_file_id",
|
||||
"reply_markup",
|
||||
"show_caption_above_media",
|
||||
"title",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
photo_file_id: str,
|
||||
title: Optional[str] = None,
|
||||
description: Optional[str] = None,
|
||||
caption: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
parse_mode: ODVInput[str] = DEFAULT_NONE,
|
||||
caption_entities: Optional[Sequence[MessageEntity]] = None,
|
||||
show_caption_above_media: Optional[bool] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.PHOTO, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.photo_file_id: str = photo_file_id
|
||||
|
||||
# Optionals
|
||||
self.title: Optional[str] = title
|
||||
self.description: Optional[str] = description
|
||||
self.caption: Optional[str] = caption
|
||||
self.parse_mode: ODVInput[str] = parse_mode
|
||||
self.caption_entities: tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
self.show_caption_above_media: Optional[bool] = show_caption_above_media
|
||||
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultCachedSticker."""
|
||||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._utils.types import JSONDict
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedSticker(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a sticker stored on the Telegram servers. By default, this sticker will
|
||||
be sent by the user. Alternatively, you can use :attr:`input_message_content` to send a
|
||||
message with the specified content instead of the sticker.
|
||||
|
||||
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
sticker_file_id (:obj:`str`): A valid file identifier of the sticker.
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the sticker.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.STICKER`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
sticker_file_id (:obj:`str`): A valid file identifier of the sticker.
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the sticker.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ("input_message_content", "reply_markup", "sticker_file_id")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
sticker_file_id: str,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.STICKER, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.sticker_file_id: str = sticker_file_id
|
||||
|
||||
# Optionals
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
@@ -0,0 +1,132 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultCachedVideo."""
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedVideo(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a video file stored on the Telegram servers. By default, this video file
|
||||
will be sent by the user with an optional caption. Alternatively, you can use
|
||||
:attr:`input_message_content` to send a message with the specified content instead
|
||||
of the video.
|
||||
|
||||
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
video_file_id (:obj:`str`): A valid file identifier for the video file.
|
||||
title (:obj:`str`): Title for the result.
|
||||
description (:obj:`str`, optional): Short description of the result.
|
||||
caption (:obj:`str`, optional): Caption of the video to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
|
||||
entities parsing.
|
||||
parse_mode (:obj:`str`, optional): |parse_mode|
|
||||
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the video.
|
||||
show_caption_above_media (:obj:`bool`, optional): Pass |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.VIDEO`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
video_file_id (:obj:`str`): A valid file identifier for the video file.
|
||||
title (:obj:`str`): Title for the result.
|
||||
description (:obj:`str`): Optional. Short description of the result.
|
||||
caption (:obj:`str`): Optional. Caption of the video to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
|
||||
entities parsing.
|
||||
parse_mode (:obj:`str`): Optional. |parse_mode|
|
||||
caption_entities (tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the video.
|
||||
show_caption_above_media (:obj:`bool`): Optional. |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"caption",
|
||||
"caption_entities",
|
||||
"description",
|
||||
"input_message_content",
|
||||
"parse_mode",
|
||||
"reply_markup",
|
||||
"show_caption_above_media",
|
||||
"title",
|
||||
"video_file_id",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
video_file_id: str,
|
||||
title: str,
|
||||
description: Optional[str] = None,
|
||||
caption: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
parse_mode: ODVInput[str] = DEFAULT_NONE,
|
||||
caption_entities: Optional[Sequence[MessageEntity]] = None,
|
||||
show_caption_above_media: Optional[bool] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.VIDEO, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.video_file_id: str = video_file_id
|
||||
self.title: str = title
|
||||
|
||||
# Optionals
|
||||
self.description: Optional[str] = description
|
||||
self.caption: Optional[str] = caption
|
||||
self.parse_mode: ODVInput[str] = parse_mode
|
||||
self.caption_entities: tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
self.show_caption_above_media: Optional[bool] = show_caption_above_media
|
||||
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultCachedVoice."""
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedVoice(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a voice message stored on the Telegram servers. By default, this voice
|
||||
message will be sent by the user. Alternatively, you can use :attr:`input_message_content` to
|
||||
send a message with the specified content instead of the voice message.
|
||||
|
||||
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
voice_file_id (:obj:`str`): A valid file identifier for the voice message.
|
||||
title (:obj:`str`): Voice message title.
|
||||
caption (:obj:`str`, optional): Caption,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
|
||||
parsing.
|
||||
parse_mode (:obj:`str`, optional): |parse_mode|
|
||||
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional):
|
||||
|captionentitiesattr|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the voice message.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.VOICE`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
voice_file_id (:obj:`str`): A valid file identifier for the voice message.
|
||||
title (:obj:`str`): Voice message title.
|
||||
caption (:obj:`str`): Optional. Caption,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
|
||||
parsing.
|
||||
parse_mode (:obj:`str`): Optional. |parse_mode|
|
||||
caption_entities (tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the voice message.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"caption",
|
||||
"caption_entities",
|
||||
"input_message_content",
|
||||
"parse_mode",
|
||||
"reply_markup",
|
||||
"title",
|
||||
"voice_file_id",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
voice_file_id: str,
|
||||
title: str,
|
||||
caption: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
parse_mode: ODVInput[str] = DEFAULT_NONE,
|
||||
caption_entities: Optional[Sequence[MessageEntity]] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.VOICE, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.voice_file_id: str = voice_file_id
|
||||
self.title: str = title
|
||||
|
||||
# Optionals
|
||||
self.caption: Optional[str] = caption
|
||||
self.parse_mode: ODVInput[str] = parse_mode
|
||||
self.caption_entities: tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultContact."""
|
||||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._utils.types import JSONDict
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultContact(InlineQueryResult):
|
||||
"""
|
||||
Represents a contact with a phone number. By default, this contact will be sent by the user.
|
||||
Alternatively, you can use :attr:`input_message_content` to send a message with the specified
|
||||
content instead of the contact.
|
||||
|
||||
.. versionchanged:: 20.5
|
||||
|removed_thumb_wildcard_note|
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
phone_number (:obj:`str`): Contact's phone number.
|
||||
first_name (:obj:`str`): Contact's first name.
|
||||
last_name (:obj:`str`, optional): Contact's last name.
|
||||
vcard (:obj:`str`, optional): Additional data about the contact in the form of a vCard,
|
||||
0-:tg-const:`telegram.constants.ContactLimit.VCARD` bytes.
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the contact.
|
||||
thumbnail_url (:obj:`str`, optional): Url of the thumbnail for the result.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_width (:obj:`int`, optional): Thumbnail width.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_height (:obj:`int`, optional): Thumbnail height.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.CONTACT`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
phone_number (:obj:`str`): Contact's phone number.
|
||||
first_name (:obj:`str`): Contact's first name.
|
||||
last_name (:obj:`str`): Optional. Contact's last name.
|
||||
vcard (:obj:`str`): Optional. Additional data about the contact in the form of a vCard,
|
||||
0-:tg-const:`telegram.constants.ContactLimit.VCARD` bytes.
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the contact.
|
||||
thumbnail_url (:obj:`str`): Optional. Url of the thumbnail for the result.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_width (:obj:`int`): Optional. Thumbnail width.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_height (:obj:`int`): Optional. Thumbnail height.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"first_name",
|
||||
"input_message_content",
|
||||
"last_name",
|
||||
"phone_number",
|
||||
"reply_markup",
|
||||
"thumbnail_height",
|
||||
"thumbnail_url",
|
||||
"thumbnail_width",
|
||||
"vcard",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
phone_number: str,
|
||||
first_name: str,
|
||||
last_name: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
vcard: Optional[str] = None,
|
||||
thumbnail_url: Optional[str] = None,
|
||||
thumbnail_width: Optional[int] = None,
|
||||
thumbnail_height: Optional[int] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.CONTACT, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.phone_number: str = phone_number
|
||||
self.first_name: str = first_name
|
||||
|
||||
# Optionals
|
||||
self.last_name: Optional[str] = last_name
|
||||
self.vcard: Optional[str] = vcard
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
self.thumbnail_url: Optional[str] = thumbnail_url
|
||||
self.thumbnail_width: Optional[int] = thumbnail_width
|
||||
self.thumbnail_height: Optional[int] = thumbnail_height
|
||||
@@ -0,0 +1,165 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultDocument"""
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultDocument(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a file. By default, this file will be sent by the user with an optional
|
||||
caption. Alternatively, you can use :attr:`input_message_content` to send a message with the
|
||||
specified content instead of the file. Currently, only .PDF and .ZIP files can be sent
|
||||
using this method.
|
||||
|
||||
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
|
||||
|
||||
.. versionchanged:: 20.5
|
||||
|removed_thumb_wildcard_note|
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
title (:obj:`str`): Title for the result.
|
||||
caption (:obj:`str`, optional): Caption of the document to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
|
||||
after entities parsing.
|
||||
parse_mode (:obj:`str`, optional): |parse_mode|
|
||||
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
|
||||
document_url (:obj:`str`): A valid URL for the file.
|
||||
mime_type (:obj:`str`): Mime type of the content of the file, either "application/pdf"
|
||||
or "application/zip".
|
||||
description (:obj:`str`, optional): Short description of the result.
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the file.
|
||||
thumbnail_url (:obj:`str`, optional): URL of the thumbnail (JPEG only) for the file.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_width (:obj:`int`, optional): Thumbnail width.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_height (:obj:`int`, optional): Thumbnail height.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.DOCUMENT`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
title (:obj:`str`): Title for the result.
|
||||
caption (:obj:`str`): Optional. Caption of the document to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
|
||||
after entities parsing.
|
||||
parse_mode (:obj:`str`): Optional. |parse_mode|
|
||||
caption_entities (tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
document_url (:obj:`str`): A valid URL for the file.
|
||||
mime_type (:obj:`str`): Mime type of the content of the file, either "application/pdf"
|
||||
or "application/zip".
|
||||
description (:obj:`str`): Optional. Short description of the result.
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the file.
|
||||
thumbnail_url (:obj:`str`): Optional. URL of the thumbnail (JPEG only) for the file.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_width (:obj:`int`): Optional. Thumbnail width.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_height (:obj:`int`): Optional. Thumbnail height.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"caption",
|
||||
"caption_entities",
|
||||
"description",
|
||||
"document_url",
|
||||
"input_message_content",
|
||||
"mime_type",
|
||||
"parse_mode",
|
||||
"reply_markup",
|
||||
"thumbnail_height",
|
||||
"thumbnail_url",
|
||||
"thumbnail_width",
|
||||
"title",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
document_url: str,
|
||||
title: str,
|
||||
mime_type: str,
|
||||
caption: Optional[str] = None,
|
||||
description: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
parse_mode: ODVInput[str] = DEFAULT_NONE,
|
||||
caption_entities: Optional[Sequence[MessageEntity]] = None,
|
||||
thumbnail_url: Optional[str] = None,
|
||||
thumbnail_width: Optional[int] = None,
|
||||
thumbnail_height: Optional[int] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.DOCUMENT, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.document_url: str = document_url
|
||||
self.title: str = title
|
||||
self.mime_type: str = mime_type
|
||||
|
||||
# Optionals
|
||||
self.caption: Optional[str] = caption
|
||||
self.parse_mode: ODVInput[str] = parse_mode
|
||||
self.caption_entities: tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
|
||||
self.description: Optional[str] = description
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
self.thumbnail_url: Optional[str] = thumbnail_url
|
||||
self.thumbnail_width: Optional[int] = thumbnail_width
|
||||
self.thumbnail_height: Optional[int] = thumbnail_height
|
||||
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultGame."""
|
||||
from typing import Optional
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._utils.types import JSONDict
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
|
||||
class InlineQueryResultGame(InlineQueryResult):
|
||||
"""Represents a :class:`telegram.Game`.
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
game_short_name (:obj:`str`): Short name of the game.
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.GAME`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
game_short_name (:obj:`str`): Short name of the game.
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ("game_short_name", "reply_markup")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
game_short_name: str,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.GAME, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.id: str = id
|
||||
self.game_short_name: str = game_short_name
|
||||
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
@@ -0,0 +1,188 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultGif."""
|
||||
import datetime as dtm
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional, Union
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg, to_timedelta
|
||||
from telegram._utils.datetime import get_timedelta_value
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput, TimePeriod
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultGif(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to an animated GIF file. By default, this animated GIF file will be sent by
|
||||
the user with optional caption. Alternatively, you can use :attr:`input_message_content` to
|
||||
send a message with the specified content instead of the animation.
|
||||
|
||||
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
|
||||
|
||||
.. versionchanged:: 20.5
|
||||
|removed_thumb_wildcard_note|
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
gif_url (:obj:`str`): A valid URL for the GIF file.
|
||||
gif_width (:obj:`int`, optional): Width of the GIF.
|
||||
gif_height (:obj:`int`, optional): Height of the GIF.
|
||||
gif_duration (:obj:`int` | :class:`datetime.timedelta`, optional): Duration of the GIF
|
||||
in seconds.
|
||||
|
||||
.. versionchanged:: v22.2
|
||||
|time-period-input|
|
||||
thumbnail_url (:obj:`str`): URL of the static (JPEG or GIF) or animated (MPEG4)
|
||||
thumbnail for the result.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
|
||||
..versionchanged:: 20.5
|
||||
|thumbnail_url_mandatory|
|
||||
|
||||
thumbnail_mime_type (:obj:`str`, optional): MIME type of the thumbnail, must be one of
|
||||
``'image/jpeg'``, ``'image/gif'``, or ``'video/mp4'``. Defaults to ``'image/jpeg'``.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
title (:obj:`str`, optional): Title for the result.
|
||||
caption (:obj:`str`, optional): Caption of the GIF file to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
|
||||
after entities parsing.
|
||||
parse_mode (:obj:`str`, optional): |parse_mode|
|
||||
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the GIF animation.
|
||||
show_caption_above_media (:obj:`bool`, optional): Pass |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.GIF`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
gif_url (:obj:`str`): A valid URL for the GIF file.
|
||||
gif_width (:obj:`int`): Optional. Width of the GIF.
|
||||
gif_height (:obj:`int`): Optional. Height of the GIF.
|
||||
gif_duration (:obj:`int` | :class:`datetime.timedelta`): Optional. Duration of the GIF
|
||||
in seconds.
|
||||
|
||||
.. deprecated:: v22.2
|
||||
|time-period-int-deprecated|
|
||||
thumbnail_url (:obj:`str`): URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail
|
||||
for the result.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_mime_type (:obj:`str`): Optional. MIME type of the thumbnail, must be one of
|
||||
``'image/jpeg'``, ``'image/gif'``, or ``'video/mp4'``. Defaults to ``'image/jpeg'``.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
title (:obj:`str`): Optional. Title for the result.
|
||||
caption (:obj:`str`): Optional. Caption of the GIF file to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
|
||||
after entities parsing.
|
||||
parse_mode (:obj:`str`): Optional. |parse_mode|
|
||||
caption_entities (tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the GIF animation.
|
||||
show_caption_above_media (:obj:`bool`): Optional. |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"_gif_duration",
|
||||
"caption",
|
||||
"caption_entities",
|
||||
"gif_height",
|
||||
"gif_url",
|
||||
"gif_width",
|
||||
"input_message_content",
|
||||
"parse_mode",
|
||||
"reply_markup",
|
||||
"show_caption_above_media",
|
||||
"thumbnail_mime_type",
|
||||
"thumbnail_url",
|
||||
"title",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
gif_url: str,
|
||||
thumbnail_url: str,
|
||||
gif_width: Optional[int] = None,
|
||||
gif_height: Optional[int] = None,
|
||||
title: Optional[str] = None,
|
||||
caption: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
gif_duration: Optional[TimePeriod] = None,
|
||||
parse_mode: ODVInput[str] = DEFAULT_NONE,
|
||||
caption_entities: Optional[Sequence[MessageEntity]] = None,
|
||||
thumbnail_mime_type: Optional[str] = None,
|
||||
show_caption_above_media: Optional[bool] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.GIF, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.gif_url: str = gif_url
|
||||
self.thumbnail_url: str = thumbnail_url
|
||||
|
||||
# Optionals
|
||||
self.gif_width: Optional[int] = gif_width
|
||||
self.gif_height: Optional[int] = gif_height
|
||||
self._gif_duration: Optional[dtm.timedelta] = to_timedelta(gif_duration)
|
||||
self.title: Optional[str] = title
|
||||
self.caption: Optional[str] = caption
|
||||
self.parse_mode: ODVInput[str] = parse_mode
|
||||
self.caption_entities: tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
self.thumbnail_mime_type: Optional[str] = thumbnail_mime_type
|
||||
self.show_caption_above_media: Optional[bool] = show_caption_above_media
|
||||
|
||||
@property
|
||||
def gif_duration(self) -> Optional[Union[int, dtm.timedelta]]:
|
||||
return get_timedelta_value(self._gif_duration, attribute="gif_duration")
|
||||
@@ -0,0 +1,220 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultLocation."""
|
||||
|
||||
import datetime as dtm
|
||||
from typing import TYPE_CHECKING, Final, Optional, Union
|
||||
|
||||
from telegram import constants
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._utils.argumentparsing import to_timedelta
|
||||
from telegram._utils.datetime import get_timedelta_value
|
||||
from telegram._utils.types import JSONDict, TimePeriod
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultLocation(InlineQueryResult):
|
||||
"""
|
||||
Represents a location on a map. By default, the location will be sent by the user.
|
||||
Alternatively, you can use :attr:`input_message_content` to send a message with the specified
|
||||
content instead of the location.
|
||||
|
||||
.. versionchanged:: 20.5
|
||||
|removed_thumb_wildcard_note|
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
latitude (:obj:`float`): Location latitude in degrees.
|
||||
longitude (:obj:`float`): Location longitude in degrees.
|
||||
title (:obj:`str`): Location title.
|
||||
horizontal_accuracy (:obj:`float`, optional): The radius of uncertainty for the location,
|
||||
measured in meters; 0-
|
||||
:tg-const:`telegram.InlineQueryResultLocation.HORIZONTAL_ACCURACY`.
|
||||
live_period (:obj:`int` | :class:`datetime.timedelta`, optional): Period in seconds for
|
||||
which the location will be updated, should be between
|
||||
:tg-const:`telegram.InlineQueryResultLocation.MIN_LIVE_PERIOD` and
|
||||
:tg-const:`telegram.InlineQueryResultLocation.MAX_LIVE_PERIOD`.
|
||||
|
||||
.. versionchanged:: v22.2
|
||||
|time-period-input|
|
||||
heading (:obj:`int`, optional): For live locations, a direction in which the user is
|
||||
moving, in degrees. Must be between
|
||||
:tg-const:`telegram.InlineQueryResultLocation.MIN_HEADING` and
|
||||
:tg-const:`telegram.InlineQueryResultLocation.MAX_HEADING` if specified.
|
||||
proximity_alert_radius (:obj:`int`, optional): For live locations, a maximum distance
|
||||
for proximity alerts about approaching another chat member, in meters. Must be
|
||||
between :tg-const:`telegram.InlineQueryResultLocation.MIN_PROXIMITY_ALERT_RADIUS`
|
||||
and :tg-const:`telegram.InlineQueryResultLocation.MAX_PROXIMITY_ALERT_RADIUS`
|
||||
if specified.
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the location.
|
||||
thumbnail_url (:obj:`str`, optional): Url of the thumbnail for the result.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_width (:obj:`int`, optional): Thumbnail width.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_height (:obj:`int`, optional): Thumbnail height.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.LOCATION`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
latitude (:obj:`float`): Location latitude in degrees.
|
||||
longitude (:obj:`float`): Location longitude in degrees.
|
||||
title (:obj:`str`): Location title.
|
||||
horizontal_accuracy (:obj:`float`): Optional. The radius of uncertainty for the location,
|
||||
measured in meters; 0-
|
||||
:tg-const:`telegram.InlineQueryResultLocation.HORIZONTAL_ACCURACY`.
|
||||
live_period (:obj:`int` | :class:`datetime.timedelta`): Optional. Period in seconds for
|
||||
which the location will be updated, should be between
|
||||
:tg-const:`telegram.InlineQueryResultLocation.MIN_LIVE_PERIOD` and
|
||||
:tg-const:`telegram.InlineQueryResultLocation.MAX_LIVE_PERIOD` or
|
||||
:tg-const:`telegram.constants.LocationLimit.LIVE_PERIOD_FOREVER` for live
|
||||
locations that can be edited indefinitely.
|
||||
|
||||
.. deprecated:: v22.2
|
||||
|time-period-int-deprecated|
|
||||
heading (:obj:`int`): Optional. For live locations, a direction in which the user is
|
||||
moving, in degrees. Must be between
|
||||
:tg-const:`telegram.InlineQueryResultLocation.MIN_HEADING` and
|
||||
:tg-const:`telegram.InlineQueryResultLocation.MAX_HEADING` if specified.
|
||||
proximity_alert_radius (:obj:`int`): Optional. For live locations, a maximum distance
|
||||
for proximity alerts about approaching another chat member, in meters. Must be
|
||||
between :tg-const:`telegram.InlineQueryResultLocation.MIN_PROXIMITY_ALERT_RADIUS`
|
||||
and :tg-const:`telegram.InlineQueryResultLocation.MAX_PROXIMITY_ALERT_RADIUS`
|
||||
if specified.
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the location.
|
||||
thumbnail_url (:obj:`str`): Optional. Url of the thumbnail for the result.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_width (:obj:`int`): Optional. Thumbnail width.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_height (:obj:`int`): Optional. Thumbnail height.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"_live_period",
|
||||
"heading",
|
||||
"horizontal_accuracy",
|
||||
"input_message_content",
|
||||
"latitude",
|
||||
"longitude",
|
||||
"proximity_alert_radius",
|
||||
"reply_markup",
|
||||
"thumbnail_height",
|
||||
"thumbnail_url",
|
||||
"thumbnail_width",
|
||||
"title",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
latitude: float,
|
||||
longitude: float,
|
||||
title: str,
|
||||
live_period: Optional[TimePeriod] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
horizontal_accuracy: Optional[float] = None,
|
||||
heading: Optional[int] = None,
|
||||
proximity_alert_radius: Optional[int] = None,
|
||||
thumbnail_url: Optional[str] = None,
|
||||
thumbnail_width: Optional[int] = None,
|
||||
thumbnail_height: Optional[int] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(constants.InlineQueryResultType.LOCATION, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.latitude: float = latitude
|
||||
self.longitude: float = longitude
|
||||
self.title: str = title
|
||||
|
||||
# Optionals
|
||||
self._live_period: Optional[dtm.timedelta] = to_timedelta(live_period)
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
self.thumbnail_url: Optional[str] = thumbnail_url
|
||||
self.thumbnail_width: Optional[int] = thumbnail_width
|
||||
self.thumbnail_height: Optional[int] = thumbnail_height
|
||||
self.horizontal_accuracy: Optional[float] = horizontal_accuracy
|
||||
self.heading: Optional[int] = heading
|
||||
self.proximity_alert_radius: Optional[int] = (
|
||||
int(proximity_alert_radius) if proximity_alert_radius else None
|
||||
)
|
||||
|
||||
@property
|
||||
def live_period(self) -> Optional[Union[int, dtm.timedelta]]:
|
||||
return get_timedelta_value(self._live_period, attribute="live_period")
|
||||
|
||||
HORIZONTAL_ACCURACY: Final[int] = constants.LocationLimit.HORIZONTAL_ACCURACY
|
||||
""":const:`telegram.constants.LocationLimit.HORIZONTAL_ACCURACY`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MIN_HEADING: Final[int] = constants.LocationLimit.MIN_HEADING
|
||||
""":const:`telegram.constants.LocationLimit.MIN_HEADING`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MAX_HEADING: Final[int] = constants.LocationLimit.MAX_HEADING
|
||||
""":const:`telegram.constants.LocationLimit.MAX_HEADING`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MIN_LIVE_PERIOD: Final[int] = constants.LocationLimit.MIN_LIVE_PERIOD
|
||||
""":const:`telegram.constants.LocationLimit.MIN_LIVE_PERIOD`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MAX_LIVE_PERIOD: Final[int] = constants.LocationLimit.MAX_LIVE_PERIOD
|
||||
""":const:`telegram.constants.LocationLimit.MAX_LIVE_PERIOD`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MIN_PROXIMITY_ALERT_RADIUS: Final[int] = constants.LocationLimit.MIN_PROXIMITY_ALERT_RADIUS
|
||||
""":const:`telegram.constants.LocationLimit.MIN_PROXIMITY_ALERT_RADIUS`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MAX_PROXIMITY_ALERT_RADIUS: Final[int] = constants.LocationLimit.MAX_PROXIMITY_ALERT_RADIUS
|
||||
""":const:`telegram.constants.LocationLimit.MAX_PROXIMITY_ALERT_RADIUS`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
@@ -0,0 +1,190 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultMpeg4Gif."""
|
||||
import datetime as dtm
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional, Union
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg, to_timedelta
|
||||
from telegram._utils.datetime import get_timedelta_value
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput, TimePeriod
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, this
|
||||
animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can
|
||||
use :attr:`input_message_content` to send a message with the specified content instead of the
|
||||
animation.
|
||||
|
||||
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
|
||||
|
||||
.. versionchanged:: 20.5
|
||||
|removed_thumb_wildcard_note|
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
mpeg4_url (:obj:`str`): A valid URL for the MP4 file.
|
||||
mpeg4_width (:obj:`int`, optional): Video width.
|
||||
mpeg4_height (:obj:`int`, optional): Video height.
|
||||
mpeg4_duration (:obj:`int` | :class:`datetime.timedelta`, optional): Video duration
|
||||
in seconds.
|
||||
|
||||
.. versionchanged:: v22.2
|
||||
|time-period-input|
|
||||
thumbnail_url (:obj:`str`): URL of the static (JPEG or GIF) or animated (MPEG4)
|
||||
thumbnail for the result.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
|
||||
..versionchanged:: 20.5
|
||||
|thumbnail_url_mandatory|
|
||||
|
||||
thumbnail_mime_type (:obj:`str`, optional): MIME type of the thumbnail, must be one of
|
||||
``'image/jpeg'``, ``'image/gif'``, or ``'video/mp4'``. Defaults to ``'image/jpeg'``.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
title (:obj:`str`, optional): Title for the result.
|
||||
caption (:obj:`str`, optional): Caption of the MPEG-4 file to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
|
||||
after entities parsing.
|
||||
parse_mode (:obj:`str`, optional): |parse_mode|
|
||||
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional):
|
||||
|captionentitiesattr|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the video animation.
|
||||
show_caption_above_media (:obj:`bool`, optional): Pass |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.MPEG4GIF`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
mpeg4_url (:obj:`str`): A valid URL for the MP4 file.
|
||||
mpeg4_width (:obj:`int`): Optional. Video width.
|
||||
mpeg4_height (:obj:`int`): Optional. Video height.
|
||||
mpeg4_duration (:obj:`int` | :class:`datetime.timedelta`): Optional. Video duration
|
||||
in seconds.
|
||||
|
||||
.. deprecated:: v22.2
|
||||
|time-period-int-deprecated|
|
||||
thumbnail_url (:obj:`str`): URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail
|
||||
for the result.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_mime_type (:obj:`str`): Optional. MIME type of the thumbnail, must be one of
|
||||
``'image/jpeg'``, ``'image/gif'``, or ``'video/mp4'``. Defaults to ``'image/jpeg'``.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
title (:obj:`str`): Optional. Title for the result.
|
||||
caption (:obj:`str`): Optional. Caption of the MPEG-4 file to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
|
||||
after entities parsing.
|
||||
parse_mode (:obj:`str`): Optional. |parse_mode|
|
||||
caption_entities (tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the video animation.
|
||||
show_caption_above_media (:obj:`bool`): Optional. |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"_mpeg4_duration",
|
||||
"caption",
|
||||
"caption_entities",
|
||||
"input_message_content",
|
||||
"mpeg4_height",
|
||||
"mpeg4_url",
|
||||
"mpeg4_width",
|
||||
"parse_mode",
|
||||
"reply_markup",
|
||||
"show_caption_above_media",
|
||||
"thumbnail_mime_type",
|
||||
"thumbnail_url",
|
||||
"title",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
mpeg4_url: str,
|
||||
thumbnail_url: str,
|
||||
mpeg4_width: Optional[int] = None,
|
||||
mpeg4_height: Optional[int] = None,
|
||||
title: Optional[str] = None,
|
||||
caption: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
mpeg4_duration: Optional[TimePeriod] = None,
|
||||
parse_mode: ODVInput[str] = DEFAULT_NONE,
|
||||
caption_entities: Optional[Sequence[MessageEntity]] = None,
|
||||
thumbnail_mime_type: Optional[str] = None,
|
||||
show_caption_above_media: Optional[bool] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.MPEG4GIF, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.mpeg4_url: str = mpeg4_url
|
||||
self.thumbnail_url: str = thumbnail_url
|
||||
|
||||
# Optional
|
||||
self.mpeg4_width: Optional[int] = mpeg4_width
|
||||
self.mpeg4_height: Optional[int] = mpeg4_height
|
||||
self._mpeg4_duration: Optional[dtm.timedelta] = to_timedelta(mpeg4_duration)
|
||||
self.title: Optional[str] = title
|
||||
self.caption: Optional[str] = caption
|
||||
self.parse_mode: ODVInput[str] = parse_mode
|
||||
self.caption_entities: tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
self.thumbnail_mime_type: Optional[str] = thumbnail_mime_type
|
||||
self.show_caption_above_media: Optional[bool] = show_caption_above_media
|
||||
|
||||
@property
|
||||
def mpeg4_duration(self) -> Optional[Union[int, dtm.timedelta]]:
|
||||
return get_timedelta_value(self._mpeg4_duration, attribute="mpeg4_duration")
|
||||
@@ -0,0 +1,161 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultPhoto."""
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultPhoto(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a photo. By default, this photo will be sent by the user with optional
|
||||
caption. Alternatively, you can use :attr:`input_message_content` to send a message with the
|
||||
specified content instead of the photo.
|
||||
|
||||
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
|
||||
|
||||
.. versionchanged:: 20.5
|
||||
|removed_thumb_url_note|
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
photo_url (:obj:`str`): A valid URL of the photo. Photo must be in JPEG format. Photo size
|
||||
must not exceed 5MB.
|
||||
thumbnail_url (:obj:`str`): URL of the thumbnail for the photo.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
|
||||
..versionchanged:: 20.5
|
||||
|thumbnail_url_mandatory|
|
||||
|
||||
photo_width (:obj:`int`, optional): Width of the photo.
|
||||
photo_height (:obj:`int`, optional): Height of the photo.
|
||||
title (:obj:`str`, optional): Title for the result.
|
||||
description (:obj:`str`, optional): Short description of the result.
|
||||
caption (:obj:`str`, optional): Caption of the photo to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
|
||||
entities parsing.
|
||||
parse_mode (:obj:`str`, optional): |parse_mode|
|
||||
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the photo.
|
||||
show_caption_above_media (:obj:`bool`, optional): Pass |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.PHOTO`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
photo_url (:obj:`str`): A valid URL of the photo. Photo must be in JPEG format. Photo size
|
||||
must not exceed 5MB.
|
||||
thumbnail_url (:obj:`str`): URL of the thumbnail for the photo.
|
||||
photo_width (:obj:`int`): Optional. Width of the photo.
|
||||
photo_height (:obj:`int`): Optional. Height of the photo.
|
||||
title (:obj:`str`): Optional. Title for the result.
|
||||
description (:obj:`str`): Optional. Short description of the result.
|
||||
caption (:obj:`str`): Optional. Caption of the photo to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
|
||||
entities parsing.
|
||||
parse_mode (:obj:`str`): Optional. |parse_mode|
|
||||
caption_entities (tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the photo.
|
||||
show_caption_above_media (:obj:`bool`): Optional. |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"caption",
|
||||
"caption_entities",
|
||||
"description",
|
||||
"input_message_content",
|
||||
"parse_mode",
|
||||
"photo_height",
|
||||
"photo_url",
|
||||
"photo_width",
|
||||
"reply_markup",
|
||||
"show_caption_above_media",
|
||||
"thumbnail_url",
|
||||
"title",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
photo_url: str,
|
||||
thumbnail_url: str,
|
||||
photo_width: Optional[int] = None,
|
||||
photo_height: Optional[int] = None,
|
||||
title: Optional[str] = None,
|
||||
description: Optional[str] = None,
|
||||
caption: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
parse_mode: ODVInput[str] = DEFAULT_NONE,
|
||||
caption_entities: Optional[Sequence[MessageEntity]] = None,
|
||||
show_caption_above_media: Optional[bool] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.PHOTO, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.photo_url: str = photo_url
|
||||
self.thumbnail_url: str = thumbnail_url
|
||||
|
||||
# Optionals
|
||||
self.photo_width: Optional[int] = photo_width
|
||||
self.photo_height: Optional[int] = photo_height
|
||||
self.title: Optional[str] = title
|
||||
self.description: Optional[str] = description
|
||||
self.caption: Optional[str] = caption
|
||||
self.parse_mode: ODVInput[str] = parse_mode
|
||||
self.caption_entities: tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
self.show_caption_above_media: Optional[bool] = show_caption_above_media
|
||||
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the class that represent a Telegram InlineQueryResultsButton."""
|
||||
|
||||
from typing import TYPE_CHECKING, Final, Optional
|
||||
|
||||
from telegram import constants
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
from telegram._webappinfo import WebAppInfo
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot
|
||||
|
||||
|
||||
class InlineQueryResultsButton(TelegramObject):
|
||||
"""This object represents a button to be shown above inline query results. You **must** use
|
||||
exactly one of the optional fields.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`text`, :attr:`web_app` and :attr:`start_parameter` are equal.
|
||||
|
||||
Args:
|
||||
text (:obj:`str`): Label text on the button.
|
||||
web_app (:class:`telegram.WebAppInfo`, optional): Description of the
|
||||
`Web App <https://core.telegram.org/bots/webapps>`_ that will be launched when the
|
||||
user presses the button. The Web App will be able to switch back to the inline mode
|
||||
using the method
|
||||
`switchInlineQuery <https://core.telegram.org/bots/webapps#initializing-mini-apps>`_
|
||||
inside the Web App.
|
||||
start_parameter (:obj:`str`, optional): Deep-linking parameter for the
|
||||
:guilabel:`/start` message sent to the bot when user presses the switch button.
|
||||
:tg-const:`telegram.constants.InlineQueryResultsButtonLimit.MIN_START_PARAMETER_LENGTH`
|
||||
-
|
||||
:tg-const:`telegram.constants.InlineQueryResultsButtonLimit.MAX_START_PARAMETER_LENGTH`
|
||||
characters, only ``A-Z``, ``a-z``, ``0-9``, ``_`` and ``-`` are allowed.
|
||||
|
||||
Example:
|
||||
An inline bot that sends YouTube videos can ask the user to connect the bot to
|
||||
their YouTube account to adapt search results accordingly. To do this, it displays
|
||||
a 'Connect your YouTube account' button above the results, or even before showing
|
||||
any. The user presses the button, switches to a private chat with the bot and, in
|
||||
doing so, passes a start parameter that instructs the bot to return an OAuth link.
|
||||
Once done, the bot can offer a switch_inline button so that the user can easily
|
||||
return to the chat where they wanted to use the bot's inline capabilities.
|
||||
|
||||
Attributes:
|
||||
text (:obj:`str`): Label text on the button.
|
||||
web_app (:class:`telegram.WebAppInfo`): Optional. Description of the
|
||||
`Web App <https://core.telegram.org/bots/webapps>`_ that will be launched when the
|
||||
user presses the button. The Web App will be able to switch back to the inline mode
|
||||
using the method ``web_app_switch_inline_query`` inside the Web App.
|
||||
start_parameter (:obj:`str`): Optional. Deep-linking parameter for the
|
||||
:tg-const:`telegram.constants.InlineQueryResultsButtonLimit.MIN_START_PARAMETER_LENGTH`
|
||||
-
|
||||
:tg-const:`telegram.constants.InlineQueryResultsButtonLimit.MAX_START_PARAMETER_LENGTH`
|
||||
characters, only ``A-Z``, ``a-z``, ``0-9``, ``_`` and ``-`` are allowed.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ("start_parameter", "text", "web_app")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
text: str,
|
||||
web_app: Optional[WebAppInfo] = None,
|
||||
start_parameter: Optional[str] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
|
||||
# Required
|
||||
self.text: str = text
|
||||
|
||||
# Optional
|
||||
self.web_app: Optional[WebAppInfo] = web_app
|
||||
self.start_parameter: Optional[str] = start_parameter
|
||||
|
||||
self._id_attrs = (self.text, self.web_app, self.start_parameter)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "InlineQueryResultsButton":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
|
||||
data["web_app"] = de_json_optional(data.get("web_app"), WebAppInfo, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
MIN_START_PARAMETER_LENGTH: Final[int] = (
|
||||
constants.InlineQueryResultsButtonLimit.MIN_START_PARAMETER_LENGTH
|
||||
)
|
||||
""":const:`telegram.constants.InlineQueryResultsButtonLimit.MIN_START_PARAMETER_LENGTH`"""
|
||||
MAX_START_PARAMETER_LENGTH: Final[int] = (
|
||||
constants.InlineQueryResultsButtonLimit.MAX_START_PARAMETER_LENGTH
|
||||
)
|
||||
""":const:`telegram.constants.InlineQueryResultsButtonLimit.MAX_START_PARAMETER_LENGTH`"""
|
||||
@@ -0,0 +1,160 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultVenue."""
|
||||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._utils.types import JSONDict
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultVenue(InlineQueryResult):
|
||||
"""
|
||||
Represents a venue. By default, the venue will be sent by the user. Alternatively, you can
|
||||
use :attr:`input_message_content` to send a message with the specified content instead of the
|
||||
venue.
|
||||
|
||||
Note:
|
||||
Foursquare details and Google Pace details are mutually exclusive. However, this
|
||||
behaviour is undocumented and might be changed by Telegram.
|
||||
|
||||
.. versionchanged:: 20.5
|
||||
|removed_thumb_wildcard_note|
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
latitude (:obj:`float`): Latitude of the venue location in degrees.
|
||||
longitude (:obj:`float`): Longitude of the venue location in degrees.
|
||||
title (:obj:`str`): Title of the venue.
|
||||
address (:obj:`str`): Address of the venue.
|
||||
foursquare_id (:obj:`str`, optional): Foursquare identifier of the venue if known.
|
||||
foursquare_type (:obj:`str`, optional): Foursquare type of the venue, if known.
|
||||
(For example, "arts_entertainment/default", "arts_entertainment/aquarium" or
|
||||
"food/icecream".)
|
||||
google_place_id (:obj:`str`, optional): Google Places identifier of the venue.
|
||||
google_place_type (:obj:`str`, optional): Google Places type of the venue. (See
|
||||
`supported types <https://developers.google.com/maps/documentation/places/web-service\
|
||||
/supported_types>`_.)
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the venue.
|
||||
thumbnail_url (:obj:`str`, optional): Url of the thumbnail for the result.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_width (:obj:`int`, optional): Thumbnail width.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_height (:obj:`int`, optional): Thumbnail height.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.VENUE`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
latitude (:obj:`float`): Latitude of the venue location in degrees.
|
||||
longitude (:obj:`float`): Longitude of the venue location in degrees.
|
||||
title (:obj:`str`): Title of the venue.
|
||||
address (:obj:`str`): Address of the venue.
|
||||
foursquare_id (:obj:`str`): Optional. Foursquare identifier of the venue if known.
|
||||
foursquare_type (:obj:`str`): Optional. Foursquare type of the venue, if known.
|
||||
(For example, "arts_entertainment/default", "arts_entertainment/aquarium" or
|
||||
"food/icecream".)
|
||||
google_place_id (:obj:`str`): Optional. Google Places identifier of the venue.
|
||||
google_place_type (:obj:`str`): Optional. Google Places type of the venue. (See
|
||||
`supported types <https://developers.google.com/maps/documentation/places/web-service\
|
||||
/supported_types>`_.)
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the venue.
|
||||
thumbnail_url (:obj:`str`): Optional. Url of the thumbnail for the result.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_width (:obj:`int`): Optional. Thumbnail width.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
thumbnail_height (:obj:`int`): Optional. Thumbnail height.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"address",
|
||||
"foursquare_id",
|
||||
"foursquare_type",
|
||||
"google_place_id",
|
||||
"google_place_type",
|
||||
"input_message_content",
|
||||
"latitude",
|
||||
"longitude",
|
||||
"reply_markup",
|
||||
"thumbnail_height",
|
||||
"thumbnail_url",
|
||||
"thumbnail_width",
|
||||
"title",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
latitude: float,
|
||||
longitude: float,
|
||||
title: str,
|
||||
address: str,
|
||||
foursquare_id: Optional[str] = None,
|
||||
foursquare_type: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
google_place_id: Optional[str] = None,
|
||||
google_place_type: Optional[str] = None,
|
||||
thumbnail_url: Optional[str] = None,
|
||||
thumbnail_width: Optional[int] = None,
|
||||
thumbnail_height: Optional[int] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.VENUE, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.latitude: float = latitude
|
||||
self.longitude: float = longitude
|
||||
self.title: str = title
|
||||
self.address: str = address
|
||||
|
||||
# Optional
|
||||
self.foursquare_id: Optional[str] = foursquare_id
|
||||
self.foursquare_type: Optional[str] = foursquare_type
|
||||
self.google_place_id: Optional[str] = google_place_id
|
||||
self.google_place_type: Optional[str] = google_place_type
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
self.thumbnail_url: Optional[str] = thumbnail_url
|
||||
self.thumbnail_width: Optional[int] = thumbnail_width
|
||||
self.thumbnail_height: Optional[int] = thumbnail_height
|
||||
@@ -0,0 +1,196 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultVideo."""
|
||||
import datetime as dtm
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional, Union
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg, to_timedelta
|
||||
from telegram._utils.datetime import get_timedelta_value
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput, TimePeriod
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultVideo(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a page containing an embedded video player or a video file. By default,
|
||||
this video file will be sent by the user with an optional caption. Alternatively, you can use
|
||||
:attr:`input_message_content` to send a message with the specified content instead of
|
||||
the video.
|
||||
|
||||
Note:
|
||||
If an InlineQueryResultVideo message contains an embedded video (e.g., YouTube), you must
|
||||
replace its content using :attr:`input_message_content`.
|
||||
|
||||
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
|
||||
|
||||
.. versionchanged:: 20.5
|
||||
|removed_thumb_url_note|
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
video_url (:obj:`str`): A valid URL for the embedded video player or video file.
|
||||
mime_type (:obj:`str`): Mime type of the content of video url, "text/html" or "video/mp4".
|
||||
thumbnail_url (:obj:`str`, optional): URL of the thumbnail (JPEG only) for the video.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
|
||||
..versionchanged:: 20.5
|
||||
|thumbnail_url_mandatory|
|
||||
|
||||
title (:obj:`str`): Title for the result.
|
||||
caption (:obj:`str`, optional): Caption of the video to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
|
||||
parsing.
|
||||
parse_mode (:obj:`str`, optional): |parse_mode|
|
||||
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
|
||||
video_width (:obj:`int`, optional): Video width.
|
||||
video_height (:obj:`int`, optional): Video height.
|
||||
video_duration (:obj:`int` | :class:`datetime.timedelta`, optional): Video duration
|
||||
in seconds.
|
||||
|
||||
.. versionchanged:: v22.2
|
||||
|time-period-input|
|
||||
description (:obj:`str`, optional): Short description of the result.
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the video. This field is required if
|
||||
``InlineQueryResultVideo`` is used to send an HTML-page as a result
|
||||
(e.g., a YouTube video).
|
||||
show_caption_above_media (:obj:`bool`, optional): Pass |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.VIDEO`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
video_url (:obj:`str`): A valid URL for the embedded video player or video file.
|
||||
mime_type (:obj:`str`): Mime type of the content of video url, "text/html" or "video/mp4".
|
||||
thumbnail_url (:obj:`str`): URL of the thumbnail (JPEG only) for the video.
|
||||
|
||||
.. versionadded:: 20.2
|
||||
title (:obj:`str`): Title for the result.
|
||||
caption (:obj:`str`): Optional. Caption of the video to be sent,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
|
||||
parsing.
|
||||
parse_mode (:obj:`str`): Optional. |parse_mode|
|
||||
caption_entities (tuple[:class:`telegram.MessageEntity`]): Optional.
|
||||
|captionentitiesattr|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
|
||||
video_width (:obj:`int`): Optional. Video width.
|
||||
video_height (:obj:`int`): Optional. Video height.
|
||||
video_duration (:obj:`int` | :class:`datetime.timedelta`): Optional. Video duration
|
||||
in seconds.
|
||||
|
||||
.. deprecated:: v22.2
|
||||
|time-period-int-deprecated|
|
||||
description (:obj:`str`): Optional. Short description of the result.
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the video. This field is required if
|
||||
``InlineQueryResultVideo`` is used to send an HTML-page as a result
|
||||
(e.g., a YouTube video).
|
||||
show_caption_above_media (:obj:`bool`): Optional. |show_cap_above_med|
|
||||
|
||||
.. versionadded:: 21.3
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"_video_duration",
|
||||
"caption",
|
||||
"caption_entities",
|
||||
"description",
|
||||
"input_message_content",
|
||||
"mime_type",
|
||||
"parse_mode",
|
||||
"reply_markup",
|
||||
"show_caption_above_media",
|
||||
"thumbnail_url",
|
||||
"title",
|
||||
"video_height",
|
||||
"video_url",
|
||||
"video_width",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
video_url: str,
|
||||
mime_type: str,
|
||||
thumbnail_url: str,
|
||||
title: str,
|
||||
caption: Optional[str] = None,
|
||||
video_width: Optional[int] = None,
|
||||
video_height: Optional[int] = None,
|
||||
video_duration: Optional[TimePeriod] = None,
|
||||
description: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
parse_mode: ODVInput[str] = DEFAULT_NONE,
|
||||
caption_entities: Optional[Sequence[MessageEntity]] = None,
|
||||
show_caption_above_media: Optional[bool] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.VIDEO, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.video_url: str = video_url
|
||||
self.mime_type: str = mime_type
|
||||
self.thumbnail_url: str = thumbnail_url
|
||||
self.title: str = title
|
||||
|
||||
# Optional
|
||||
self.caption: Optional[str] = caption
|
||||
self.parse_mode: ODVInput[str] = parse_mode
|
||||
self.caption_entities: tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
|
||||
self.video_width: Optional[int] = video_width
|
||||
self.video_height: Optional[int] = video_height
|
||||
self._video_duration: Optional[dtm.timedelta] = to_timedelta(video_duration)
|
||||
self.description: Optional[str] = description
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
self.show_caption_above_media: Optional[bool] = show_caption_above_media
|
||||
|
||||
@property
|
||||
def video_duration(self) -> Optional[Union[int, dtm.timedelta]]:
|
||||
return get_timedelta_value(self._video_duration, attribute="video_duration")
|
||||
@@ -0,0 +1,141 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InlineQueryResultVoice."""
|
||||
import datetime as dtm
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional, Union
|
||||
|
||||
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from telegram._inline.inlinequeryresult import InlineQueryResult
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg, to_timedelta
|
||||
from telegram._utils.datetime import get_timedelta_value
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput, TimePeriod
|
||||
from telegram.constants import InlineQueryResultType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultVoice(InlineQueryResult):
|
||||
"""
|
||||
Represents a link to a voice recording in an .ogg container encoded with OPUS. By default,
|
||||
this voice recording will be sent by the user. Alternatively, you can use
|
||||
:attr:`input_message_content` to send a message with the specified content instead of
|
||||
the voice message.
|
||||
|
||||
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
voice_url (:obj:`str`): A valid URL for the voice recording.
|
||||
title (:obj:`str`): Recording title.
|
||||
caption (:obj:`str`, optional): Caption,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
|
||||
parsing.
|
||||
parse_mode (:obj:`str`, optional): |parse_mode|
|
||||
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
|
||||
voice_duration (:obj:`int` | :class:`datetime.timedelta`, optional): Recording duration
|
||||
in seconds.
|
||||
|
||||
.. versionchanged:: v22.2
|
||||
|time-period-input|
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
|
||||
message to be sent instead of the voice recording.
|
||||
|
||||
Attributes:
|
||||
type (:obj:`str`): :tg-const:`telegram.constants.InlineQueryResultType.VOICE`.
|
||||
id (:obj:`str`): Unique identifier for this result,
|
||||
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
|
||||
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
|
||||
voice_url (:obj:`str`): A valid URL for the voice recording.
|
||||
title (:obj:`str`): Recording title.
|
||||
caption (:obj:`str`): Optional. Caption,
|
||||
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
|
||||
parsing.
|
||||
parse_mode (:obj:`str`): Optional. |parse_mode|
|
||||
caption_entities (tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
voice_duration (:obj:`int` | :class:`datetime.timedelta`): Optional. Recording duration
|
||||
in seconds.
|
||||
|
||||
.. deprecated:: v22.2
|
||||
|time-period-int-deprecated|
|
||||
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
|
||||
to the message.
|
||||
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
|
||||
message to be sent instead of the voice recording.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"_voice_duration",
|
||||
"caption",
|
||||
"caption_entities",
|
||||
"input_message_content",
|
||||
"parse_mode",
|
||||
"reply_markup",
|
||||
"title",
|
||||
"voice_url",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
voice_url: str,
|
||||
title: str,
|
||||
voice_duration: Optional[TimePeriod] = None,
|
||||
caption: Optional[str] = None,
|
||||
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
||||
input_message_content: Optional["InputMessageContent"] = None,
|
||||
parse_mode: ODVInput[str] = DEFAULT_NONE,
|
||||
caption_entities: Optional[Sequence[MessageEntity]] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
# Required
|
||||
super().__init__(InlineQueryResultType.VOICE, id, api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
self.voice_url: str = voice_url
|
||||
self.title: str = title
|
||||
|
||||
# Optional
|
||||
self._voice_duration: Optional[dtm.timedelta] = to_timedelta(voice_duration)
|
||||
self.caption: Optional[str] = caption
|
||||
self.parse_mode: ODVInput[str] = parse_mode
|
||||
self.caption_entities: tuple[MessageEntity, ...] = parse_sequence_arg(caption_entities)
|
||||
self.reply_markup: Optional[InlineKeyboardMarkup] = reply_markup
|
||||
self.input_message_content: Optional[InputMessageContent] = input_message_content
|
||||
|
||||
@property
|
||||
def voice_duration(self) -> Optional[Union[int, dtm.timedelta]]:
|
||||
return get_timedelta_value(self._voice_duration, attribute="voice_duration")
|
||||
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InputContactMessageContent."""
|
||||
from typing import Optional
|
||||
|
||||
from telegram._inline.inputmessagecontent import InputMessageContent
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
|
||||
class InputContactMessageContent(InputMessageContent):
|
||||
"""Represents the content of a contact message to be sent as the result of an inline query.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`phone_number` is equal.
|
||||
|
||||
Args:
|
||||
phone_number (:obj:`str`): Contact's phone number.
|
||||
first_name (:obj:`str`): Contact's first name.
|
||||
last_name (:obj:`str`, optional): Contact's last name.
|
||||
vcard (:obj:`str`, optional): Additional data about the contact in the form of a vCard,
|
||||
0-:tg-const:`telegram.constants.ContactLimit.VCARD` bytes.
|
||||
|
||||
Attributes:
|
||||
phone_number (:obj:`str`): Contact's phone number.
|
||||
first_name (:obj:`str`): Contact's first name.
|
||||
last_name (:obj:`str`): Optional. Contact's last name.
|
||||
vcard (:obj:`str`): Optional. Additional data about the contact in the form of a vCard,
|
||||
0-:tg-const:`telegram.constants.ContactLimit.VCARD` bytes.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ("first_name", "last_name", "phone_number", "vcard")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
phone_number: str,
|
||||
first_name: str,
|
||||
last_name: Optional[str] = None,
|
||||
vcard: Optional[str] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
# Required
|
||||
self.phone_number: str = phone_number
|
||||
self.first_name: str = first_name
|
||||
# Optionals
|
||||
self.last_name: Optional[str] = last_name
|
||||
self.vcard: Optional[str] = vcard
|
||||
|
||||
self._id_attrs = (self.phone_number,)
|
||||
@@ -0,0 +1,264 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 a class that represents a Telegram InputInvoiceMessageContent."""
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inputmessagecontent import InputMessageContent
|
||||
from telegram._payment.labeledprice import LabeledPrice
|
||||
from telegram._utils.argumentparsing import de_list_optional, parse_sequence_arg
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot
|
||||
|
||||
|
||||
class InputInvoiceMessageContent(InputMessageContent):
|
||||
"""
|
||||
Represents the content of a invoice message to be sent as the result of an inline query.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`title`, :attr:`description`, :attr:`payload`,
|
||||
:attr:`currency` and :attr:`prices` are equal.
|
||||
|
||||
.. versionadded:: 13.5
|
||||
.. versionchanged:: 21.11
|
||||
:attr:`provider_token` is no longer considered for equality comparison.
|
||||
|
||||
Args:
|
||||
title (:obj:`str`): Product name. :tg-const:`telegram.Invoice.MIN_TITLE_LENGTH`-
|
||||
:tg-const:`telegram.Invoice.MAX_TITLE_LENGTH` characters.
|
||||
description (:obj:`str`): Product description.
|
||||
:tg-const:`telegram.Invoice.MIN_DESCRIPTION_LENGTH`-
|
||||
:tg-const:`telegram.Invoice.MAX_DESCRIPTION_LENGTH` characters.
|
||||
payload (:obj:`str`): Bot-defined invoice payload.
|
||||
:tg-const:`telegram.Invoice.MIN_PAYLOAD_LENGTH`-
|
||||
:tg-const:`telegram.Invoice.MAX_PAYLOAD_LENGTH` bytes. This will not be displayed
|
||||
to the user, use it for your internal processes.
|
||||
provider_token (:obj:`str`, optional): Payment provider token, obtained via
|
||||
`@Botfather <https://t.me/Botfather>`_. Pass an empty string for payments in
|
||||
|tg_stars|.
|
||||
|
||||
.. versionchanged:: 21.11
|
||||
Bot API 7.4 made this parameter is optional and this is now reflected in the
|
||||
class signature.
|
||||
currency (:obj:`str`): Three-letter ISO 4217 currency code, see more on
|
||||
`currencies <https://core.telegram.org/bots/payments#supported-currencies>`_.
|
||||
Pass ``XTR`` for payments in |tg_stars|.
|
||||
prices (Sequence[:class:`telegram.LabeledPrice`]): Price breakdown, a list of
|
||||
components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus,
|
||||
etc.). Must contain exactly one item for payments in |tg_stars|.
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
|
||||
max_tip_amount (:obj:`int`, optional): The maximum accepted amount for tips in the
|
||||
*smallest units* of the currency (integer, **not** float/double). For example, for a
|
||||
maximum tip of ``US$ 1.45`` pass ``max_tip_amount = 145``. See the ``exp`` parameter in
|
||||
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_, it
|
||||
shows the number of digits past the decimal point for each currency (2 for the majority
|
||||
of currencies). Defaults to ``0``. Not supported for payments in |tg_stars|.
|
||||
suggested_tip_amounts (Sequence[:obj:`int`], optional): An array of suggested
|
||||
amounts of tip in the *smallest units* of the currency (integer, **not** float/double).
|
||||
At most 4 suggested tip amounts can be specified. The suggested tip amounts must be
|
||||
positive, passed in a strictly increased order and must not exceed
|
||||
:attr:`max_tip_amount`.
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
|
||||
provider_data (:obj:`str`, optional): An object for data about the invoice,
|
||||
which will be shared with the payment provider. A detailed description of the required
|
||||
fields should be provided by the payment provider.
|
||||
photo_url (:obj:`str`, optional): URL of the product photo for the invoice. Can be a photo
|
||||
of the goods or a marketing image for a service. People like it better when they see
|
||||
what they are paying for.
|
||||
photo_size (:obj:`int`, optional): Photo size.
|
||||
photo_width (:obj:`int`, optional): Photo width.
|
||||
photo_height (:obj:`int`, optional): Photo height.
|
||||
need_name (:obj:`bool`, optional): Pass :obj:`True`, if you require the user's full
|
||||
name to complete the order. Ignored for payments in |tg_stars|.
|
||||
need_phone_number (:obj:`bool`, optional): Pass :obj:`True`, if you require the user's
|
||||
phone number to complete the order. Ignored for payments in |tg_stars|.
|
||||
need_email (:obj:`bool`, optional): Pass :obj:`True`, if you require the user's email
|
||||
address to complete the order. Ignored for payments in |tg_stars|.
|
||||
need_shipping_address (:obj:`bool`, optional): Pass :obj:`True`, if you require the
|
||||
user's shipping address to complete the order. Ignored for payments in |tg_stars|
|
||||
send_phone_number_to_provider (:obj:`bool`, optional): Pass :obj:`True`, if user's
|
||||
phone number should be sent to provider. Ignored for payments in |tg_stars|.
|
||||
send_email_to_provider (:obj:`bool`, optional): Pass :obj:`True`, if user's email
|
||||
address should be sent to provider. Ignored for payments in |tg_stars|.
|
||||
is_flexible (:obj:`bool`, optional): Pass :obj:`True`, if the final price depends on
|
||||
the shipping method. Ignored for payments in |tg_stars|.
|
||||
|
||||
Attributes:
|
||||
title (:obj:`str`): Product name. :tg-const:`telegram.Invoice.MIN_TITLE_LENGTH`-
|
||||
:tg-const:`telegram.Invoice.MAX_TITLE_LENGTH` characters.
|
||||
description (:obj:`str`): Product description.
|
||||
:tg-const:`telegram.Invoice.MIN_DESCRIPTION_LENGTH`-
|
||||
:tg-const:`telegram.Invoice.MAX_DESCRIPTION_LENGTH` characters.
|
||||
payload (:obj:`str`): Bot-defined invoice payload.
|
||||
:tg-const:`telegram.Invoice.MIN_PAYLOAD_LENGTH`-
|
||||
:tg-const:`telegram.Invoice.MAX_PAYLOAD_LENGTH` bytes. This will not be displayed
|
||||
to the user, use it for your internal processes.
|
||||
provider_token (:obj:`str`): Payment provider token, obtained via
|
||||
`@Botfather <https://t.me/Botfather>`_. Pass an empty string for payments in `Telegram
|
||||
Stars <https://t.me/BotNews/90>`_.
|
||||
currency (:obj:`str`): Three-letter ISO 4217 currency code, see more on
|
||||
`currencies <https://core.telegram.org/bots/payments#supported-currencies>`_.
|
||||
Pass ``XTR`` for payments in |tg_stars|.
|
||||
prices (tuple[:class:`telegram.LabeledPrice`]): Price breakdown, a list of
|
||||
components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus,
|
||||
etc.). Must contain exactly one item for payments in |tg_stars|.
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|tupleclassattrs|
|
||||
|
||||
max_tip_amount (:obj:`int`): Optional. The maximum accepted amount for tips in the
|
||||
*smallest units* of the currency (integer, **not** float/double). For example, for a
|
||||
maximum tip of ``US$ 1.45`` ``max_tip_amount`` is ``145``. See the ``exp`` parameter in
|
||||
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_, it
|
||||
shows the number of digits past the decimal point for each currency (2 for the majority
|
||||
of currencies). Defaults to ``0``. Not supported for payments in |tg_stars|.
|
||||
suggested_tip_amounts (tuple[:obj:`int`]): Optional. An array of suggested
|
||||
amounts of tip in the *smallest units* of the currency (integer, **not** float/double).
|
||||
At most 4 suggested tip amounts can be specified. The suggested tip amounts must be
|
||||
positive, passed in a strictly increased order and must not exceed
|
||||
:attr:`max_tip_amount`.
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|tupleclassattrs|
|
||||
|
||||
provider_data (:obj:`str`): Optional. An object for data about the invoice,
|
||||
which will be shared with the payment provider. A detailed description of the required
|
||||
fields should be provided by the payment provider.
|
||||
photo_url (:obj:`str`): Optional. URL of the product photo for the invoice. Can be a photo
|
||||
of the goods or a marketing image for a service. People like it better when they see
|
||||
what they are paying for.
|
||||
photo_size (:obj:`int`): Optional. Photo size.
|
||||
photo_width (:obj:`int`): Optional. Photo width.
|
||||
photo_height (:obj:`int`): Optional. Photo height.
|
||||
need_name (:obj:`bool`): Optional. Pass :obj:`True`, if you require the user's full name to
|
||||
complete the order. Ignored for payments in |tg_stars|.
|
||||
need_phone_number (:obj:`bool`): Optional. Pass :obj:`True`, if you require the user's
|
||||
phone number to complete the order. Ignored for payments in |tg_stars|.
|
||||
need_email (:obj:`bool`): Optional. Pass :obj:`True`, if you require the user's email
|
||||
address to complete the order. Ignored for payments in |tg_stars|.
|
||||
need_shipping_address (:obj:`bool`): Optional. Pass :obj:`True`, if you require the user's
|
||||
shipping address to complete the order. Ignored for payments in |tg_stars|.
|
||||
send_phone_number_to_provider (:obj:`bool`): Optional. Pass :obj:`True`, if user's phone
|
||||
number should be sent to provider. Ignored for payments in |tg_stars|.
|
||||
send_email_to_provider (:obj:`bool`): Optional. Pass :obj:`True`, if user's email address
|
||||
should be sent to provider. Ignored for payments in |tg_stars|.
|
||||
is_flexible (:obj:`bool`): Optional. Pass :obj:`True`, if the final price depends on the
|
||||
shipping method. Ignored for payments in |tg_stars|.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"currency",
|
||||
"description",
|
||||
"is_flexible",
|
||||
"max_tip_amount",
|
||||
"need_email",
|
||||
"need_name",
|
||||
"need_phone_number",
|
||||
"need_shipping_address",
|
||||
"payload",
|
||||
"photo_height",
|
||||
"photo_size",
|
||||
"photo_url",
|
||||
"photo_width",
|
||||
"prices",
|
||||
"provider_data",
|
||||
"provider_token",
|
||||
"send_email_to_provider",
|
||||
"send_phone_number_to_provider",
|
||||
"suggested_tip_amounts",
|
||||
"title",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
title: str,
|
||||
description: str,
|
||||
payload: str,
|
||||
currency: str,
|
||||
prices: Sequence[LabeledPrice],
|
||||
provider_token: Optional[str] = None,
|
||||
max_tip_amount: Optional[int] = None,
|
||||
suggested_tip_amounts: Optional[Sequence[int]] = None,
|
||||
provider_data: Optional[str] = None,
|
||||
photo_url: Optional[str] = None,
|
||||
photo_size: Optional[int] = None,
|
||||
photo_width: Optional[int] = None,
|
||||
photo_height: Optional[int] = None,
|
||||
need_name: Optional[bool] = None,
|
||||
need_phone_number: Optional[bool] = None,
|
||||
need_email: Optional[bool] = None,
|
||||
need_shipping_address: Optional[bool] = None,
|
||||
send_phone_number_to_provider: Optional[bool] = None,
|
||||
send_email_to_provider: Optional[bool] = None,
|
||||
is_flexible: Optional[bool] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
# Required
|
||||
self.title: str = title
|
||||
self.description: str = description
|
||||
self.payload: str = payload
|
||||
self.currency: str = currency
|
||||
self.prices: tuple[LabeledPrice, ...] = parse_sequence_arg(prices)
|
||||
# Optionals
|
||||
self.provider_token: Optional[str] = provider_token
|
||||
self.max_tip_amount: Optional[int] = max_tip_amount
|
||||
self.suggested_tip_amounts: tuple[int, ...] = parse_sequence_arg(suggested_tip_amounts)
|
||||
self.provider_data: Optional[str] = provider_data
|
||||
self.photo_url: Optional[str] = photo_url
|
||||
self.photo_size: Optional[int] = photo_size
|
||||
self.photo_width: Optional[int] = photo_width
|
||||
self.photo_height: Optional[int] = photo_height
|
||||
self.need_name: Optional[bool] = need_name
|
||||
self.need_phone_number: Optional[bool] = need_phone_number
|
||||
self.need_email: Optional[bool] = need_email
|
||||
self.need_shipping_address: Optional[bool] = need_shipping_address
|
||||
self.send_phone_number_to_provider: Optional[bool] = send_phone_number_to_provider
|
||||
self.send_email_to_provider: Optional[bool] = send_email_to_provider
|
||||
self.is_flexible: Optional[bool] = is_flexible
|
||||
|
||||
self._id_attrs = (
|
||||
self.title,
|
||||
self.description,
|
||||
self.payload,
|
||||
self.currency,
|
||||
self.prices,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "InputInvoiceMessageContent":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["prices"] = de_list_optional(data.get("prices"), LabeledPrice, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
@@ -0,0 +1,164 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InputLocationMessageContent."""
|
||||
|
||||
import datetime as dtm
|
||||
from typing import Final, Optional, Union
|
||||
|
||||
from telegram import constants
|
||||
from telegram._inline.inputmessagecontent import InputMessageContent
|
||||
from telegram._utils.argumentparsing import to_timedelta
|
||||
from telegram._utils.datetime import get_timedelta_value
|
||||
from telegram._utils.types import JSONDict, TimePeriod
|
||||
|
||||
|
||||
class InputLocationMessageContent(InputMessageContent):
|
||||
# fmt: off
|
||||
"""
|
||||
Represents the content of a location message to be sent as the result of an inline query.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`latitude` and :attr:`longitude` are equal.
|
||||
|
||||
Args:
|
||||
latitude (:obj:`float`): Latitude of the location in degrees.
|
||||
longitude (:obj:`float`): Longitude of the location in degrees.
|
||||
horizontal_accuracy (:obj:`float`, optional): The radius of uncertainty for the location,
|
||||
measured in meters; 0-
|
||||
:tg-const:`telegram.InputLocationMessageContent.HORIZONTAL_ACCURACY`.
|
||||
live_period (:obj:`int` | :class:`datetime.timedelta`, optional): Period in seconds for
|
||||
which the location will be updated, should be between
|
||||
:tg-const:`telegram.InputLocationMessageContent.MIN_LIVE_PERIOD` and
|
||||
:tg-const:`telegram.InputLocationMessageContent.MAX_LIVE_PERIOD` or
|
||||
:tg-const:`telegram.constants.LocationLimit.LIVE_PERIOD_FOREVER` for live
|
||||
locations that can be edited indefinitely.
|
||||
|
||||
.. versionchanged:: v22.2
|
||||
|time-period-input|
|
||||
heading (:obj:`int`, optional): For live locations, a direction in which the user is
|
||||
moving, in degrees. Must be between
|
||||
:tg-const:`telegram.InputLocationMessageContent.MIN_HEADING` and
|
||||
:tg-const:`telegram.InputLocationMessageContent.MAX_HEADING` if specified.
|
||||
proximity_alert_radius (:obj:`int`, optional): For live locations, a maximum distance
|
||||
for proximity alerts about approaching another chat member, in meters. Must be
|
||||
between :tg-const:`telegram.InputLocationMessageContent.MIN_PROXIMITY_ALERT_RADIUS`
|
||||
and :tg-const:`telegram.InputLocationMessageContent.MAX_PROXIMITY_ALERT_RADIUS`
|
||||
if specified.
|
||||
|
||||
Attributes:
|
||||
latitude (:obj:`float`): Latitude of the location in degrees.
|
||||
longitude (:obj:`float`): Longitude of the location in degrees.
|
||||
horizontal_accuracy (:obj:`float`): Optional. The radius of uncertainty for the location,
|
||||
measured in meters; 0-
|
||||
:tg-const:`telegram.InputLocationMessageContent.HORIZONTAL_ACCURACY`.
|
||||
live_period (:obj:`int` | :class:`datetime.timedelta`): Optional. Period in seconds for
|
||||
which the location can be updated, should be between
|
||||
:tg-const:`telegram.InputLocationMessageContent.MIN_LIVE_PERIOD` and
|
||||
:tg-const:`telegram.InputLocationMessageContent.MAX_LIVE_PERIOD`.
|
||||
|
||||
.. deprecated:: v22.2
|
||||
|time-period-int-deprecated|
|
||||
heading (:obj:`int`): Optional. For live locations, a direction in which the user is
|
||||
moving, in degrees. Must be between
|
||||
:tg-const:`telegram.InputLocationMessageContent.MIN_HEADING` and
|
||||
:tg-const:`telegram.InputLocationMessageContent.MAX_HEADING` if specified.
|
||||
proximity_alert_radius (:obj:`int`): Optional. For live locations, a maximum distance
|
||||
for proximity alerts about approaching another chat member, in meters. Must be
|
||||
between :tg-const:`telegram.InputLocationMessageContent.MIN_PROXIMITY_ALERT_RADIUS`
|
||||
and :tg-const:`telegram.InputLocationMessageContent.MAX_PROXIMITY_ALERT_RADIUS`
|
||||
if specified.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"_live_period",
|
||||
"heading",
|
||||
"horizontal_accuracy",
|
||||
"latitude",
|
||||
"longitude",
|
||||
"proximity_alert_radius",
|
||||
)
|
||||
# fmt: on
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
latitude: float,
|
||||
longitude: float,
|
||||
live_period: Optional[TimePeriod] = None,
|
||||
horizontal_accuracy: Optional[float] = None,
|
||||
heading: Optional[int] = None,
|
||||
proximity_alert_radius: Optional[int] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
# Required
|
||||
self.latitude: float = latitude
|
||||
self.longitude: float = longitude
|
||||
|
||||
# Optionals
|
||||
self._live_period: Optional[dtm.timedelta] = to_timedelta(live_period)
|
||||
self.horizontal_accuracy: Optional[float] = horizontal_accuracy
|
||||
self.heading: Optional[int] = heading
|
||||
self.proximity_alert_radius: Optional[int] = (
|
||||
int(proximity_alert_radius) if proximity_alert_radius else None
|
||||
)
|
||||
|
||||
self._id_attrs = (self.latitude, self.longitude)
|
||||
|
||||
@property
|
||||
def live_period(self) -> Optional[Union[int, dtm.timedelta]]:
|
||||
return get_timedelta_value(self._live_period, attribute="live_period")
|
||||
|
||||
HORIZONTAL_ACCURACY: Final[int] = constants.LocationLimit.HORIZONTAL_ACCURACY
|
||||
""":const:`telegram.constants.LocationLimit.HORIZONTAL_ACCURACY`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MIN_HEADING: Final[int] = constants.LocationLimit.MIN_HEADING
|
||||
""":const:`telegram.constants.LocationLimit.MIN_HEADING`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MAX_HEADING: Final[int] = constants.LocationLimit.MAX_HEADING
|
||||
""":const:`telegram.constants.LocationLimit.MAX_HEADING`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MIN_LIVE_PERIOD: Final[int] = constants.LocationLimit.MIN_LIVE_PERIOD
|
||||
""":const:`telegram.constants.LocationLimit.MIN_LIVE_PERIOD`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MAX_LIVE_PERIOD: Final[int] = constants.LocationLimit.MAX_LIVE_PERIOD
|
||||
""":const:`telegram.constants.LocationLimit.MAX_LIVE_PERIOD`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MIN_PROXIMITY_ALERT_RADIUS: Final[int] = constants.LocationLimit.MIN_PROXIMITY_ALERT_RADIUS
|
||||
""":const:`telegram.constants.LocationLimit.MIN_PROXIMITY_ALERT_RADIUS`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
MAX_PROXIMITY_ALERT_RADIUS: Final[int] = constants.LocationLimit.MAX_PROXIMITY_ALERT_RADIUS
|
||||
""":const:`telegram.constants.LocationLimit.MAX_PROXIMITY_ALERT_RADIUS`
|
||||
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InputMessageContent."""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
|
||||
class InputMessageContent(TelegramObject):
|
||||
"""Base class for Telegram InputMessageContent Objects.
|
||||
|
||||
See: :class:`telegram.InputContactMessageContent`,
|
||||
:class:`telegram.InputInvoiceMessageContent`,
|
||||
:class:`telegram.InputLocationMessageContent`, :class:`telegram.InputTextMessageContent` and
|
||||
:class:`telegram.InputVenueMessageContent` for more details.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
def __init__(self, *, api_kwargs: Optional[JSONDict] = None) -> None:
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
|
||||
self._freeze()
|
||||
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InputTextMessageContent."""
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._inline.inputmessagecontent import InputMessageContent
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._utils.argumentparsing import parse_lpo_and_dwpp, parse_sequence_arg
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram._linkpreviewoptions import LinkPreviewOptions
|
||||
|
||||
|
||||
class InputTextMessageContent(InputMessageContent):
|
||||
"""
|
||||
Represents the content of a text message to be sent as the result of an inline query.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`message_text` is equal.
|
||||
|
||||
Examples:
|
||||
:any:`Inline Bot <examples.inlinebot>`
|
||||
|
||||
Args:
|
||||
message_text (:obj:`str`): Text of the message to be sent,
|
||||
:tg-const:`telegram.constants.MessageLimit.MIN_TEXT_LENGTH`-
|
||||
:tg-const:`telegram.constants.MessageLimit.MAX_TEXT_LENGTH` characters after entities
|
||||
parsing.
|
||||
parse_mode (:obj:`str`, optional): |parse_mode|
|
||||
entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|sequenceclassargs|
|
||||
|
||||
link_preview_options (:obj:`LinkPreviewOptions`, optional): Link preview generation
|
||||
options for the message. Mutually exclusive with
|
||||
:paramref:`disable_web_page_preview`.
|
||||
|
||||
.. versionadded:: 20.8
|
||||
|
||||
Keyword Args:
|
||||
disable_web_page_preview (:obj:`bool`, optional): Disables link previews for links in the
|
||||
sent message. Convenience parameter for setting :paramref:`link_preview_options`.
|
||||
Mutually exclusive with :paramref:`link_preview_options`.
|
||||
|
||||
.. versionchanged:: 20.8
|
||||
Bot API 7.0 introduced :paramref:`link_preview_options` replacing this
|
||||
argument. PTB will automatically convert this argument to that one, but
|
||||
for advanced options, please use :paramref:`link_preview_options` directly.
|
||||
|
||||
.. versionchanged:: 21.0
|
||||
|keyword_only_arg|
|
||||
|
||||
Attributes:
|
||||
message_text (:obj:`str`): Text of the message to be sent,
|
||||
:tg-const:`telegram.constants.MessageLimit.MIN_TEXT_LENGTH`-
|
||||
:tg-const:`telegram.constants.MessageLimit.MAX_TEXT_LENGTH` characters after entities
|
||||
parsing.
|
||||
parse_mode (:obj:`str`): Optional. |parse_mode|
|
||||
entities (tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
|
||||
|
||||
.. versionchanged:: 20.0
|
||||
|
||||
* |tupleclassattrs|
|
||||
* |alwaystuple|
|
||||
link_preview_options (:obj:`LinkPreviewOptions`): Optional. Link preview generation
|
||||
options for the message.
|
||||
|
||||
.. versionadded:: 20.8
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ("entities", "link_preview_options", "message_text", "parse_mode")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
message_text: str,
|
||||
parse_mode: ODVInput[str] = DEFAULT_NONE,
|
||||
entities: Optional[Sequence[MessageEntity]] = None,
|
||||
link_preview_options: ODVInput["LinkPreviewOptions"] = DEFAULT_NONE,
|
||||
*,
|
||||
disable_web_page_preview: Optional[bool] = None,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
|
||||
with self._unfrozen():
|
||||
# Required
|
||||
self.message_text: str = message_text
|
||||
# Optionals
|
||||
self.parse_mode: ODVInput[str] = parse_mode
|
||||
self.entities: tuple[MessageEntity, ...] = parse_sequence_arg(entities)
|
||||
self.link_preview_options: ODVInput[LinkPreviewOptions] = parse_lpo_and_dwpp(
|
||||
disable_web_page_preview, link_preview_options
|
||||
)
|
||||
|
||||
self._id_attrs = (self.message_text,)
|
||||
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 the classes that represent Telegram InputVenueMessageContent."""
|
||||
from typing import Optional
|
||||
|
||||
from telegram._inline.inputmessagecontent import InputMessageContent
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
|
||||
class InputVenueMessageContent(InputMessageContent):
|
||||
"""Represents the content of a venue message to be sent as the result of an inline query.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`latitude`, :attr:`longitude` and :attr:`title`
|
||||
are equal.
|
||||
|
||||
Note:
|
||||
Foursquare details and Google Pace details are mutually exclusive. However, this
|
||||
behaviour is undocumented and might be changed by Telegram.
|
||||
|
||||
Args:
|
||||
latitude (:obj:`float`): Latitude of the location in degrees.
|
||||
longitude (:obj:`float`): Longitude of the location in degrees.
|
||||
title (:obj:`str`): Name of the venue.
|
||||
address (:obj:`str`): Address of the venue.
|
||||
foursquare_id (:obj:`str`, optional): Foursquare identifier of the venue, if known.
|
||||
foursquare_type (:obj:`str`, optional): Foursquare type of the venue, if known.
|
||||
(For example, "arts_entertainment/default", "arts_entertainment/aquarium" or
|
||||
"food/icecream".)
|
||||
google_place_id (:obj:`str`, optional): Google Places identifier of the venue.
|
||||
google_place_type (:obj:`str`, optional): Google Places type of the venue. (See
|
||||
`supported types <https://developers.google.com/maps/documentation/places/web-service\
|
||||
/supported_types>`_.)
|
||||
|
||||
Attributes:
|
||||
latitude (:obj:`float`): Latitude of the location in degrees.
|
||||
longitude (:obj:`float`): Longitude of the location in degrees.
|
||||
title (:obj:`str`): Name of the venue.
|
||||
address (:obj:`str`): Address of the venue.
|
||||
foursquare_id (:obj:`str`): Optional. Foursquare identifier of the venue, if known.
|
||||
foursquare_type (:obj:`str`): Optional. Foursquare type of the venue, if known.
|
||||
(For example, "arts_entertainment/default", "arts_entertainment/aquarium" or
|
||||
"food/icecream".)
|
||||
google_place_id (:obj:`str`): Optional. Google Places identifier of the venue.
|
||||
google_place_type (:obj:`str`): Optional. Google Places type of the venue. (See
|
||||
`supported types <https://developers.google.com/maps/documentation/places/web-service\
|
||||
/supported_types>`_.)
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
"address",
|
||||
"foursquare_id",
|
||||
"foursquare_type",
|
||||
"google_place_id",
|
||||
"google_place_type",
|
||||
"latitude",
|
||||
"longitude",
|
||||
"title",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
latitude: float,
|
||||
longitude: float,
|
||||
title: str,
|
||||
address: str,
|
||||
foursquare_id: Optional[str] = None,
|
||||
foursquare_type: Optional[str] = None,
|
||||
google_place_id: Optional[str] = None,
|
||||
google_place_type: Optional[str] = None,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
with self._unfrozen():
|
||||
# Required
|
||||
self.latitude: float = latitude
|
||||
self.longitude: float = longitude
|
||||
self.title: str = title
|
||||
self.address: str = address
|
||||
# Optionals
|
||||
self.foursquare_id: Optional[str] = foursquare_id
|
||||
self.foursquare_type: Optional[str] = foursquare_type
|
||||
self.google_place_id: Optional[str] = google_place_id
|
||||
self.google_place_type: Optional[str] = google_place_type
|
||||
|
||||
self._id_attrs = (
|
||||
self.latitude,
|
||||
self.longitude,
|
||||
self.title,
|
||||
)
|
||||
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2025
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# 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 Prepared inline Message."""
|
||||
import datetime as dtm
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot
|
||||
|
||||
|
||||
class PreparedInlineMessage(TelegramObject):
|
||||
"""Describes an inline message to be sent by a user of a Mini App.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`id` is equal.
|
||||
|
||||
.. versionadded:: 21.8
|
||||
|
||||
Args:
|
||||
id (:obj:`str`): Unique identifier of the prepared message
|
||||
expiration_date (:class:`datetime.datetime`): Expiration date of the prepared message.
|
||||
Expired prepared messages can no longer be used.
|
||||
|datetime_localization|
|
||||
|
||||
Attributes:
|
||||
id (:obj:`str`): Unique identifier of the prepared message
|
||||
expiration_date (:class:`datetime.datetime`): Expiration date of the prepared message.
|
||||
Expired prepared messages can no longer be used.
|
||||
|datetime_localization|
|
||||
"""
|
||||
|
||||
__slots__ = ("expiration_date", "id")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
id: str, # pylint: disable=redefined-builtin
|
||||
expiration_date: dtm.datetime,
|
||||
*,
|
||||
api_kwargs: Optional[JSONDict] = None,
|
||||
):
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.id: str = id
|
||||
self.expiration_date: dtm.datetime = expiration_date
|
||||
|
||||
self._id_attrs = (self.id,)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "PreparedInlineMessage":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
data["expiration_date"] = from_timestamp(data.get("expiration_date"), tzinfo=loc_tzinfo)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
Reference in New Issue
Block a user