Skip to content
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

API 7.2 #4180

Merged
merged 32 commits into from Apr 12, 2024
Merged

API 7.2 #4180

Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1fbac17
Add new parameter to bot methods and 2 new business params in Message
harshil21 Mar 31, 2024
4b0e7fc
Remove whitespace detected by ruff
harshil21 Mar 31, 2024
af341cc
Bump bot api version number
harshil21 Mar 31, 2024
735ed1e
fix pre-commit
harshil21 Mar 31, 2024
9c35dbd
doc fix
harshil21 Mar 31, 2024
badf3fc
Add new parameters to Update along with the new method
harshil21 Apr 1, 2024
6bb22f4
forgot to add method to extbot
harshil21 Apr 1, 2024
1b33dfa
Add new handlers and filters
harshil21 Apr 1, 2024
dc3c1b9
fix doc build and improve type completeness
harshil21 Apr 1, 2024
3ff7a68
Apply Sticker method and pack changes
harshil21 Apr 1, 2024
e942ebf
fix tests again
harshil21 Apr 2, 2024
dcb471e
Feat: add the field `is_from_offline` to the class `Message` (#4189)
mahdyar Apr 2, 2024
17b295a
Merge branch 'master' into api-7.2
Bibo-Joshi Apr 2, 2024
6b6fcf5
Revert "Temporarily Mark Tests with `get_sticker_set` as XFAIL due to…
Bibo-Joshi Apr 2, 2024
c67f751
Make test_drop_callback_data use NonchalantHttpxRequest to avoid floo…
harshil21 Apr 2, 2024
9250017
Add Birthdate class and field to Chat
harshil21 Apr 2, 2024
a1f86c6
Add replace_sticker_in_set method
harshil21 Apr 3, 2024
a9e0eda
Add can_connect_to_business field
harshil21 Apr 3, 2024
3d513ec
Add personal_chat to Chat
harshil21 Apr 3, 2024
c350584
Add filters.IS_FROM_OFFLINE
harshil21 Apr 3, 2024
f927ad0
Update test_official
harshil21 Apr 3, 2024
275fd33
Improve test coverage
harshil21 Apr 3, 2024
b3becd6
Doc fix for the new handlers
harshil21 Apr 4, 2024
9305a43
change business_connection_id test target
harshil21 Apr 4, 2024
bb9bdb4
Business info (#4183)
aelkheir Apr 6, 2024
0f99ace
Request Chat Improvements (tests remaining)
clot27 Apr 7, 2024
6935e6a
fix pre-commit
clot27 Apr 7, 2024
88bba66
Merge branch 'master' into api-7.2
Bibo-Joshi Apr 7, 2024
91b1da6
Review: remove business_connection_id from Message methods
harshil21 Apr 7, 2024
8addbf4
Work on UsersShared
Bibo-Joshi Apr 8, 2024
b1af7d5
Work on tests
Bibo-Joshi Apr 8, 2024
0fb2322
Fix docs and add TestSharedUser
Bibo-Joshi Apr 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
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-7.1-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-7.2-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 **7.1** are supported.
All types and methods of the Telegram Bot API **7.2** are supported.

Installing
==========
Expand Down
4 changes: 2 additions & 2 deletions README_RAW.rst
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-7.1-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-7.2-blue?logo=telegram
:target: https://core.telegram.org/bots/api-changelog
:alt: Supported Bot API versions

Expand Down Expand Up @@ -85,7 +85,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 **7.1** are supported.
All types and methods of the Telegram Bot API **7.2** are supported.

Installing
==========
Expand Down
12 changes: 8 additions & 4 deletions docs/source/inclusions/bot_methods.rst
Expand Up @@ -113,6 +113,10 @@
:align: left
:widths: 1 4

* - :meth:`~telegram.Bot.approve_chat_join_request`
- Used for approving a chat join request
* - :meth:`~telegram.Bot.decline_chat_join_request`
- Used for declining a chat join request
* - :meth:`~telegram.Bot.ban_chat_member`
- Used for banning a member from the chat
* - :meth:`~telegram.Bot.unban_chat_member`
Expand All @@ -137,10 +141,6 @@
- Used for editing a non-primary invite link
* - :meth:`~telegram.Bot.revoke_chat_invite_link`
- Used for revoking an invite link created by the bot
* - :meth:`~telegram.Bot.approve_chat_join_request`
- Used for approving a chat join request
* - :meth:`~telegram.Bot.decline_chat_join_request`
- Used for declining a chat join request
* - :meth:`~telegram.Bot.set_chat_photo`
- Used for setting a photo to a chat
* - :meth:`~telegram.Bot.delete_chat_photo`
Expand All @@ -155,6 +155,8 @@
- Used for unpinning a message
* - :meth:`~telegram.Bot.unpin_all_chat_messages`
- Used for unpinning all pinned chat messages
* - :meth:`~telegram.Bot.get_business_connection`
- Used for getting information about the business account.
* - :meth:`~telegram.Bot.get_user_profile_photos`
- Used for obtaining user's profile pictures
* - :meth:`~telegram.Bot.get_chat`
Expand Down Expand Up @@ -237,6 +239,8 @@
- Used for setting a sticker set of a chat
* - :meth:`~telegram.Bot.delete_chat_sticker_set`
- Used for deleting the set sticker set of a chat
* - :meth:`~telegram.Bot.replace_sticker_in_set`
- Used for replacing a sticker in a set
* - :meth:`~telegram.Bot.set_sticker_position_in_set`
- Used for moving a sticker's position in the set
* - :meth:`~telegram.Bot.set_sticker_set_title`
Expand Down
8 changes: 8 additions & 0 deletions docs/source/telegram.at-tree.rst
Expand Up @@ -6,6 +6,7 @@ Available Types

telegram.animation
telegram.audio
telegram.birthdate
telegram.botcommand
telegram.botcommandscope
telegram.botcommandscopeallchatadministrators
Expand All @@ -18,6 +19,12 @@ Available Types
telegram.botdescription
telegram.botname
telegram.botshortdescription
telegram.businessconnection
telegram.businessintro
telegram.businesslocation
telegram.businessopeninghours
telegram.businessopeninghoursinterval
telegram.businessmessagesdeleted
telegram.callbackquery
telegram.chat
telegram.chatadministratorrights
Expand Down Expand Up @@ -107,6 +114,7 @@ Available Types
telegram.replykeyboardremove
telegram.replyparameters
telegram.sentwebappmessage
telegram.shareduser
telegram.story
telegram.switchinlinequerychosenchat
telegram.telegramobject
Expand Down
7 changes: 7 additions & 0 deletions docs/source/telegram.birthdate.rst
@@ -0,0 +1,7 @@
Birthdate
=========

.. autoclass:: telegram.Birthdate
:members:
:show-inheritance:

6 changes: 6 additions & 0 deletions docs/source/telegram.businessconnection.rst
@@ -0,0 +1,6 @@
BusinessConnection
==================

.. autoclass:: telegram.BusinessConnection
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.businessintro.rst
@@ -0,0 +1,6 @@
BusinessIntro
==================

.. autoclass:: telegram.BusinessIntro
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.businesslocation.rst
@@ -0,0 +1,6 @@
BusinessLocation
==================

.. autoclass:: telegram.BusinessLocation
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.businessmessagesdeleted.rst
@@ -0,0 +1,6 @@
BusinessMessagesDeleted
=======================

.. autoclass:: telegram.BusinessMessagesDeleted
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.businessopeninghours.rst
@@ -0,0 +1,6 @@
BusinessOpeningHours
====================

.. autoclass:: telegram.BusinessOpeningHours
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.businessopeninghoursinterval.rst
@@ -0,0 +1,6 @@
BusinessOpeningHoursInterval
============================

.. autoclass:: telegram.BusinessOpeningHoursInterval
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.ext.businessconnectionhandler.rst
@@ -0,0 +1,6 @@
BusinessConnectionHandler
=========================

.. autoclass:: telegram.ext.BusinessConnectionHandler
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.ext.businessmessagesdeletedhandler.rst
@@ -0,0 +1,6 @@
BusinessMessagesDeletedHandler
==============================

.. autoclass:: telegram.ext.BusinessMessagesDeletedHandler
:members:
:show-inheritance:
2 changes: 2 additions & 0 deletions docs/source/telegram.ext.handlers-tree.rst
Expand Up @@ -5,6 +5,8 @@ Handlers
:titlesonly:

telegram.ext.basehandler
telegram.ext.businessconnectionhandler
telegram.ext.businessmessagesdeletedhandler
telegram.ext.callbackqueryhandler
telegram.ext.chatboosthandler
telegram.ext.chatjoinrequesthandler
Expand Down
7 changes: 7 additions & 0 deletions docs/source/telegram.shareduser.rst
@@ -0,0 +1,7 @@
SharedUser
==========

.. autoclass:: telegram.SharedUser
:members:
:show-inheritance:

2 changes: 2 additions & 0 deletions docs/substitutions/global.rst
Expand Up @@ -79,3 +79,5 @@
.. |do_quote| replace:: If set to :obj:`True`, the replied message is quoted. For a dict, it must be the output of :meth:`~telegram.Message.build_reply_arguments` to specify exact ``reply_parameters``. If ``reply_to_message_id`` or ``reply_parameters`` are passed, this parameter will be ignored. Default: :obj:`True` in group chats and :obj:`False` in private chats.

.. |non_optional_story_argument| replace:: As of this version, this argument is now required. In accordance with our `stability policy <https://docs.python-telegram-bot.org/en/stable/stability_policy.html>`__, the signature will be kept as optional for now, though they are mandatory and an error will be raised if you don't pass it.

.. |business_id_str| replace:: Unique identifier of the business connection on behalf of which the message will be sent.
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -20,7 +20,7 @@ explicit-preview-rules = true
ignore = ["PLR2004", "PLR0911", "PLR0912", "PLR0913", "PLR0915", "PERF203"]
select = ["E", "F", "I", "PL", "UP", "RUF", "PTH", "C4", "B", "PIE", "SIM", "RET", "RSE",
"G", "ISC", "PT", "ASYNC", "TCH", "SLOT", "PERF", "PYI", "FLY", "AIR", "RUF022",
"RUF023", "Q", "INP",]
"RUF023", "Q", "INP", "W"]
# Add "FURB" after it's out of preview

[tool.ruff.lint.per-file-ignores]
Expand Down
19 changes: 18 additions & 1 deletion telegram/__init__.py
Expand Up @@ -22,6 +22,7 @@
__all__ = (
"Animation",
"Audio",
"Birthdate",
"Bot",
"BotCommand",
"BotCommandScope",
Expand All @@ -35,6 +36,12 @@
"BotDescription",
"BotName",
"BotShortDescription",
"BusinessConnection",
"BusinessIntro",
"BusinessLocation",
"BusinessMessagesDeleted",
"BusinessOpeningHours",
"BusinessOpeningHoursInterval",
"CallbackGame",
"CallbackQuery",
"Chat",
Expand Down Expand Up @@ -184,6 +191,7 @@
"SecureData",
"SecureValue",
"SentWebAppMessage",
"SharedUser",
"ShippingAddress",
"ShippingOption",
"ShippingQuery",
Expand Down Expand Up @@ -224,6 +232,7 @@


from . import _version, constants, error, helpers, request, warnings
from ._birthdate import Birthdate
from ._bot import Bot
from ._botcommand import BotCommand
from ._botcommandscope import (
Expand All @@ -238,6 +247,14 @@
)
from ._botdescription import BotDescription, BotShortDescription
from ._botname import BotName
from ._business import (
BusinessConnection,
BusinessIntro,
BusinessLocation,
BusinessMessagesDeleted,
BusinessOpeningHours,
BusinessOpeningHoursInterval,
)
from ._callbackquery import CallbackQuery
from ._chat import Chat
from ._chatadministratorrights import ChatAdministratorRights
Expand Down Expand Up @@ -393,7 +410,7 @@
from ._replykeyboardmarkup import ReplyKeyboardMarkup
from ._replykeyboardremove import ReplyKeyboardRemove
from ._sentwebappmessage import SentWebAppMessage
from ._shared import ChatShared, UsersShared
from ._shared import ChatShared, SharedUser, UsersShared
from ._story import Story
from ._switchinlinequerychosenchat import SwitchInlineQueryChosenChat
from ._telegramobject import TelegramObject
Expand Down
88 changes: 88 additions & 0 deletions telegram/_birthdate.py
harshil21 marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,88 @@
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2024
# 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 Birthday."""
from datetime import datetime
from typing import Optional

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


class Birthdate(TelegramObject):
"""
This object represents a user's birthday.

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

.. versionadded:: NEXT.VERSION

Args:
day (:obj:`int`): Day of the user's birth; 1-31.
month (:obj:`int`): Month of the user's birth; 1-12.
year (:obj:`int`, optional): Year of the user's birth.

Attributes:
day (:obj:`int`): Day of the user's birth; 1-31.
month (:obj:`int`): Month of the user's birth; 1-12.
year (:obj:`int`): Optional. Year of the user's birth.

"""

__slots__ = ("day", "month", "year")

def __init__(
self,
day: int,
month: int,
year: Optional[int] = None,
*,
api_kwargs: Optional[JSONDict] = None,
):
super().__init__(api_kwargs=api_kwargs)

# Required
self.day: int = day
self.month: int = month
# Optional
self.year: Optional[int] = year

self._id_attrs = (
self.day,
self.month,
)

self._freeze()

def to_date(self, year: Optional[int] = None) -> datetime:
"""Return the birthdate as a datetime object.

Args:
year (:obj:`int`, optional): The year to use. Required, if the :attr:`year` was not
present.

Returns:
:obj:`datetime.datetime`: The birthdate as a datetime object.
"""
if self.year is None and year is None:
raise ValueError(
"The `year` argument is required if the `year` attribute was not present."
)

return datetime(year or self.year, self.month, self.day) # type: ignore[arg-type]