[Question] Cannot start a dialog consecutively twice?
I know the title is terrible.
Bot Info
- SDK Platform: Node.js
- SDK Version: 3.13.1
- Deployment Environment: Heroku + Azure Bot Service
Issue Description
In my bot, some dialogs bind to a command. Now, if I try to trigger the dialog twice, I'll be able to trigger it first, but not the second time.
Code Example
bot.dialog("a", (session) => {session.endDialog("ok")}).triggerAction({matches: /a/gi});
bot.dialog("b", [...]).triggerAction({matches: /b/gi});
bot.dialog("/", (session) => {session.endDialog("not ok")}); // Default dialog, obviously
Reproduction Steps
- Input
a. - You get "ok".
- Input
aagain.
Expected Behavior
You get "ok" which is written in dialog a.
Actual Results
You get "not ok" which is written in dialog / instead.
When a dialog runs and completes, it returns to the parent. As that dialog has already executed, it goes on to the default if nothing else matches it. I believe this is by design.
What you could try to workaround this and get your desired functionality is performing a test on the match inside the default method of the dialog you're trying to trigger multiple times in a row,
Example:
bot.dialog("a", (session) => {session.endDialog("ok")}).triggerAction({matches: /a/gi});
bot.dialog("b", [...]).triggerAction({matches: /b/gi});
bot.dialog("/", (session) => {
if (/a/gi.test(session.message.text)) {
session.beginDialog("a");
return; // prevents the rest of the default from processing.
}
if (/b/gi.test(session.message.text)) {
session.beginDialog("b");
return; // prevents the rest of the default from processing.
}
session.endDialog("not ok")
}); // Default dialog, obviously
You'll want to be careful if there are choices that could trigger multiple dialogs, so you'll want to make sure the trigger conditions are unique and won't match another by accident for this to work.
Triggers are unique. I think this can be a workaround. Thanks @nodeomega !
you can write a test to automate checking this (and imo is faster and easier than using the emulator) with mocha/chai or ava using the BotTester framework
const { BotTester, TestConnector } = require('bot-tester');
const FunctionToInitializeYourBotWithConnector = require('wherever it lives')
describe('Bot Test', () => {
it('Dialog can be started consecutively twice', () => {
const bot = FunctionToInitializeYourBotWithConnector(TestConnector);
return new BotTester(bot)
.sendMessageToBot('a', 'ok')
.sendMessageToBot('a', 'ok')
.runTest();
});
});
you can also inspect session state and run expectations against it to ensure you're where you expect/want in the dialog stack.
Closing the issue assuming it as resolved. Please reopen a new issue if it still persists.