Search code examples
javascriptbotframeworkbotconnectordirect-line-botframework

Bot Connector - Direct Line API cross conversation?


I wrote a quick little JavaScript chat to work with the direct line API. To keep my App Secret secure the js makes an ajax call to my server where I make a server side API call with the secret to generate the token and pass that back to the js. When a user submits a message, the js make a post to start the conversation (if I don't already have a conversationID), then posts the message, the does a get to get the response(s).

Luckily, when I started this, I googled something and skimmed some post about including a value for "from" in the message object when posting or it just starts over every post. But now all works great, no problems.

Then I noticed what seemed odd. If I opened a browser, and started chatting it picked up where the other browser left off.

I quickly realized that it was because I had hard coded a "from" value in the js. But that still seems odd... 2 different tokens, 2 different conversationIDs, 2 different browsers and 1 conversation. Are conversations really linked by the from field in messages?

If so, what is the point of having a conversationID? Are they somehow using IP and/or MAC address in combination with the from property?

I am still working on local host so I haven't tested it coming from 2 different IPs.

I know it is easily fixed by having the js generate a random value for "from" to limit the conversation to the lifetime of the js, but that still seems odd. Is there a good reason for it or is it a bug?

UPDATE See the github question for answers: https://github.com/Microsoft/BotBuilder/issues/1307#issuecomment-249187807


Solution

  • You should generate a random ID when your client loads. (Or, you can use an existing user ID within your application, like a device ID.) The auto-assign behavior has been a source of confusion and will not exist in the next version of Direct Line. (See GitHub Discussion)