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

Bot API v8.2 #55

Merged
merged 11 commits into from
Jan 23, 2025
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<br>

<div align="center"> <a href="https://core.telegram.org/bots/api-changelog#november-17-2024"> <img src="https://img.shields.io/badge/Bot%20API-8.0-blue?logo=telegram" alt="Supported Bot API version"> </a> <a href="https://pypi.org/project/tgram/"> <img src="https://img.shields.io/pypi/v/tgram.svg?logo=python&logoColor=%23959DA5&label=pypi&labelColor=%23282f37" alt="PyPI"> </a> <a href="https://pepy.tech/project/tgram"> <img src="https://static.pepy.tech/badge/tgram" alt="Downloads"> </a> <a href="https://t.me/tgbot_channel"> <img src="https://img.shields.io/badge/Telegram-Channel-blue.svg?logo=telegram" alt="Telegram Channel"> </a> <a href="https://t.me/tgbot_chat"> <img src="https://img.shields.io/badge/Telegram-Group-blue.svg?logo=telegram" alt="Telegram Group"> </a> </div>
<div align="center"> <a href="https://core.telegram.org/bots/api-changelog#november-17-2024"> <img src="https://img.shields.io/badge/Bot%20API-8.2-blue?logo=telegram" alt="Supported Bot API version"> </a> <a href="https://pypi.org/project/tgram/"> <img src="https://img.shields.io/pypi/v/tgram.svg?logo=python&logoColor=%23959DA5&label=pypi&labelColor=%23282f37" alt="PyPI"> </a> <a href="https://pepy.tech/project/tgram"> <img src="https://static.pepy.tech/badge/tgram" alt="Downloads"> </a> <a href="https://t.me/tgbot_channel"> <img src="https://img.shields.io/badge/Telegram-Channel-blue.svg?logo=telegram" alt="Telegram Channel"> </a> <a href="https://t.me/tgbot_chat"> <img src="https://img.shields.io/badge/Telegram-Group-blue.svg?logo=telegram" alt="Telegram Group"> </a> </div>

## 🚀 Quick Start
Here's a basic example to get started with tgram:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tgram"
version = "1.12.4"
version = "1.12.5"
description = "Tgram is a user-friendly and lightweight Python library that simplifies interaction with the Telegram Bot API. It allows developers to easily create, manage, and automate Telegram bots."
authors = ["Zaid <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion tgram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"storage",
]

__version__ = "1.12.4"
__version__ = "1.12.5"

from . import (
filters,
Expand Down
9 changes: 9 additions & 0 deletions tgram/methods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@

from .bot.runner import Runner

from .chats.verify_chat import VerifyChat
from .chats.verify_user import VerifyUser
from .chats.remove_chat_verification import RemoveChatVerification
from .chats.remove_user_verification import RemoveUserVerification


class TelegramBotMethods(
AddStickerToSet,
Expand Down Expand Up @@ -282,5 +287,9 @@ class TelegramBotMethods(
UnRestrictChatMember,
UploadStickerFile,
Runner,
VerifyChat,
VerifyUser,
RemoveUserVerification,
RemoveChatVerification,
):
pass
26 changes: 26 additions & 0 deletions tgram/methods/chats/remove_chat_verification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import tgram

from typing import Union


class RemoveChatVerification:
async def remove_chat_verification(
self: "tgram.TgBot",
chat_id: Union[str, int],
) -> bool:
"""
Removes verification from a chat that is currently verified on behalf of the organization represented by the bot. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#removechatverification

:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
:type chat_id: :obj:`int` or :obj:`str`

:return: True on success
:rtype: :obj:`bool`
"""

result = await self(
"removeChatVerification",
chat_id=chat_id,
)
return result["result"]
24 changes: 24 additions & 0 deletions tgram/methods/chats/remove_user_verification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import tgram


class RemoveUserVerification:
async def remove_user_verification(
self: "tgram.TgBot",
user_id: int,
) -> bool:
"""
Removes verification from a user who is currently verified on behalf of the organization represented by the bot. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#removeuserverification

:param user_id: Unique identifier of the target user
:type user_id: :obj:`int`

:return: True on success
:rtype: :obj:`bool`
"""

result = await self(
"removeUserVerification",
user_id=user_id,
)
return result["result"]
28 changes: 28 additions & 0 deletions tgram/methods/chats/verify_chat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import tgram

from typing import Union


class VerifyChat:
async def verify_chat(
self: "tgram.TgBot", chat_id: Union[str, int], custom_description: str = None
) -> bool:
"""
Verifies a chat on behalf of the organization which is represented by the bot. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#verifychat

:param chat_id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)
:type chat_id: :obj:`int` or :obj:`str`

:param custom_description: UCustom description for the verification; 0-70 characters.
Must be empty if the organization isn't allowed to provide a custom verification description.
:type custom_description: :obj:`str`

:return: True on success
:rtype: :obj:`bool`
"""

result = await self(
"verifyChat", chat_id=chat_id, custom_description=custom_description
)
return result["result"]
26 changes: 26 additions & 0 deletions tgram/methods/chats/verify_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import tgram


class VerifyUser:
async def verify_user(
self: "tgram.TgBot", user_id: int, custom_description: str = None
) -> bool:
"""
Verifies a user on behalf of the organization which is represented by the bot. Returns True on success.
Telegram documentation: https://core.telegram.org/bots/api#verifyuser

:param user_id: Unique identifier of the target user
:type user_id: :obj:`int`

:param custom_description: UCustom description for the verification; 0-70 characters.
Must be empty if the organization isn't allowed to provide a custom verification description.
:type custom_description: :obj:`str`

:return: True on success
:rtype: :obj:`bool`
"""

result = await self(
"verifyUser", user_id=user_id, custom_description=custom_description
)
return result["result"]
6 changes: 6 additions & 0 deletions tgram/methods/messages/send_gift.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ async def send_gift(
self: "tgram.TgBot",
user_id: int,
gift_id: str,
pay_for_upgrade: bool = None,
text: str = None,
text_parse_mode: ParseMode = None,
text_entities: List[MessageEntity] = None,
Expand All @@ -24,6 +25,10 @@ async def send_gift(
:param gift_id: Identifier of the gift
:type gift_id: :obj:`str`

:param pay_for_upgrade: Pass True to pay for the gift upgrade from the bot's balance,
thereby making the upgrade free for the receiver
:type pay_for_upgrade: :obj:`bool`

:param text: Text that will be shown along with the gift; 0-255 characters
:type text: :obj:`str`

Expand All @@ -41,6 +46,7 @@ async def send_gift(
"sendGift",
user_id=user_id,
gift_id=gift_id,
pay_for_upgrade=pay_for_upgrade,
text=text,
text_parse_mode=text_parse_mode,
text_entities=text_entities,
Expand Down
6 changes: 6 additions & 0 deletions tgram/types/_gift.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Gift(Type_):
:param star_count: The number of Telegram Stars that must be paid to send the sticker
:type star_count: :obj:`int`

:param upgrade_star_count: Optional. The number of Telegram Stars that must be paid to upgrade the gift to a unique one
:type upgrade_star_count: :obj:`int

:param total_count: Optional. The total number of the gifts of this type that can be sent; for limited gifts only
:type total_count: :obj:`int`

Expand All @@ -34,6 +37,7 @@ def __init__(
id: "str" = None,
sticker: "tgram.types.Sticker" = None,
star_count: "int" = None,
upgrade_star_count: "int" = None,
total_count: "int" = None,
remaining_count: "int" = None,
me: "tgram.TgBot" = None,
Expand All @@ -43,6 +47,7 @@ def __init__(
self.id = id
self.sticker = sticker
self.star_count = star_count
self.upgrade_star_count = upgrade_star_count
self.total_count = total_count
self.remaining_count = remaining_count

Expand All @@ -55,6 +60,7 @@ def _parse(
id=d.get("id"),
sticker=tgram.types.Sticker._parse(me, d.get("sticker")),
star_count=d.get("star_count"),
upgrade_star_count=d.get("upgrade_star_count"),
total_count=d.get("total_count"),
remaining_count=d.get("remaining_count"),
)
Expand Down
6 changes: 0 additions & 6 deletions tgram/types/_inline_query_result_article.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ class InlineQueryResultArticle(Type_):
:param url: Optional. URL of the result
:type url: :obj:`str`

:param hide_url: Optional. Pass True, if you don't want the URL to be shown in the message
:type hide_url: :obj:`bool`

:param description: Optional. Short description of the result
:type description: :obj:`str`

Expand All @@ -54,7 +51,6 @@ def __init__(
input_message_content: "tgram.types.InputMessageContent" = None,
reply_markup: "tgram.types.InlineKeyboardMarkup" = None,
url: "str" = None,
hide_url: "bool" = None,
description: "str" = None,
thumbnail_url: "str" = None,
thumbnail_width: "int" = None,
Expand All @@ -69,7 +65,6 @@ def __init__(
self.input_message_content = input_message_content
self.reply_markup = reply_markup
self.url = url
self.hide_url = hide_url
self.description = description
self.thumbnail_url = thumbnail_url
self.thumbnail_width = thumbnail_width
Expand All @@ -91,7 +86,6 @@ def _parse(
me=me, d=d.get("reply_markup")
),
url=d.get("url"),
hide_url=d.get("hide_url"),
description=d.get("description"),
thumbnail_url=d.get("thumbnail_url"),
thumbnail_width=d.get("thumbnail_width"),
Expand Down
Loading