Skip to content

Filters.regex fails on non-text messages #1115

@Thorbijoern

Description

@Thorbijoern

Steps to reproduce

  1. given a handler like the following:
    def msg(bot, update): answer = random.choice(bot_misc.ANSWERS) update.message.reply_text(answer) updater.dispatcher.add_handler(MessageHandler(Filters.regex('Hi'), msg))

  2. send the bot some kind of media (like a sticker, an image or a voice-message)

  3. error (success)

Expected behaviour

I usually expect a regex filter to imply Filters.text (that the message is text), because you can only regex over text...

Actual behaviour

the regex filter fails with the following error when it tries to process the update:
2018-05-21 18:15:43,279 - telegram.ext.dispatcher - ERROR - An uncaught error was raised while processing the update Traceback (most recent call last): File "/home/thorbijoern/env/ptb/lib/python3.6/site-packages/telegram/ext/dispatcher.py", line 278, in process_update for handler in (x for x in self.handlers[group] if x.check_update(update)): File "/home/thorbijoern/env/ptb/lib/python3.6/site-packages/telegram/ext/dispatcher.py", line 278, in <genexpr> for handler in (x for x in self.handlers[group] if x.check_update(update)): File "/home/thorbijoern/env/ptb/lib/python3.6/site-packages/telegram/ext/messagehandler.py", line 152, in check_update res = self.filters(message) File "/home/thorbijoern/env/ptb/lib/python3.6/site-packages/telegram/ext/filters.py", line 65, in __call__ return self.filter(message) File "/home/thorbijoern/env/ptb/lib/python3.6/site-packages/telegram/ext/filters.py", line 201, in filter return bool(self.pattern.search(message.text)) TypeError: expected string or bytes-like object

workaround

a workaround would be just using (Filters.text & Filters.regex('foo')).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions