Question: sending proactive message without breaking the dialog stack
Hi. I read the document and already know that saving address and use with universalBot.send can send any message, or beginDialog to clean up existing stack and start a new one. However, I wonder if there is a way to "hack" into session and send proactive message without breaking the current dialog stack?
Thanks! I am using the Nodejs SDK.
what do you mean by that? Explain in details..
Hi. The use case is like this: my user is in the middle of a dialog stack doing something, and I want to send a "broadcast" quiz (a choice prompt) and get the result from the user input. After that, the user can resume the previous dialog. The problem now is that by "beginDialog" from a UniversalBot, it clears up all existing dialog stack and restart a new one, as compared to a dialog started by a session. So how to send a proactive message using a stored Address and push it to the existing dialog stack?
That's an interesting problem... I had to think about that a bit but it is doable. You need to manually trigger an global beginDialogAction(). Ironically enough you'd do this in a much similar way to sending a proactive message using bot.send() but you'll want to call bot.receive() with your proactive message. Define your action as something like this:
bot.beginDialogAction('sendQuiz', '/sendQuiz');
bot.dialog('sendQuiz', [
function (session, args) {
var question = args.data;
Then to trigger it do something like this:
var msg = new builder.Message().address(savedAddress).text('action?sendQuiz=' + question);
bot.receive(msg);
Conceptually you can think of this as the user pressing a button called "sendQuiz" and you've bound that button to your beginDialogAction(). Since you never send them a card with a button for them to press you're just proactively pressing it for them.
I forgot to add that the '/sendQuiz' dialog will get pushed onto the stack and after they answer the question they'll automatically be returned to where they were which sounds like your desired behavior.
Did @Stevenic solve your problem?
I'm closing this for now. I'm actually thinking of a simpler way to support this scenario in 3.6. But the above should work.
so to summarize this, you would have the bot.beginDialogAction inside a setInterval?
setInterval(function () {
var newAddresses = addresses.splice(0);
newAddresses.forEach(function (address) {
console.log('Starting survey for address:', address);
// new conversation address, copy without conversationId
var newConversationAddress = Object.assign({}, address);
delete newConversationAddress.conversation;
// start survey dialog
bot.beginDialogAction('sendQuiz', '/sendQuiz')
});
}, 20000);
bot.dialog('sendQuiz', [
function (session, args) {
var question = args.data;
..
)
can you please clarify where var msg = new builder.Message().address(savedAddress).text('action?sendQuiz=' + question); bot.receive(msg); comes into the picture?
How is this done from a lib.dialog library ?
I get lib.receive(msg) ^
TypeError: lib.receive is not a function
workaround doesn't work in 3.13, getting type error id of undefined. any updates @Stevenic @chrimc62 ?
best link to follow : https://github.com/Microsoft/BotBuilder/issues/1930