Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filters.regex fails on non-text messages #1115

Closed
Thorbijoern opened this issue May 21, 2018 · 1 comment · Fixed by #1158
Closed

Filters.regex fails on non-text messages #1115

Thorbijoern opened this issue May 21, 2018 · 1 comment · Fixed by #1158
Labels

Comments

@Thorbijoern
Copy link

Thorbijoern commented May 21, 2018

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')).

@Eldinnie
Copy link
Member

Although there is a small addition to the expected behavior (it should also work on captions, not only text), it's bad behavior that it does not check this.
Thanks for the report.

jsmnbom pushed a commit that referenced this issue Aug 26, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Aug 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants