Botkit: remove @direct_mention from middleware receive message text

Created on 10 Apr 2016  路  3Comments  路  Source: howdyai/botkit

Is there a built-in way to strip the user (<@userid>) from the message.text that is passed to the middleware receive function? Currently it comes baked into the string, so I'd have to manually parse it out in the middleware with regex.

Crosspost from the botkit-middelware-witai: https://github.com/howdyai/botkit-middleware-witai/issues/2

The message.text value passed to the middleware.receive function contains the username mentioned, which means it gets set to wit.ai. For example, a "direct_mention" shows up in wit.ai as:
@U0ZA78R19 testing pt 2. This may be an issue with how https://github.com/howdyai/botkit works, but is there any way to strip out the user prior to passing it to wit.captureTextIntent in the case of "direct_mention" and "direct_message"?

enhancement question

All 3 comments

I have the same problem and just do a basic and not very elegant:

function cleanID(id) {
        var newString = id.substr(2); //remove two first char
        return newString.substring(0,9);
    }

Closing as answered.

@airlikidh2 can you give an example of how I would use your cleanID function? I'm still seeing this same problem with both the witai and apiai middlewares when used with Slack.

Was this page helpful?
0 / 5 - 0 ratings