@@ -130,6 +130,7 @@ def __init__(self, bot, update_queue, workers=4):
130130 self .bot = bot
131131 self .update_queue = update_queue
132132 self .telegram_message_handlers = []
133+ self .telegram_inline_handlers = []
133134 self .telegram_command_handlers = {}
134135 self .telegram_regex_handlers = {}
135136 self .string_regex_handlers = {}
@@ -236,21 +237,23 @@ def processUpdate(self, update):
236237 handled = True
237238
238239 # Telegram update (regex)
239- if isinstance (update , Update ):
240+ if isinstance (update , Update ) and update . message is not None :
240241 self .dispatchRegex (update )
241242 handled = True
242243
243- # Telegram update (command)
244- if isinstance (update , Update ) \
245- and update .message .text .startswith ('/' ):
246- self .dispatchTelegramCommand (update )
247- handled = True
248-
249- # Telegram update (message)
250- elif isinstance (update , Update ):
251- self .dispatchTelegramMessage (update )
252- handled = True
244+ # Telegram update (command)
245+ if update .message .text .startswith ('/' ):
246+ self .dispatchTelegramCommand (update )
253247
248+ # Telegram update (message)
249+ else :
250+ self .dispatchTelegramMessage (update )
251+ handled = True
252+ elif isinstance (update , Update ) and \
253+ (update .inline_query is not None or
254+ update .chosen_inline_result is not None ):
255+ self .dispatchTelegramInline (update )
256+ handled = True
254257 # Update not recognized
255258 if not handled :
256259 self .dispatchError (update , TelegramError (
@@ -268,6 +271,17 @@ def addTelegramMessageHandler(self, handler):
268271
269272 self .telegram_message_handlers .append (handler )
270273
274+ def addTelegramInlineHandler (self , handler ):
275+ """
276+ Registers an inline query handler in the Dispatcher.
277+
278+ Args:
279+ handler (function): A function that takes (Bot, Update, *args) as
280+ arguments.
281+ """
282+
283+ self .telegram_inline_handlers .append (handler )
284+
271285 def addTelegramCommandHandler (self , command , handler ):
272286 """
273287 Registers a command handler in the Dispatcher.
@@ -397,6 +411,17 @@ def removeTelegramMessageHandler(self, handler):
397411 if handler in self .telegram_message_handlers :
398412 self .telegram_message_handlers .remove (handler )
399413
414+ def removeTelegramInlineHandler (self , handler ):
415+ """
416+ De-registers an inline query handler.
417+
418+ Args:
419+ handler (any):
420+ """
421+
422+ if handler in self .telegram_inline_handlers :
423+ self .telegram_inline_handlers .remove (handler )
424+
400425 def removeTelegramCommandHandler (self , command , handler ):
401426 """
402427 De-registers a command handler.
@@ -574,6 +599,17 @@ def dispatchTelegramMessage(self, update):
574599
575600 self .dispatchTo (self .telegram_message_handlers , update )
576601
602+ def dispatchTelegramInline (self , update ):
603+ """
604+ Dispatches an update that contains an inline update.
605+
606+ Args:
607+ update (telegram.Update): The Telegram update that contains the
608+ message.
609+ """
610+
611+ self .dispatchTo (self .telegram_inline_handlers , update )
612+
577613 def dispatchError (self , update , error ):
578614 """
579615 Dispatches an error.
0 commit comments