2

I'm having issues using the bot.customAction for a simple QnA object, the expected result is to send "I'm wonderful as always, but thanks for asking!" if the user send "Fine and you?", "Well and you?", "Good and you?", I've tried 2 options as below

1st Option:

bot.customAction({
    matches: /^Fine and you$|^Good and you$|^Well and you$/i,
    onSelectAction: (session, args, next) => {
        session.send("I'm wonderful as always, but thanks for asking!");
    }
});

2nd Option:

bot.customAction({
    matches: "Fine and you?"|"Good and you?"|"Well and you?",
    onSelectAction: (session, args, next) => {
        session.send("I'm wonderful as always, but thanks for asking!");
    }
});

In the first option the matches only recognizes the exactly word without the question mark "?"

[BotFramework Emulator] Word recognized without the question mark "?"

In the second option nothing happened, just start the waterfall conversation

[BotFramework Emulator] Second option is ignored by bot and start the waterfall conversation

Thanks for your time!

1 Answer 1

1

Short answer

bot.customAction({
    matches: /^Fine and you|^Good and you|^Well and you/i,
    onSelectAction: (session, args, next) => {
        session.send("I'm wonderful as always, but thanks for asking!");
    }
});

First option

In regexes, ^ represents beginning of the string and $ represents end of the string. So when your regex was /^Fine and you$/, you were matching Fine and you with no extra content at the beginning or end.

To fix this, you need to make your regex more flexible.

/^Fine and you\??$/ 'Fine and you' with an optional question mark

/^Fine and you/ Any string that starts with 'Fine and you', with anything else after it (Fine and you foobar blah blah would also match)

You might benefit from an introduction to regexes

Second option

bot.customAction({
    matches: "Fine and you?"|"Good and you?"|"Well and you?",
    onSelectAction: (session, args, next) => {
        session.send("I'm wonderful as always, but thanks for asking!");
    }
});

In this example, you are using the bitwise OR operator (|)

The expression "Fine and you?"|"Good and you?"|"Well and you?" will resolve to 0, so this code is actually running

bot.customAction({
    matches: 0,
    onSelectAction: (session, args, next) => {
        session.send("I'm wonderful as always, but thanks for asking!");
    }
});

You should use a modified version of the regex you provided in your first example instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.