[Node.js SDK] Dialog prompt in bot.on('conversationUpdate') repeats itself in Web Chat
Bot Info
- SDK Platform: Node.js
- SDK Version: 3.14.0
- Active Channels: Direct Line, Web Chat
- Deployment Environment: Azure Bot Service, Azure App Service
Issue Description
I have a requirement to show greeting message and prompt for user when Web Chat appears first time. To implement this I am using code based on conversationUpdate activity as defined in code snippet below. The issue happens when user opens chat window first time: he sees greeting message once and then prompt with buttons to select an option, but when he selects any option, he sees prompt message second time again and only after second reply, code is executing correctly, which is NOT expected behaviour.
Code Example
'use strict';
const restify = require('restify');
const builder = require('botbuilder');
// Setup Restify Server
let server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat connector for communicating with the Bot Framework Service
let connector = new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
// Using in memory storage for test/dev purpose
let inMemoryStorage = new builder.MemoryBotStorage();
let bot = new builder.UniversalBot(connector, [
function (session) {
builder.Prompts.choice(session, "Please select your option?",
["Option 1", "Option 2"], { listStyle: builder.ListStyle.button });
},
function(session, results) {
if (results.response.index === 0) {
session.send("You've selected option 1")
} else {
let msg = "You've selected option 2";
session.endConversation(msg);
}
}
]).set('storage', inMemoryStorage);
bot.on('conversationUpdate', function (activity) {
if (activity.membersAdded) {
activity.membersAdded.forEach(function (identity) {
if (identity.id === activity.address.bot.id) {
var reply = new builder.Message()
.address(activity.address)
.text("Hi there!");
bot.send(reply);
bot.beginDialog(activity.address,'/');
}
});
}
});
Reproduction Steps
- Run the app with code above
- Open Web Chat iframe
- Test the dialog
Expected Behavior
Expected behaviour is when user sees prompt message from default dialog only once after greeting message.
Actual Results
Any ideas on that?
Does this error occur only with the first prompt option, or with either one?
@nodeomega Only with first prompt
It works fine in Bot Emulator, but issue occurs in Web Chat.
С уважением, Эмин Аскеров
2018-04-05 21:53 GMT+03:00 surya [email protected]:
[image: github] https://user-images.githubusercontent.com/14793809/38385784-7481baf6-3930-11e8-9d1f-2f025776cac4.PNG
is this what you are expecting? If yes, I replicated the same code you posted.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Microsoft/BotBuilder/issues/4387#issuecomment-379040450, or mute the thread https://github.com/notifications/unsubscribe-auth/ATAl4lsQ8hg8uWg6lpHD9c7nn9tXfQ29ks5tlmgtgaJpZM4TA9SU .
I'm still investigating this issue, and have found that it's not just WebChat that has the error. I tested this with a console app using DirectLine, and had the same problem occur with the repeat on the first set oif prompts, so this appears to be related to DirectLine itself.
I am continuing to troubleshoot and will advise as soon as I have a solution.
This is a known issue. ConversationUpdate does not send enough information to construct the data bags, and as a result the dialog state is not persisted. Please refer to the answer here for a workaround: https://github.com/Microsoft/BotBuilder/issues/4245
@easkerov, did @EricDahlvang's suggestion (#4245) help in resolving your issue?
@EricDahlvang @nodeomega I've tried solution in #4245 and it works as expected now with! Thank you so much!
@easkerov Excellent! We can consider this issue closed, and if you run into any more issues, feel free to open a new request.