10000 API 6.7 by Bibo-Joshi · Pull Request #3673 · python-telegram-bot/python-telegram-bot · GitHub
[go: up one dir, main page]

Skip to content

API 6.7 #3673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
May 7, 2023
Merged

API 6.7 #3673

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8c3d3e6
Update Bot API Version to 6.6
Bibo-Joshi Apr 21, 2023
20ca104
Add `BotName` class
Bibo-Joshi Apr 21, 2023
c8a7132
Add `{set, get}_my_name` Methods
Bibo-Joshi Apr 21, 2023
7129ba6
`ChatMemberUpdated.via_chat_folder_invite_link`
Bibo-Joshi Apr 21, 2023
489dfc9
Add `InlineQueryResultsButton`
Bibo-Joshi Apr 21, 2023
269e088
Update `Bot.answer_inline_query`
Bibo-Joshi Apr 21, 2023
3c974ba
Try fixing tests
Bibo-Joshi Apr 21, 2023
0c0bc83
add `web_app_name` to `WriteAccessAllowed`
lemontree210 Apr 21, 2023
9c9cdc0
Add & Integrate SwitchInlineQueryChosenChat
harshil21 Apr 21, 2023
a1d1369
Review: Correct docstring in IKB
harshil21 Apr 21, 2023
3484dcf
Correct again
harshil21 Apr 21, 2023
7e6818e
Update Docs
Bibo-Joshi Apr 22, 2023
bd73413
Update Docs
Bibo-Joshi Apr 22, 2023
b8ec32f
Feat: Support for custom emojis
Poolitzer Apr 22, 2023
1106fb3
Merge remote-tracking branch 'origin/api-6.7' into api-6.7
Poolitzer Apr 22, 2023
28127b0
Fix some tests properly and the name tests temporarily
Bibo-Joshi Apr 23, 2023
6d7ec48
Update `test_official`
Bibo-Joshi Apr 23, 2023
5433627
Fix: Rename test
Poolitzer Apr 23, 2023
1504019
Fix: Improve docstring
Poolitzer Apr 23, 2023
dca7f94
Merge remote-tracking branch 'origin/api-6.7' into api-6.7
Poolitzer Apr 23, 2023
2135781
Increase coverage
Bibo-Joshi Apr 23, 2023
8b93d69
Review: Refine switch_inline_query tip
harshil21 Apr 24, 2023
cb038d9
Deprecate custom emoji replacement in MD v1
Bibo-Joshi Apr 24, 2023
352047d
Completely skip set_get_my_name test until it's mocked
Bibo-Joshi Apr 25, 2023
f21d8c9
Add a note on `set_my_name`
Bibo-Joshi Apr 26, 2023
cdadcb7
Mock the `set/get_my_name` test
Bibo-Joshi Apr 26, 2023
ff72e3e
Review
Bibo-Joshi Apr 27, 2023
aa4c2be
Merge branch 'master' into api-6.7
Bibo-Joshi Apr 30, 2023
f78c737
Fix some typos
harshil21 May 5, 2023
9e85331
update warning test to use bot and extbot
May 6, 2023
9bfd5a1
`pre-commit` autoupdate (#3688)
pre-commit-ci[bot] May 6, 2023
858a047
Merge branch 'master' into api-6.7
Bibo-Joshi May 6, 2023
775deeb
Add a shortcut
Bibo-Joshi May 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
:target: https://pypi.org/project/python-telegram-bot/
:alt: Supported Python versions

.. image:: https://img.shields.io/badge/Bot%20API-6.6-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-6.7-blue?logo=telegram
:target: https://core.telegram.org/bots/api-changelog
:alt: Supported Bot API versions

Expand Down Expand Up @@ -93,7 +93,7 @@ Installing both ``python-telegram-bot`` and ``python-telegram-bot-raw`` in conju
Telegram API support
====================

All types and methods of the Telegram Bot API **6.6** are supported.
All types and methods of the Telegram Bot API **6.7** are supported.

Installing
==========
Expand Down
4 changes: 2 additions & 2 deletions README_RAW.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
:target: https://pypi.org/project/python-telegram-bot-raw/
:alt: Supported Python versions

.. image:: https://img.shields.io/badge/Bot%20API-6.6-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-6.7-blue?logo=telegram
:target: https://core.telegram.org/bots/api-changelog
:alt: Supported Bot API versions

Expand Down Expand Up @@ -89,7 +89,7 @@ Installing both ``python-telegram-bot`` and ``python-telegram-bot-raw`` in conju
Telegram API support
====================

All types and methods of the Telegram Bot API **6.6** are supported.
All types and methods of the Telegram Bot API **6.7** are supported.

Installing
==========
Expand Down
4 changes: 4 additions & 0 deletions docs/source/inclusions/bot_methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@
- Used for setting the short description of the bot
* - :meth:`~telegram.Bot.get_my_short_description`
- Used for obtaining the short description of the bot
* - :meth:`~telegram.Bot.set_my_name`
- Used for setting the name of the bot
* - :meth:`~telegram.Bot.get_my_name`
- Used for obtaining the name of the bot

.. raw:: html

Expand Down
2 changes: 2 additions & 0 deletions docs/source/telegram.at-tree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Available Types
telegram.botcommandscopechatmember
telegram.botcommandscopedefault
telegram.botdescription
telegram.botname
telegram.botshortdescription
telegram.callbackquery
telegram.chat
Expand Down Expand Up @@ -78,6 +79,7 @@ Available Types
telegram.replykeyboardmarkup
telegram.replykeyboardremove
telegram.sentwebappmessage
telegram.switchinlinequerychosenchat
telegram.telegramobject
telegram.update
telegram.user
Expand Down
6 changes: 6 additions & 0 deletions docs/source/telegram.botname.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BotName
=======

.. autoclass:: telegram.BotName
:members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/source/telegram.inline-tree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Inline Mode
telegram.inlinequeryresultlocation
telegram.inlinequeryresultmpeg4gif
telegram.inlinequeryresultphoto
telegram.inlinequeryresultsbutton
telegram.inlinequeryresultvenue
telegram.inlinequeryresultvideo
telegram.inlinequeryresultvoice
Expand Down
6 changes: 6 additions & 0 deletions docs/source/telegram.inlinequeryresultsbutton.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
InlineQueryResultsButton
========================

.. autoclass:: telegram.InlineQueryResultsButton
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.switchinlinequerychosenchat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SwitchInlineQueryChosenChat
===========================

.. autoclass:: telegram.SwitchInlineQueryChosenChat
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"BotCommandScopeChatMember",
"BotCommandScopeDefault",
"BotDescription",
"BotName",
"BotShortDescription",
"CallbackGame",
"CallbackQuery",
Expand Down Expand Up @@ -102,6 +103,7 @@
"InlineQueryResultLocation",
"InlineQueryResultMpeg4Gif",
"InlineQueryResultPhoto",
"InlineQueryResultsButton",
"InlineQueryResultVenue",
"InlineQueryResultVideo",
"InlineQueryResultVoice",
Expand Down Expand Up @@ -169,6 +171,7 @@
"Sticker",
"StickerSet",
"SuccessfulPayment",
"SwitchInlineQueryChosenChat",
"TelegramObject",
"Update",
"User",
Expand Down Expand Up @@ -204,6 +207,7 @@
BotCommandScopeDefault,
)
from ._botdescription import BotDescription, BotShortDescription
from ._botname import BotName
from ._callbackquery import CallbackQuery
from ._chat import Chat
from ._chatadministratorrights import ChatAdministratorRights
Expand Down Expand Up @@ -280,6 +284,7 @@
from ._inline.inlinequeryresultlocation import InlineQueryResultLocation
from ._inline.inlinequeryresultmpeg4gif import InlineQueryResultMpeg4Gif
from ._inline.inlinequeryresultphoto import InlineQueryResultPhoto
from ._inline.inlinequeryresultsbutton import InlineQueryResultsButton
from ._inline.inlinequeryresultvenue import InlineQueryResultVenue
from ._inline.inlinequeryresultvideo import InlineQueryResultVideo
from ._inline.inlinequeryresultvoice import InlineQueryResultVoice
Expand Down Expand Up @@ -336,6 +341,7 @@
from ._replykeyboardremove import ReplyKeyboardRemove
from ._sentwebappmessage import SentWebAppMessage
from ._shared import ChatShared, UserShared
from ._switchinlinequerychosenchat import SwitchInlineQueryChosenChat
from ._telegramobject import TelegramObject
from ._update import Update
from ._user import User
Expand Down
146 changes: 135 additions & 11 deletions telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
from telegram._botcommand import BotCommand
from telegram._botcommandscope import BotCommandScope
from telegram._botdescription import BotDescription, BotShortDescription
from telegram._botname import BotName
from telegram._chat import Chat
from telegram._chatadministratorrights import ChatAdministratorRights
from telegram._chatinvitelink import ChatInviteLink
Expand All @@ -79,6 +80,7 @@
from telegram._forumtopic import ForumTopic
from telegram._games.gamehighscore import GameHighScore
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresultsbutton import InlineQueryResultsButton
from telegram._menubutton import MenuButton
from telegram._message import Message
from telegram._messageid import MessageId
Expand Down Expand Up @@ -2811,8 +2813,15 @@ async def answer_inline_query(
cache_time: int = None,
is_personal: bool = None,
next_offset: str = None,
# Deprecated params since bot api 6.7
# <----
switch_pm_text: str = None,
switch_pm_parameter: str = None,
# --->
# New params since bot api 6.7
# <----
button: InlineQueryResultsButton = None,
# --->
*,
current_offset: str = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
Expand All @@ -2825,15 +2834,6 @@ async def answer_inline_query(
Use this method to send answers to an inline query. No more than
:tg-const:`telegram.InlineQuery.MAX_RESULTS` results per query 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.

Warning:
In most use cases :paramref:`current_offset` should not be passed manually. Instead of
calling this method directly, use the shortcut :meth:`telegram.InlineQuery.answer` with
Expand All @@ -2842,6 +2842,9 @@ async def answer_inline_query(

.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`

.. |api6_7_depr| replace:: Since Bot API 6.7, this argument is deprecated in favour of
:paramref:`button`.

Args:
inline_query_id (:obj:`str`): Unique identifier for the answered query.
results (List[:class:`telegram.InlineQueryResult`] | Callable): A list of results for
Expand All @@ -2862,12 +2865,22 @@ async def answer_inline_query(
switch_pm_text (:obj:`str`, optional): If passed, clients will display a button with
specified text that switches the user to a private chat with the bot and sends the
bot a start message with the parameter :paramref:`switch_pm_parameter`.

.. deprecated:: NEXT.VERSION
|api6_7_depr|
switch_pm_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.InlineQuery.MIN_SWITCH_PM_TEXT_LENGTH`-
:tg-const:`telegram.InlineQuery.MAX_SWITCH_PM_TEXT_LENGTH` characters,
only ``A-Z``, ``a-z``, ``0-9``, ``_`` and ``-`` are allowed.

.. deprecated:: NEXT.VERSION
|api6_7_depr|
button (:class:`telegram.InlineQueryResultsButton`, optional): A button to be shown
above the inline query results.

.. versionadded:: NEXT.VERSION

Keyword Args:
current_offset (:obj:`str`, optional): The :attr:`telegram.InlineQuery.offset` of
the inline query to answer. If passed, PTB will automatically take care of
Expand All @@ -2881,6 +2894,26 @@ async def answer_inline_query(
:class:`telegram.error.TelegramError`

"""
if (switch_pm_text or switch_pm_parameter) and button:
raise TypeError(
"Since Bot API 6.7, the parameter `button is mutually exclusive to the deprecated "
"parameters `switch_pm_text` and `switch_pm_parameter`. Please use the new "
"parameter `button`."
)

if switch_pm_text and switch_pm_parameter:
self._warn(
"Since Bot API 6.7, the parameters `switch_pm_text` and `switch_pm_parameter` are "
"deprecated in favour of the new parameter `button`. Please use the new parameter "
"`button` instead.",
category=PTBDeprecationWarning,
stacklevel=3,
)
button = InlineQueryResultsButton(
text=switch_pm_text,
start_parameter=switch_pm_parameter,
)

effective_results, next_offset = self._effective_inline_results(
results=results, next_offset=next_offset, current_offset=current_offset
)
Expand All @@ -2896,8 +2929,7 @@ async def answer_inline_query(
"next_offset": next_offset,
"cache_time": cache_time,
"is_personal": is_personal,
"switch_pm_text": switch_pm_text,
"switch_pm_parameter": switch_pm_parameter,
"button": button,
}

return await self._post(
Expand Down Expand Up @@ -8138,6 +8170,94 @@ async def get_my_short_description(
bot=self,
)

@_log
async def set_my_name(
self,
name: str = None,
language_code: str = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> bool:
"""
Use this method to change the bot's name.

.. versionadded:: NEXT.VERSION

Args:
name (:obj:`str`, optional): New bot name;
0-:tg-const:`telegram.constants.BotNameLimit.MAX_NAME_LENGTH`
characters. Pass an empty string to remove the dedicated name for the given
language.

Caution:
If :paramref:`language_code` is not specified, a :paramref:`name` *must*
be specified.
language_code (:obj:`str`, optional): A two-letter ISO 639-1 language code. If empty,
the name will be applied to all users for whose language there is no
dedicated name.

Returns:
:obj:`bool`: On success, :obj:`True` is returned.

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

"""
data: JSONDict = {"name": name, "language_code": language_code}

return await self._post(
"setMyName",
data,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
)

@_log
async def get_my_name(
self,
language_code: str = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> BotName:
"""
Use this method to get the current bot name for the given user language.

Args:
language_code (:obj:`str`, optional): A two-letter ISO 639-1 language code or an empty
string.

Returns:
:class:`telegram.BotName`: On success, the bot name is returned.

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

"""
data = {"language_code": language_code}
return BotName.de_json( # type: ignore[return-value]
await self._post(
"getMyName",
data,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
),
bot=self,
)

def to_dict(self, recursive: bool = True) -> JSONDict: # skipcq: PYL-W0613
"""See :meth:`telegram.TelegramObject.to_dict`."""
data: JSONDict = {"id": self.id, "username": self.username, "first_name": self.first_name}
Expand Down Expand Up @@ -8382,3 +8502,7 @@ def __hash__(self) -> int:
"""Alias for :meth:`set_sticker_keywords`"""
setStickerMaskPosition = set_sticker_mask_position
"""Alias for :meth:`set_sticker_mask_position`"""
setMyName = set_my_name
"""Alias for :meth:`set_my_name`"""
getMyName = get_my_name
"""Alias for :meth:`get_my_name`"""
Loading
0