howdyai / botkit-middleware-witai

Middleware for using Wit.ai with Botkit-powered bots
MIT License
87 stars 49 forks source link

message sent to wit.ai contains @mention #2

Open simpixelated opened 8 years ago

simpixelated commented 8 years ago

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 commented 8 years ago

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.

cesarvarela commented 7 years ago

Any news about this?

simpixelated commented 7 years ago

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.

makstaks commented 7 years ago

@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.

simpixelated commented 7 years ago

@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.

makstaks commented 7 years ago

@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.