Search code examples
botframeworkweb-chat

sending a message to bot: v3 directline.postActivity vs. v4 dispatch from webchat store


We are migrating from BotFramework-Webchat v3 to v4. Usually we send a message from the chat through the directline object created from v3 BotChat using the directline.postActivity function. However in our v4 implementation there were issues with the behavior of messages shown in the chat window when posting activities like this.

It seems that sending messages through the webchat redux store as shown in this example is the recommended approach.

I am wondering what is the difference between these two usages? It seems something is different between v3 and v4 versions and I am having difficulty finding references in the documentation about this. Should directline.postActivity be avoided completely?


Solution

  • It isn't documented anywhere, but best practice is what is demonstrated via the samples, by use of the Web Chat redux store and its list of available actions.

    Essentially, Web Chat v4 is built on top of BotFramework-DirectlineJS which does use observables. Web Chat then translates the Direct Line observables into its own methods for consumption internally and by the user.

    As you noted, it is possible to use the Direct Line observables in Web Chat but it is neither the best method nor the best practice to do so. Primarily, because Web Chat wasn't specifically designed around their use, except internally. It can work, but it opens you up to potentially curious behavior.