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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions examples/asynchronous_telebot/date_time_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/python

# This example shows how to send a message with the Bot API 9.5 'date_time' entity.
# Telegram clients will render the selected text range as a localized date and time.

import asyncio
import time

from telebot import types
from telebot.async_telebot import AsyncTeleBot


API_TOKEN = '<api_token>'
bot = AsyncTeleBot(API_TOKEN)


@bot.message_handler(commands=['date_time'])
async def send_date_time(message):
unix_time = int(time.time()) + 3600
text = 'Reminder'
entity = types.MessageEntity(
type='date_time',
offset=0,
length=len(text),
unix_time=unix_time,
date_time_format='Dt'
)

await bot.send_message(message.chat.id, text, entities=[entity])


asyncio.run(bot.polling())
28 changes: 28 additions & 0 deletions examples/asynchronous_telebot/set_chat_member_tag_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/python

# This example shows how to assign a tag to a regular supergroup member.
# The bot must be an administrator with permission to manage tags.

import asyncio

from telebot.async_telebot import AsyncTeleBot


API_TOKEN = '<api_token>'
CHAT_ID = -1001234567890
USER_ID = 123456789
TAG = 'support'

bot = AsyncTeleBot(API_TOKEN)


async def main():
await bot.set_chat_member_tag(CHAT_ID, USER_ID, TAG)

member = await bot.get_chat_member(CHAT_ID, USER_ID)
print(member.tag)

await bot.close_session()


asyncio.run(main())
31 changes: 31 additions & 0 deletions examples/date_time_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/python

# This example shows how to send a message with the Bot API 9.5 'date_time' entity.
# Telegram clients will render the selected text range as a localized date and time.

import time

import telebot
from telebot import types


API_TOKEN = '<api_token>'
bot = telebot.TeleBot(API_TOKEN)


@bot.message_handler(commands=['date_time'])
def send_date_time(message):
unix_time = int(time.time()) + 3600
text = 'Reminder'
entity = types.MessageEntity(
type='date_time',
offset=0,
length=len(text),
unix_time=unix_time,
date_time_format='Dt'
)

bot.send_message(message.chat.id, text, entities=[entity])


bot.infinity_polling()
19 changes: 19 additions & 0 deletions examples/set_chat_member_tag_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/python

# This example shows how to assign a tag to a regular supergroup member.
# The bot must be an administrator with permission to manage tags.

import telebot


API_TOKEN = '<api_token>'
CHAT_ID = -1001234567890
USER_ID = 123456789
TAG = 'support'

bot = telebot.TeleBot(API_TOKEN)

bot.set_chat_member_tag(CHAT_ID, USER_ID, TAG)

