ibm-cloud-solutions / hubot-ibmcloud-nlc

Adds a framework to enable Natural Language interactions in your Hubot scripts
http://www.ibm.com/
Other
11 stars 1 forks source link

Removing bot name from string for processing needs to be centralized in utils #62

Open CiaranHannigan opened 8 years ago

CiaranHannigan commented 8 years ago

Removing the bots name from strings is done several different ways in multiple places in the repo.

nlc.confidence.high

// Obtain statement from res removing the bot name
var text = res.message.text.replace(robot.name, '').trim();

nlc.receive.js

// Remove the bot name from the bot statement
if (text.indexOf(botName) >= 0){
    let botnameIndex = text.indexOf(botName);
    text = text.substring(botnameIndex + botName.length);
}

nlc.catchall.js

function stripBotName(text) {
    var nameToken = new RegExp('(^|\\s)@?' + botName + ':?\\s', 'g');
    return text.replace(nameToken, ' ').trim();
}
CiaranHannigan commented 8 years ago

We should remove all instances of bot name from the string, here is the list of permutations I can think of in Slack.

botname @botname botname: @botname: