mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 14:35:00 +01:00
ConversationHandler: Docs & edited_channel_post behavior (#2339)
* Update docs & ignore edited channel posts * typo * Apply suggestions from code review Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com> * Update telegram/ext/conversationhandler.py * fix pre-commit Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com>
This commit is contained in:
parent
36d49ea9cd
commit
544a3fbf48
2 changed files with 24 additions and 6 deletions
|
@ -58,8 +58,22 @@ class _ConversationTimeoutContext:
|
|||
|
||||
class ConversationHandler(Handler[Update]):
|
||||
"""
|
||||
A handler to hold a conversation with a single user by managing four collections of other
|
||||
handlers.
|
||||
A handler to hold a conversation with a single or multiple users through Telegram updates by
|
||||
managing four collections of other handlers.
|
||||
|
||||
Note:
|
||||
``ConversationHandler`` will only accept updates that are (subclass-)instances of
|
||||
:class:`telegram.Update`. This is, because depending on the :attr:`per_user` and
|
||||
:attr:`per_chat` ``ConversationHandler`` relies on
|
||||
:attr:`telegram.Update.effective_user` and/or :attr:`telegram.Update.effective_chat` in
|
||||
order to determine which conversation an update should belong to. For ``per_message=True``,
|
||||
``ConversationHandler`` uses ``update.callback_query.message.message_id`` when
|
||||
``per_chat=True`` and ``update.callback_query.inline_message_id`` when ``per_chat=False``.
|
||||
For a more detailed explanation, please see our `FAQ`_.
|
||||
|
||||
Finally, ``ConversationHandler``, does *not* handle (edited) channel posts.
|
||||
|
||||
.. _`FAQ`: https://git.io/JtcyU
|
||||
|
||||
The first collection, a ``list`` named :attr:`entry_points`, is used to initiate the
|
||||
conversation, for example with a :class:`telegram.ext.CommandHandler` or
|
||||
|
@ -424,7 +438,7 @@ class ConversationHandler(Handler[Update]):
|
|||
if not isinstance(update, Update):
|
||||
return None
|
||||
# Ignore messages in channels
|
||||
if update.channel_post:
|
||||
if update.channel_post or update.edited_channel_post:
|
||||
return None
|
||||
if self.per_chat and not update.effective_chat:
|
||||
return None
|
||||
|
|
|
@ -726,10 +726,14 @@ class TestConversationHandler:
|
|||
|
||||
def test_channel_message_without_chat(self, bot):
|
||||
handler = ConversationHandler(
|
||||
entry_points=[CommandHandler('start', self.start_end)], states={}, fallbacks=[]
|
||||
entry_points=[MessageHandler(Filters.all, self.start_end)], states={}, fallbacks=[]
|
||||
)
|
||||
message = Message(0, None, None, Chat(0, Chat.CHANNEL, 'Misses Test'), bot=bot)
|
||||
update = Update(0, message=message)
|
||||
message = Message(0, date=None, chat=Chat(0, Chat.CHANNEL, 'Misses Test'), bot=bot)
|
||||
|
||||
update = Update(0, channel_post=message)
|
||||
assert not handler.check_update(update)
|
||||
|
||||
update = Update(0, edited_channel_post=message)
|
||||
assert not handler.check_update(update)
|
||||
|
||||
def test_all_update_types(self, dp, bot, user1):
|
||||
|
|
Loading…
Reference in a new issue