How to deal with overlapping sessions (same user.id, same conversation.id, different address.id)
Bot Info
- SDK Platform: Node.js
- SDK Version: 3.13.1
- Active Channels: Emulator
- Deployment Environment: local development with Emulator
Issue Description
if a user triggers a new bot session by typing two or more messages very close in time on the Emulator, it happens that the newly created session has more than one valid user address associated. As a consequence, all messages from the Bot to the Emulator are delivered more than once.
Code Example
The "Hello World" Bot is ok to this purpose: you will get "Hello World" more than once.
Reproduction Steps
- start the Bot ("node app.js")
- open the Emulator and connect to the Bot on the app's local port
- send two or more messages very quickly to the Bot
Expected Behavior
One would expect Bot messages to be received only once on the emulator, as only one conversation has been actually created.
Actual Results
Messages are delivered more than once. Here is the dump of two user addresses involved in such a situation:
{"id":"g47afbimj58","channelId":"emulator","user":{"id":"default-user","name":"User"},"conversation":{"id":"j73je891i2ci"},"bot":{"id":"eg3age7628mj","name":"Bot"},"serviceUrl":"https://7e988633.ngrok.io"}
{"id":"k8njb01cj72a","channelId":"emulator","user":{"id":"default-user","name":"User"},"conversation":{"id":"j73je891i2ci"},"bot":{"id":"eg3age7628mj","name":"Bot"},"serviceUrl":"https://7e988633.ngrok.io"}
Please notice that they are identical, except for the address id's.
It looks to me like only one conversation was created (conversation id is the same for both of the messages: j73je891i2ci).
Why is there no text property in the two example messages you've shared? There's also no message type.
I think we need more details in order to get to the bottom of this. Please elaborate ... from what you've described so far, you are sending multiple messages to the bot and receiving multiple replies. Message id's are different, but that is expected.
Hi Eric, you're right: only one conversation has been created, yet two different addresses have been bound to it. Sorry for attaching only part of the information, here is the whole messages' dump:
{"type":"message","agent":"botbuilder","source":"emulator","textLocale":"en-GB","address":{"id":"l86ge7fejfce","channelId":"emulator","user":{"id":"default-user","name":"User"},"conversation":{"id":"em7lnc98252m"},"bot":{"id":"eg3age7628mj","name":"Bot"},"serviceUrl":"https://94986e6f.ngrok.io"},"text":"Hello World!"}
{"type":"message","agent":"botbuilder","source":"emulator","textLocale":"en-GB","address":{"id":"cca5hi44nca7","channelId":"emulator","user":{"id":"default-user","name":"User"},"conversation":{"id":"em7lnc98252m"},"bot":{"id":"eg3age7628mj","name":"Bot"},"serviceUrl":"https://94986e6f.ngrok.io"},"text":"Hello World!"}
Information in bold is what actually differs between the two messages: each of corresponding addresses can be used to reach for the same user (and client) independently, thus resulting in a message duplication on the emulator. See attached screenshot.
For the sake of completeness, here is the (trivial) code that leads to this situation:
botmanager.bot.dialog('/', [
function (session, args) {
var msg = new builder.Message(session);
msg.text("Hello World!");
console.log(JSON.stringify(msg.data));
session.send(msg);
}
])
Hope it's clearer now, thank you very much.
Marco

Please click on one of the messages sent from the emulator, and check the properties there:

The .json message.id is mapped to the address.id by the sdk:

Message.id (and address.id) should be different. If conversation.id was different, then there would definitely be a problem.
Ok, under this perspective it makes sense to have two messages in response. Yet, to be sincere, I find a bit weird that message IDs are mapped onto address IDs: according to Bot Framework's documentation, addresses are meant to identify the user, in order to reach him at a further time (i.e. "proactive messages"). Or maybe am I missing something of the underlying logics of the Framework (I didn't go deep enough into this matter yet)? Thank you very much.