@@ -171,6 +171,8 @@ def __init__(self, token: str, parse_mode: Optional[str]=None, offset: Optional[
171171 self .my_chat_member_handlers = []
172172 self .chat_member_handlers = []
173173 self .chat_join_request_handlers = []
174+ self .removed_chat_boost_handlers = []
175+ self .chat_boost_handlers = []
174176 self .custom_filters = {}
175177 self .state_handlers = []
176178 self .middlewares = []
@@ -590,6 +592,8 @@ async def process_new_updates(self, updates: List[types.Update]):
590592 new_my_chat_members = None
591593 new_chat_members = None
592594 chat_join_request = None
595+ removed_chat_boost_handlers = None
596+ chat_boost_handlers = None
593597 for update in updates :
594598 logger .debug ('Processing updates: {0}' .format (update ))
595599 if update .message :
@@ -640,6 +644,12 @@ async def process_new_updates(self, updates: List[types.Update]):
640644 if update .message_reaction_count :
641645 if new_message_reaction_count_handlers is None : new_message_reaction_count_handlers = []
642646 new_message_reaction_count_handlers .append (update .message_reaction_count )
647+ if update .chat_boost :
648+ if chat_boost_handlers is None : chat_boost_handlers = []
649+ chat_boost_handlers .append (update .chat_boost )
650+ if update .removed_chat_boost :
651+ if removed_chat_boost_handlers is None : removed_chat_boost_handlers = []
652+ removed_chat_boost_handlers .append (update .removed_chat_boost )
643653
644654
645655 if new_messages :
@@ -674,6 +684,8 @@ async def process_new_updates(self, updates: List[types.Update]):
674684 await self .process_new_message_reaction (new_message_reactions )
675685 if new_message_reaction_count_handlers :
676686 await self .process_new_message_reaction_count (new_message_reaction_count_handlers )
687+ if chat_boost_handlers :
688+ await self .process_new_chat_boost (chat_boost_handlers )
677689
678690 async def process_new_messages (self , new_messages ):
679691 """
@@ -772,6 +784,18 @@ async def process_chat_join_request(self, chat_join_request):
772784 """
773785 await self ._process_updates (self .chat_join_request_handlers , chat_join_request , 'chat_join_request' )
774786
787+ async def process_new_chat_boost (self , chat_boost ):
788+ """
789+ :meta private:
790+ """
791+ await self ._process_updates (self .chat_boost_handlers , chat_boost , 'chat_boost' )
792+
793+ async def process_new_removed_chat_boost (self , removed_chat_boost ):
794+ """
795+ :meta private:
796+ """
797+ await self ._process_updates (self .removed_chat_boost_handlers , removed_chat_boost , 'removed_chat_boost' )
798+
775799 async def _get_middlewares (self , update_type ):
776800 """
777801 :meta private:
@@ -2002,6 +2026,105 @@ def register_chat_join_request_handler(self, callback: Callable[[Any], Awaitable
20022026 handler_dict = self ._build_handler_dict (callback , func = func , pass_bot = pass_bot , ** kwargs )
20032027 self .add_chat_join_request_handler (handler_dict )
20042028
2029+
2030+ def chat_boost_handler (self , func = None , ** kwargs ):
2031+ """
2032+ Handles new incoming chat boost state.
2033+ it passes :class:`telebot.types.ChatBoostUpdated` object.
2034+
2035+ :param func: Function executed as a filter
2036+ :type func: :obj:`function`
2037+
2038+ :param kwargs: Optional keyword arguments(custom filters)
2039+ :return: None
2040+ """
2041+ def decorator (handler ):
2042+ handler_dict = self ._build_handler_dict (handler , func = func , ** kwargs )
2043+ self .add_chat_boost_handler (handler_dict )
2044+ return handler
2045+
2046+ return decorator
2047+
2048+ def add_chat_boost_handler (self , handler_dict ):
2049+ """
2050+ Adds a chat_boost handler.
2051+ Note that you should use register_chat_boost_handler to add chat_boost_handler to the bot.
2052+
2053+ :meta private:
2054+
2055+ :param handler_dict:
2056+ :return:
2057+ """
2058+ self .chat_boost_handlers .append (handler_dict )
2059+
2060+ def register_chat_boost_handler (self , callback : Callable , func : Optional [Callable ]= None , pass_bot :Optional [bool ]= False , ** kwargs ):
2061+ """
2062+ Registers chat boost handler.
2063+
2064+ :param callback: function to be called
2065+ :type callback: :obj:`function`
2066+
2067+ :param func: Function executed as a filter
2068+ :type func: :obj:`function`
2069+
2070+ :param pass_bot: True if you need to pass TeleBot instance to handler(useful for separating handlers into different files)
2071+
2072+ :param kwargs: Optional keyword arguments(custom filters)
2073+
2074+ :return: None
2075+ """
2076+ handler_dict = self ._build_handler_dict (callback , func = func , pass_bot = pass_bot , ** kwargs )
2077+ self .add_chat_boost_handler (handler_dict )
2078+
2079+ def removed_chat_boost_handler (self , func = None , ** kwargs ):
2080+ """
2081+ Handles new incoming chat boost state.
2082+ it passes :class:`telebot.types.ChatBoostRemoved` object.
2083+
2084+ :param func: Function executed as a filter
2085+ :type func: :obj:`function`
2086+
2087+ :param kwargs: Optional keyword arguments(custom filters)
2088+ :return: None
2089+ """
2090+ def decorator (handler ):
2091+ handler_dict = self ._build_handler_dict (handler , func = func , ** kwargs )
2092+ self .add_removed_chat_boost_handler (handler_dict )
2093+ return handler
2094+
2095+ return decorator
2096+
2097+ def add_removed_chat_boost_handler (self , handler_dict ):
2098+ """
2099+ Adds a removed_chat_boost handler.
2100+ Note that you should use register_removed_chat_boost_handler to add removed_chat_boost_handler to the bot.
2101+
2102+ :meta private:
2103+
2104+ :param handler_dict:
2105+ :return:
2106+ """
2107+ self .removed_chat_boost_handlers .append (handler_dict )
2108+
2109+ def register_removed_chat_boost_handler (self , callback : Callable , func : Optional [Callable ]= None , pass_bot :Optional [bool ]= False , ** kwargs ):
2110+ """
2111+ Registers removed chat boost handler.
2112+
2113+ :param callback: function to be called
2114+ :type callback: :obj:`function`
2115+
2116+ :param func: Function executed as a filter
2117+ :type func: :obj:`function`
2118+
2119+ :param pass_bot: True if you need to pass TeleBot instance to handler(useful for separating handlers into different files)
2120+
2121+ :param kwargs: Optional keyword arguments(custom filters)
2122+
2123+ :return: None
2124+ """
2125+ handler_dict = self ._build_handler_dict (callback , func = func , pass_bot = pass_bot , ** kwargs )
2126+ self .add_removed_chat_boost_handler (handler_dict )
2127+
20052128 @staticmethod
20062129 def _build_handler_dict (handler , pass_bot = False , ** filters ):
20072130 """
0 commit comments