Skip to content

Commit

Permalink
Bot API 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
coder2020official committed Nov 6, 2021
1 parent 06c8782 commit 953e228
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
11 changes: 11 additions & 0 deletions examples/chat_join_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import telebot


bot = telebot.TeleBot('TOKEN')

@bot.chat_join_request_handler()
def make_some(message: telebot.types.ChatJoinRequest):
bot.send_message(message.chat.id, 'I accepted a new user!')
bot.approve_chat_join_request(message.chat.id, message.from_user.id)

bot.infinity_polling(allowed_updates=telebot.util.update_types)
28 changes: 28 additions & 0 deletions telebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ def process_new_updates(self, updates):
if new_chat_members is None: new_chat_members = []
new_chat_members.append(update.chat_member)
if update.chat_join_request:
print('we received1')
if chat_join_request is None: chat_join_request = []
chat_join_request.append(update.chat_join_request)

Expand Down Expand Up @@ -514,6 +515,7 @@ def process_new_updates(self, updates):
if new_chat_members:
self.process_new_chat_member(new_chat_members)
if chat_join_request:
print('we received2')
self.process_chat_join_request(chat_join_request)


Expand Down Expand Up @@ -1747,6 +1749,32 @@ def export_chat_invite_link(self, chat_id: Union[int, str]) -> str:
"""
return apihelper.export_chat_invite_link(self.token, chat_id)

def approve_chat_join_request(self, chat_id: Union[str, int], user_id: Union[int, str]) -> bool:
"""
Use this method to approve a chat join request.
The bot must be an administrator in the chat for this to work and must have
the can_invite_users administrator right. Returns True on success.
:param chat_id: Unique identifier for the target chat or username of the target supergroup
(in the format @supergroupusername)
:param user_id: Unique identifier of the target user
:return: True on success.
"""
return apihelper.approve_chat_join_request(self.token, chat_id, user_id)

def decline_chat_join_request(self, chat_id: Union[str, int], user_id: Union[int, str]) -> bool:
"""
Use this method to decline a chat join request.
The bot must be an administrator in the chat for this to work and must have
the can_invite_users administrator right. Returns True on success.
:param chat_id: Unique identifier for the target chat or username of the target supergroup
(in the format @supergroupusername)
:param user_id: Unique identifier of the target user
:return: True on success.
"""
return apihelper.decline_chat_join_request(self.token, chat_id, user_id)

def set_chat_photo(self, chat_id: Union[int, str], photo: Any) -> bool:
"""
Use this method to set a new profile photo for the chat. Photos can't be changed for private chats.
Expand Down
15 changes: 14 additions & 1 deletion telebot/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,20 @@ def export_chat_invite_link(token, chat_id):
payload = {'chat_id': chat_id}
return _make_request(token, method_url, params=payload, method='post')


def approve_chat_join_request(token, chat_id, user_id):
method_url = 'approveChatJoinRequest'
payload = {
'chat_id': chat_id,
'user_id': user_id
}
return _make_request(token, method_url, params=payload, method='post')
def decline_chat_join_request(token, chat_id, user_id):
method_url = 'declineChatJoinRequest'
payload = {
'chat_id': chat_id,
'user_id': user_id
}
return _make_request(token, method_url, params=payload, method='post')
def set_chat_photo(token, chat_id, photo):
method_url = 'setChatPhoto'
payload = {'chat_id': chat_id}
Expand Down
7 changes: 4 additions & 3 deletions telebot/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ def de_json(cls, json_string):
chat_join_request = ChatJoinRequest.de_json(obj.get('chat_join_request'))
return cls(update_id, message, edited_message, channel_post, edited_channel_post, inline_query,
chosen_inline_result, callback_query, shipping_query, pre_checkout_query, poll, poll_answer,
my_chat_member, chat_member)
my_chat_member, chat_member, chat_join_request)

def __init__(self, update_id, message, edited_message, channel_post, edited_channel_post, inline_query,
chosen_inline_result, callback_query, shipping_query, pre_checkout_query, poll, poll_answer,
my_chat_member, chat_member):
my_chat_member, chat_member, chat_join_request):
self.update_id = update_id
self.message = message
self.edited_message = edited_message
Expand All @@ -129,6 +129,7 @@ def __init__(self, update_id, message, edited_message, channel_post, edited_chan
self.poll_answer = poll_answer
self.my_chat_member = my_chat_member
self.chat_member = chat_member
self.chat_join_request = chat_join_request


class ChatMemberUpdated(JsonDeserializable):
Expand Down Expand Up @@ -173,7 +174,7 @@ def de_json(cls, json_string):
if json_string is None: return None
obj = cls.check_json(json_string)
obj['chat'] = Chat.de_json(obj['chat'])
obj['from'] = User.de_json(obj['from'])
obj['from_user'] = User.de_json(obj['from'])

return cls(**obj)

Expand Down
2 changes: 1 addition & 1 deletion telebot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
update_types = [
"update_id", "message", "edited_message", "channel_post", "edited_channel_post", "inline_query",
"chosen_inline_result", "callback_query", "shipping_query", "pre_checkout_query", "poll", "poll_answer",
"my_chat_member", "chat_member"
"my_chat_member", "chat_member", "chat_join_request"
]

class WorkerThread(threading.Thread):
Expand Down

0 comments on commit 953e228

Please sign in to comment.