hubot-slack icon indicating copy to clipboard operation
hubot-slack copied to clipboard

Match on raw text instead of formatted text on incoming messages

Open technicalpickles opened this issue 10 years ago • 3 comments

This was originally filed at https://github.com/github/hubot/issues/1053 but I believe this to be an adapter specific problem. From @callumacrae:

We have a script which starts like this:

robot.hear /some sentence here/i, (msg) ->

However, it doesn't hear it if the words are formatted at all, e.g. "some sentence here".

Would it be possible / desired to remove formatting from messages before parsing them?

I suggested this:

Slack already has a place it strips formatting for links. That'd be a good place to do it for other things: https://github.com/slackhq/hubot-slack/blob/master/src/slack.coffee#L153-L192

I think it is going to be up to the adapters to strip formatting like this. They probably should preserve the raw message in case an adapter-specific script wants to do something about, like hubot-slack does here: https://github.com/slackhq/hubot-slack/blob/master/src/slack.coffee#L112-L120

technicalpickles avatar Oct 09 '15 20:10 technicalpickles

This is a tough call. We could probably add this functionality enabled by an optional flag, to maintain the current behavior.

UncannyBingo avatar Jun 27 '16 20:06 UncannyBingo

if someone would like to propose an API for optionally matching on an "unformatted" version of the message text, we are open to that. at the moment, we don't have any plans to implement this.

aoberoi avatar Oct 17 '17 19:10 aoberoi

since 4.4.0, rawMessage is available on each message. so if your script listens for all messages, you can inspect that property and do your own matching against it. here's the idea in some code (i haven't actually run this):

robot.listen((message) => {
  if (message.rawText) {
    return \some sentence here\.exec(message.rawText);
  }
  return false;
}, (response) => {
  response.reply('matched raw text!');
});

aoberoi avatar Mar 30 '18 00:03 aoberoi