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

Strip formatting from messages? #1053

Closed
callumacrae opened this issue Sep 18, 2015 · 7 comments
Closed

Strip formatting from messages? #1053

callumacrae opened this issue Sep 18, 2015 · 7 comments
Labels

Comments

@callumacrae
Copy link

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?

@tonydaly
Copy link

👍

@technicalpickles
Copy link
Member

That is a good question. It's going to depend on the adapter I think, because not every one has rich formatting.

Which adapter are you using? I'd guess Slack.

@bhuga
Copy link
Contributor

bhuga commented Sep 22, 2015

Receive middleware can solve this elegantly. It can edit the message before listeners attempt to match it. Here's an example that would let /ping also respond to a typo, /pnig:

module.exports = (robot) ->
  robot.receiveMiddleware (context, next, done) ->
    context.response.message.text = context.response.message.text.replace("pnig", "ping")
    next()
Hubot> /pnig
Hubot> PONG

If you can write a function to strip the formatting, you could replace the message text with the stripped message in a similar way.

@callumacrae
Copy link
Author

Yeah, we're using Slack.

A middleware would work. Not sure I can think of any cases where I would want robot.hear to be specifically matched against a formatted message, though.

@technicalpickles
Copy link
Member

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
Copy link
Member

This is adapter specific, so I filed slackapi/hubot-slack#241 to track Slack doing something special with formatting.

@bkeepers
Copy link
Contributor

Closing since this is being tracked in slackapi/hubot-slack#241

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants