diff --git a/telegram/ext/conversationhandler.py b/telegram/ext/conversationhandler.py index a144420898b..c8589f190dc 100644 --- a/telegram/ext/conversationhandler.py +++ b/telegram/ext/conversationhandler.py @@ -206,10 +206,11 @@ def check_update(self, update): """ # Ignore messages in channels - if (not isinstance(update, Update) or update.channel_post or self.per_chat - and (update.inline_query or update.chosen_inline_result) or self.per_message - and not update.callback_query or update.callback_query and self.per_chat - and not update.callback_query.message): + if (not isinstance(update, Update) or + update.channel_post or + self.per_chat and not update.effective_chat or + self.per_message and not update.callback_query or + update.callback_query and self.per_chat and not update.callback_query.message): return False key = self._get_key(update) diff --git a/tests/test_conversationhandler.py b/tests/test_conversationhandler.py index d72b1eaf263..d0e29de4b94 100644 --- a/tests/test_conversationhandler.py +++ b/tests/test_conversationhandler.py @@ -20,7 +20,8 @@ import pytest -from telegram import Update, Message, User, Chat, CallbackQuery +from telegram import (CallbackQuery, Chat, ChosenInlineResult, InlineQuery, Message, + PreCheckoutQuery, ShippingQuery, Update, User) from telegram.ext import (ConversationHandler, CommandHandler, CallbackQueryHandler) @@ -277,3 +278,19 @@ def test_channel_message_without_chat(self, bot): message = Message(0, None, None, Chat(0, Chat.CHANNEL, 'Misses Test'), bot=bot) update = Update(0, message=message) assert not handler.check_update(update) + + def test_all_update_types(self, dp, bot, user1): + handler = ConversationHandler(entry_points=[CommandHandler('start', self.start_end)], + states={}, fallbacks=[]) + message = Message(0, user1, None, self.group, text='ignore', bot=bot) + callback_query = CallbackQuery(0, user1, None, message=message, data='data', bot=bot) + chosen_inline_result = ChosenInlineResult(0, user1, 'query', bot=bot) + inline_query = InlineQuery(0, user1, 'query', 0, bot=bot) + pre_checkout_query = PreCheckoutQuery(0, user1, 'USD', 100, [], bot=bot) + shipping_query = ShippingQuery(0, user1, [], None, bot=bot) + assert not handler.check_update(Update(0, callback_query=callback_query)) + assert not handler.check_update(Update(0, chosen_inline_result=chosen_inline_result)) + assert not handler.check_update(Update(0, inline_query=inline_query)) + assert not handler.check_update(Update(0, message=message)) + assert not handler.check_update(Update(0, pre_checkout_query=pre_checkout_query)) + assert not handler.check_update(Update(0, shipping_query=shipping_query))
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: