diff --git a/telegram/ext/conversationhandler.py b/telegram/ext/conversationhandler.py index 25e22a4e8..0e52064fc 100644 --- a/telegram/ext/conversationhandler.py +++ b/telegram/ext/conversationhandler.py @@ -206,10 +206,11 @@ class ConversationHandler(Handler): """ # 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 b765eda18..332233681 100644 --- a/tests/test_conversationhandler.py +++ b/tests/test_conversationhandler.py @@ -20,7 +20,8 @@ from time import sleep 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 @@ class TestConversationHandler(object): 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))