X Tutup
Skip to content

Commit c5598b9

Browse files
manoromjh0ker
authored andcommitted
* Fix Bug python-telegram-bot#571 ConversationHandler will not process CallbackQuery if per_chat=True and the CallbackQuery has no message attached to it (as is the case with buttons on inline results) * Adds test case for CallbackQuery without Chat
1 parent ca43510 commit c5598b9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

telegram/ext/conversationhandler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ def check_update(self, update):
174174
# Ignore messages in channels
175175
if (not isinstance(update, Update) or update.channel_post or self.per_chat
176176
and (update.inline_query or update.chosen_inline_result) or self.per_message
177-
and not update.callback_query):
177+
and not update.callback_query or update.callback_query and self.per_chat
178+
and not update.callback_query.message):
178179
return False
179180

180181
key = self._get_key(update)

tests/test_conversationhandler.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,14 @@ def test_endOnFirstMessageAsync(self):
322322
# Assert that the Promise has been resolved and the conversation ended.
323323
self.assertEquals(len(handler.conversations), 0)
324324

325+
def test_perChatMessageWithoutChat(self):
326+
handler = ConversationHandler(
327+
entry_points=[CommandHandler('start', self.start_end)], states={}, fallbacks=[])
328+
user = User(first_name="Misses Test", id=123)
329+
cbq = CallbackQuery(0, user, None, None)
330+
update = Update(0, callback_query=cbq)
331+
handler.check_update(update)
332+
325333

326334
if __name__ == '__main__':
327335
unittest.main()

0 commit comments

Comments
 (0)
X Tutup