I have the following code to proactively send a message to the user when they enter the web chat and then begin the root dialog:
bot.on('conversationUpdate', function (message) {
console.log("Conversation update")
if (message.membersAdded) {
message.membersAdded.forEach(function (identity) {
if (message.membersAdded[0].id === message.address.bot.id) {
bot.send(new builder.Message()
.address(message.address)
.text("Hello! You've started a conversation"));
console.log("Conversation Updated")
bot.beginDialog(message.address, "/")
}
});
}
});
The root dialog will then begin another dialog which is be chained to more dialogs to ask a series of questions:
bot.dialog('/',function (session){
console.log("Root Dialog")
session.send("Root Dialog")
session.replaceDialog("/dialog1");
});
bot.dialog("/dialog1", [function(session){
console.log("Dialog1")
builder.Prompts.choice(session,"Are you there?", "Yes|No", {listStyle: builder.ListStyle.button});
},function(session){
.....
}]);
The bot will then start the dialog and ask a series of questions. This works fine on the emulator, however when I deploy the bot and run it in a web chat (or test in web chat on azure), the bot will start the root dialog again after receiving a response from '/dialog1' prompt, and then continue as normal.
Maybe the root dialog should be called upon the bot receiving a message from the user for the first time - either way both the emulator and web chat should be doing the same thing. Therefore, I'm not sure if the issue lies in the emulator or direct line/ web chat.
Logs:
2018-02-23T09:16:43.315918+00:00 app[web.1]: restify listening to http://[::]:21401
2018-02-23T09:16:43.785044+00:00 heroku[web.1]: State changed from starting to up
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
2018-02-23T09:16:37.821517+00:00 heroku[web.1]: Restarting
2018-02-23T09:16:37.822135+00:00 heroku[web.1]: State changed from up to starting
2018-02-23T09:16:38.557504+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-02-23T09:16:38.621179+00:00 heroku[web.1]: Process exited with status 143
2018-02-23T09:16:40.829258+00:00 heroku[web.1]: Starting process with command `npm start`
2018-02-23T09:16:42.697800+00:00 app[web.1]:
2018-02-23T09:16:42.697831+00:00 app[web.1]: > [email protected] start /app
2018-02-23T09:16:42.697832+00:00 app[web.1]: > node index.js
2018-02-23T09:16:42.697833+00:00 app[web.1]:
2018-02-23T09:16:43.315918+00:00 app[web.1]: restify listening to http://[::]:21401
2018-02-23T09:16:43.785044+00:00 heroku[web.1]: State changed from starting to up
2018-02-23T09:17:08.944909+00:00 app[web.1]: Conversation Updated
2018-02-23T09:17:08.946087+00:00 app[web.1]: The Bot State API is deprecated. Please refer to https://aka.ms/I6swrh for details on how to replace with your own storage.
2018-02-23T09:17:08.948859+00:00 heroku[router]: at=info method=POST path="/api/messages" host=mybot.herokuapp.com request_id=e0064177-f453-4b66-8b58-9a6a1bd405f4 fwd="13.94.247.233" dyno=web.1 connect=0ms service=181ms status=202 bytes=117 protocol=https
2018-02-23T09:17:12.070370+00:00 app[web.1]: Root Dialog
2018-02-23T09:17:12.070882+00:00 app[web.1]: Dialog1
2018-02-23T09:17:12.330680+00:00 app[web.1]: The Bot State API is deprecated. Please refer to https://aka.ms/I6swrh for details on how to replace with your own storage.
2018-02-23T09:17:18.504947+00:00 app[web.1]: The Bot State API is deprecated. Please refer to https://aka.ms/I6swrh for details on how to replace with your own storage.
2018-02-23T09:17:18.699714+00:00 app[web.1]: Root Dialog
2018-02-23T09:17:18.699893+00:00 app[web.1]: Dialog1
2018-02-23T09:17:18.462740+00:00 heroku[router]: at=info method=POST path="/api/messages" host=mybot.herokuapp.com request_id=a7af5e93-5c33-46ab-aec0-707a6e45d16f fwd="13.94.243.156" dyno=web.1 connect=0ms service=4ms status=202 bytes=117 protocol=https
2018-02-23T09:17:18.507719+00:00 heroku[router]: at=info method=POST path="/api/messages" host=mybot.herokuapp.com request_id=e26f9bbc-7484-46e4-b0e7-b0173fac069d fwd="13.94.243.156" dyno=web.1 connect=0ms service=5ms status=202 bytes=117 protocol=https
2018-02-23T09:17:18.950503+00:00 app[web.1]: The Bot State API is deprecated. Please refer to https://aka.ms/I6swrh for details on how to replace with your own storage.
Hi there!
Any news on this one? I get the same error in the web client, but it works well in the emulator.
Apparently, the web client doesn't understand that the dialog belongs to the current user.
Running on the emulator, I get a msg ""Hi there, Username" and running on the webclient, i get "Hi there undefined" which means that session.message.user.name is not defined in this dialog when initiated within the bot.on('conversationUpdate') callback.
Im using the latest version and still get this issue.
Conversation Update is sent by the direct line connector once when the bot joins the conversation, and once when the user joins the conversation. In the emulator, these are both sent immediately (not the same behavior of the direct line connector). Using WebChat or directline, the bot's ConversationUpdate is sent when the conversation is created and the user's ConversationUpdate is sent when they first send a message. When ConversationUpdate is sent, there isn't enough information in the message to construct the dialog stack... this means that prompts do not work correctly as a response to ConversationUpdate. There is a workaround you can use described here: https://github.com/Microsoft/BotBuilder/issues/4245#issuecomment-369311452
@EricDahlvang Thanks for the prompt reply. To me it looked like a bug but now it makes more sense. I will implement in the way you suggested. Thanks again.
@victorliafook I added a bug on Emulator side to make sure the behavior match the same as on Direct Line service.
I am closing this for now and tracking it over there. Thanks!
Most helpful comment
Conversation Update is sent by the direct line connector once when the bot joins the conversation, and once when the user joins the conversation. In the emulator, these are both sent immediately (not the same behavior of the direct line connector). Using WebChat or directline, the bot's ConversationUpdate is sent when the conversation is created and the user's ConversationUpdate is sent when they first send a message. When ConversationUpdate is sent, there isn't enough information in the message to construct the dialog stack... this means that prompts do not work correctly as a response to ConversationUpdate. There is a workaround you can use described here: https://github.com/Microsoft/BotBuilder/issues/4245#issuecomment-369311452