botkit-middleware-witai icon indicating copy to clipboard operation
botkit-middleware-witai copied to clipboard

message sent to wit.ai contains @mention

Open simpixelated opened this issue 8 years ago • 6 comments

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"?

simpixelated avatar Apr 10 '16 15:04 simpixelated

I tried to wrap receive with a function that replaces the bot ID:

controller.middleware.receive.use(function (bot, message, next) {
  if (message.text) {
    var reg = new RegExp('^<@' + bot.identity.id + '>:?\s?');
    message.text = message.text.replace(reg, '').trim();
    wit.receive(bot, message, next);
  }
});

EDIT: this solves the problem with sending the message to wit.ai with the user ID stripped, but it breaks the hears middleware. Seems like botkit may be matching against that string to determine "direct_mention", so if the bot userid is not there it won't even get passed to middleware.hears.

simpixelated avatar Apr 10 '16 17:04 simpixelated

Any news about this?

cesarvarela avatar Aug 30 '16 23:08 cesarvarela

No news. I'm still seeing the issue with this and https://github.com/abeai/botkit-middleware-apiai. I think it needs to be fixed within the receive function of each middleware.

simpixelated avatar Jan 02 '17 00:01 simpixelated

@simpixelated I thought sending the @user_id to wit.ai was the expected behaviour, so in wit.ai I marked the @user_id as a contact and wit.ai began to correctly determine the intent of the phrase. Having the @user_id might be a useful piece of information to create more interesting functionality.

makstaks avatar Jan 12 '17 07:01 makstaks

@makstaks you have a good point; is there a way to filter it out of intents within wit.ai though? Last time I checked there was not, which meant I had to include both "this my intent" and "<@botid> this is my intent" in order to trigger the correct responses.

simpixelated avatar Jan 14 '17 16:01 simpixelated

@simpixelated Sorry I missed your message. I was including both, but after using wit.ai with actual users, I'm finding it is still not working very well, even with single word commands. I don't have a solution yet, for now I just disabled wit.

makstaks avatar Jan 31 '17 04:01 makstaks