I'm running into an issue using regex patterns in botkit conversations that I can't quite work through, and though I'm sure someone else will have a quick answer, I'm utterly stumped.
I'm building a conversation that will store user information in a JSON file, but I need a small amount of validation on the entries before I store them. Specifically, the inputs must either be a full name (any number of words greater than one with a space between them) or a domain username in the format of domain\name with no spaces and the correct domain.
Using RegExr, I came up with the following regEx expressions which match in that user interface but which will not match when placed in the "pattern" attribute of the botkit conversation node:
\w+( +\w+)+
for the any number of words with a space between them.domain+(\\+\w+)
for the specified domain + a username
But when I use these in the botkit conversation, they're not matching -- so I'm not quite clear on what I'm doing wrong.
Here's the code snippet in which these are being used:
bot.startConversation(message, function (err, convo) {
convo.say("I don't know who you are in TFS. Can you tell me?");
convo.addQuestion("You can say \"no\" or tell me your TFS name or your domain name (eg: \"domain\\username)", [
{
pattern: bot.utterances.no,
callback: function (response, convo) {
convo.say("Okay, maybe another time then.");
convo.next();
}
},
{
pattern: '\w+( +\w+)+',
callback: function (response, convo) {
convo.say("You said your TFS name is " + response.text);
convo.next();
}
},
{
pattern: 'domain+(\\+\w+)+',
callback: function (response, convo) {
convo.say("You said your TFS name is " + response.text);
convo.next();
}
},
{
default: true,
callback: function (response, convo) {
convo.say("I didn't understand that.");
convo.repeat();
convo.next();
}
}
], {}, 'default');