member = bot.get_chat_member(CHAT_ID, USER_ID)
print(member.tag)
37 changes: 34 additions & 3 deletions telebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4236,8 +4236,8 @@ def send_message_draft(
parse_mode: Optional[str]=None,
entities: Optional[List[types.MessageEntity]]=None):
"""
Use this method to stream a partial message to a user while the message is being generated;
supported only for bots with forum topic mode enabled. Returns True on success.
Use this method to stream a partial message to a user while the message is being generated.
Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#sendmessagedraft

Expand Down Expand Up @@ -4487,7 +4487,8 @@ def promote_chat_member(
can_post_stories: Optional[bool]=None,
can_edit_stories: Optional[bool]=None,
can_delete_stories: Optional[bool]=None,
can_manage_direct_messages: Optional[bool]=None) -> bool:
can_manage_direct_messages: Optional[bool]=None,
can_manage_tags: Optional[bool]=None) -> bool:
"""
Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator
in the chat for this to work and must have the appropriate admin rights.
Expand Down Expand Up @@ -4561,6 +4562,10 @@ def promote_chat_member(
within the channel and decline suggested posts; for channels only
:type can_manage_direct_messages: :obj:`bool`

:param can_manage_tags: Pass True if the administrator can edit the tags of regular members;
for groups and supergroups only
:type can_manage_tags: :obj:`bool`

:return: True on success.
:rtype: :obj:`bool`
"""
Expand All @@ -4578,6 +4583,7 @@ def promote_chat_member(
can_manage_video_chats=can_manage_video_chats, can_manage_topics=can_manage_topics,
can_post_stories=can_post_stories, can_edit_stories=can_edit_stories,
can_delete_stories=can_delete_stories, can_manage_direct_messages=can_manage_direct_messages,
can_manage_tags=can_manage_tags,
)


Expand Down Expand Up @@ -4606,6 +4612,31 @@ def set_chat_administrator_custom_title(
return apihelper.set_chat_administrator_custom_title(self.token, chat_id, user_id, custom_title)


def set_chat_member_tag(
self, chat_id: Union[int, str], user_id: int, tag: Optional[str]=None) -> bool:
"""
Use this method to set a tag for a regular member in a group or a supergroup.
The bot must be an administrator in the chat for this to work and must have the can_manage_tags administrator right.
Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setchatmembertag

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

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

:param tag: New tag for the member; 0-16 characters, emoji are not allowed
:type tag: :obj:`str`

:return: True on success.
:rtype: :obj:`bool`
"""
return apihelper.set_chat_member_tag(self.token, chat_id, user_id, tag)


def ban_chat_sender_chat(self, chat_id: Union[int, str], sender_chat_id: Union[int, str]) -> bool:
"""
Use this method to ban a channel chat in a supergroup or a channel.
Expand Down
12 changes: 11 additions & 1 deletion telebot/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ def promote_chat_member(
can_restrict_members=None, can_pin_messages=None, can_promote_members=None,
is_anonymous=None, can_manage_chat=None, can_manage_video_chats=None,
can_manage_topics=None, can_post_stories=None, can_edit_stories=None,
can_delete_stories=None, can_manage_direct_messages=None):
can_delete_stories=None, can_manage_direct_messages=None, can_manage_tags=None):
method_url = 'promoteChatMember'
payload = {'chat_id': chat_id, 'user_id': user_id}
if can_change_info is not None:
Expand Down Expand Up @@ -1322,6 +1322,8 @@ def promote_chat_member(
payload['can_delete_stories'] = can_delete_stories
if can_manage_direct_messages is not None:
payload['can_manage_direct_messages'] = can_manage_direct_messages
if can_manage_tags is not None:
payload['can_manage_tags'] = can_manage_tags
return _make_request(token, method_url, params=payload, method='post')


Expand All @@ -1333,6 +1335,14 @@ def set_chat_administrator_custom_title(token, chat_id, user_id, custom_title):
return _make_request(token, method_url, params=payload, method='post')


def set_chat_member_tag(token, chat_id, user_id, tag=None):
method_url = 'setChatMemberTag'
payload = {'chat_id': chat_id, 'user_id': user_id}
if tag is not None:
payload['tag'] = tag
return _make_request(token, method_url, params=payload, method='post')


def ban_chat_sender_chat(token, chat_id, sender_chat_id):
method_url = 'banChatSenderChat'
payload = {'chat_id': chat_id, 'sender_chat_id': sender_chat_id}
Expand Down
39 changes: 35 additions & 4 deletions telebot/async_telebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5756,8 +5756,8 @@ async def send_message_draft(
parse_mode: Optional[str]=None,
entities: Optional[List[types.MessageEntity]]=None):
"""
Use this method to stream a partial message to a user while the message is being generated;
supported only for bots with forum topic mode enabled. Returns True on success.
Use this method to stream a partial message to a user while the message is being generated.
Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#sendmessagedraft

Expand Down Expand Up @@ -5996,7 +5996,8 @@ async def promote_chat_member(
can_post_stories: Optional[bool]=None,
can_edit_stories: Optional[bool]=None,
can_delete_stories: Optional[bool]=None,
can_manage_direct_messages: Optional[bool]=None) -> bool:
can_manage_direct_messages: Optional[bool]=None,
can_manage_tags: Optional[bool]=None) -> bool:
"""
Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator
in the chat for this to work and must have the appropriate admin rights.
Expand Down Expand Up @@ -6070,6 +6071,10 @@ async def promote_chat_member(
within the channel and decline suggested posts; for channels only
:type can_manage_direct_messages: :obj:`bool`

:param can_manage_tags: Pass True if the administrator can edit the tags of regular members;
for groups and supergroups only
:type can_manage_tags: :obj:`bool`

:return: True on success.
:rtype: :obj:`bool`
"""
Expand All @@ -6084,7 +6089,8 @@ async def promote_chat_member(
can_edit_messages, can_delete_messages, can_invite_users,
can_restrict_members, can_pin_messages, can_promote_members,
is_anonymous, can_manage_chat, can_manage_video_chats, can_manage_topics,
can_post_stories, can_edit_stories, can_delete_stories, can_manage_direct_messages=can_manage_direct_messages
can_post_stories, can_edit_stories, can_delete_stories,
can_manage_direct_messages=can_manage_direct_messages, can_manage_tags=can_manage_tags
)

async def set_chat_administrator_custom_title(
Expand Down Expand Up @@ -6112,6 +6118,31 @@ async def set_chat_administrator_custom_title(
return await asyncio_helper.set_chat_administrator_custom_title(self.token, chat_id, user_id, custom_title)


async def set_chat_member_tag(
self, chat_id: Union[int, str], user_id: int, tag: Optional[str]=None) -> bool:
"""
Use this method to set a tag for a regular member in a group or a supergroup.
The bot must be an administrator in the chat for this to work and must have the can_manage_tags administrator right.
Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setchatmembertag

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

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

:param tag: New tag for the member; 0-16 characters, emoji are not allowed
:type tag: :obj:`str`

:return: True on success.
:rtype: :obj:`bool`
"""
return await asyncio_helper.set_chat_member_tag(self.token, chat_id, user_id, tag)


async def ban_chat_sender_chat(self, chat_id: Union[int, str], sender_chat_id: Union[int, str]) -> bool:
"""
Use this method to ban a channel chat in a supergroup or a channel.
Expand Down
13 changes: 11 additions & 2 deletions telebot/asyncio_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ async def promote_chat_member(
can_restrict_members=None, can_pin_messages=None, can_promote_members=None,
is_anonymous=None, can_manage_chat=None, can_manage_video_chats=None, can_manage_topics=None,
can_post_stories=None, can_edit_stories=None, can_delete_stories=None,
can_manage_direct_messages=None):
can_manage_direct_messages=None, can_manage_tags=None):
method_url = 'promoteChatMember'
payload = {'chat_id': chat_id, 'user_id': user_id}
if can_change_info is not None:
Expand Down Expand Up @@ -1316,6 +1316,8 @@ async def promote_chat_member(
payload['can_delete_stories'] = can_delete_stories
if can_manage_direct_messages is not None:
payload['can_manage_direct_messages'] = can_manage_direct_messages
if can_manage_tags is not None:
payload['can_manage_tags'] = can_manage_tags
return await _process_request(token, method_url, params=payload, method='post')


Expand All @@ -1327,6 +1329,14 @@ async def set_chat_administrator_custom_title(token, chat_id, user_id, custom_ti
return await _process_request(token, method_url, params=payload, method='post')


async def set_chat_member_tag(token, chat_id, user_id, tag=None):
method_url = 'setChatMemberTag'
payload = {'chat_id': chat_id, 'user_id': user_id}
if tag is not None:
payload['tag'] = tag
return await _process_request(token, method_url, params=payload, method='post')


async def ban_chat_sender_chat(token, chat_id, sender_chat_id):
method_url = 'banChatSenderChat'
payload = {'chat_id': chat_id, 'sender_chat_id': sender_chat_id}
Expand Down Expand Up @@ -2784,4 +2794,3 @@ class RequestTimeout(Exception):
"""
pass


Loading