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

Fix mention extraction when parsing message for non-breaking space characters sent by Slack #32

Merged
merged 2 commits into from
Apr 13, 2021

Conversation

kvnxiao
Copy link
Contributor

@kvnxiao kvnxiao commented Apr 12, 2021

When a user copy-and-pastes a command into Slack and hits enter, for some reason Slack sends the event payload with non-breaking space characters (unicode \u00A0), which causes omnibot to not detect a directed bot user in these cases and hence will not forward the even payload to the corresponding downstream bot.

e.g. raw text payloads:

  1. {"text": "@bot-name command"} -> omnibot knows this text payload is targeting a bot with the name bot-name
  2. {"text": "@bot-name\u00A0command"} -> omnibot does not know this text payload is targeting a bot because the original logic for setting directed = True is when text.split(' ')[0] == bot name, which in this case there is no ' ' char to split by because Slack sent us a non-breaking space character instead.

This change allows for any whitespace character to be between the @bot-mention and the start of the command for forwarding the payload downstream.

NOTE that Slack has acknowledged this issue as a bug but is unsure when this will be fixed by them upstream.

@@ -178,7 +180,7 @@ def extract_mentions(text, bot, channel):
with statsd.timer('parser.extract_mentions'):
to_me = False
at_me = '@{}'.format(bot.name)
if text.split(' ')[0] == at_me:
if SPACE_REGEX.split(text)[0] == at_me:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any unit tests can be added here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

@kvnxiao kvnxiao merged commit c81ae55 into master Apr 13, 2021
@kvnxiao kvnxiao deleted the nbsp-mention-fix branch April 13, 2021 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants