BotBuilder-Samples icon indicating copy to clipboard operation
BotBuilder-Samples copied to clipboard

Conversation history does not work

Open raghukrishnamoorthy opened this issue 7 years ago • 6 comments

Sample information

  1. Sample type: \samples\
  2. Sample language: dotnetcore
  3. Sample name: https://github.com/Microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/22.conversation-history

Describe the bug

The sendConversationHistory method in the sample does not render the conversation history.

To Reproduce

Steps to reproduce the behavior:

  1. Download the sample
  2. Configure azure storage as instructed
  3. Run the application
  4. Conversation history is not rendered

Expected behavior

Conversation history should be rendered after all the activities are fetched from Azure storage

Additional context

After trying out the sample,

  1. The conversation activities are stored in blob storage.
  2. The sample code also retrieves all activities and I can see them stored in the activities variable.
  3. However, the sendconversationHistory method does not seem to do anything at this point. No history is rendered. I had to manually loop through the activities and send each activity to the webchat control.

[bug]

raghukrishnamoorthy avatar Feb 11 '19 04:02 raghukrishnamoorthy

Hi @raghukrishnamoorthy

Thank you for reporting this. This is a shortcoming in the Sample. I've submitted a PR to fix the issue for WebChat, Emulator and the Direct Line.

This is actually a client side rendering issue since these items are filtered out of the WebChat store due to the ids already being present. Nonetheless, fixing the issue bot side seems like a valid option.

    foreach (var a in activities)
    {
        incrementId++;
        a.Id = string.Concat(activity.Conversation.Id, "|", incrementId.ToString().PadLeft(7, '0'));
        a.Timestamp = DateTimeOffset.UtcNow;
        a.ChannelData = string.Empty; // WebChat uses ChannelData for id comparisons, so we clear it here
    }

EricDahlvang avatar Feb 12 '19 01:02 EricDahlvang

@ericdahlvang Do you mean to say we don't have to handle the conversation Id like you've done once the PR gets merged?

raghukrishnamoorthy avatar Feb 12 '19 08:02 raghukrishnamoorthy

The PR is to update the sample so it correctly modifies these properties: https://github.com/Microsoft/BotBuilder-Samples/pull/1222

EricDahlvang avatar Feb 12 '19 16:02 EricDahlvang

This hack will cause a problem. Think of this scenario. When you open the same HTML in a new tab, the history gets rendered there alright. But if you go back to the old tab now, the entire chat window has the original chat followed by history rendered again. This would look like the same conversation repeating once more in the first window. If you open another window, the conversation history gets rendered there followed by the first window having the conversation history showing thrice.

Does this make sense? I tried out the code now and I got this issue as I'm typing this out.

raghukrishnamoorthy avatar Feb 13 '19 10:02 raghukrishnamoorthy

Hi @raghukrishnamoorthy

How are you loading webchat? What sort of behavior do you expect?

I'm not sure this is actually an issue with the sample itself. The comments for SendConversationHistoryAsync are as follows:

This method allows you to upload the historic activities to the conversation. Sender must ensure that the historic activities have unique ids and appropriate timestamps. The ids are used by the client to deal with duplicate activities and the timestamps are used by the client to render the activities in the right order.

The sample was not previously doing this, but is now. Previously, the sample did not show the history sent with the call to SendConversationHistoryAsync in WebChat or the Emulator due to not changing the activity ids, and without changing the TimeStamps, the messages would be shown out of order.

EricDahlvang avatar Feb 13 '19 19:02 EricDahlvang

@raghukrishnamoorthy Thanks again for opening this issue. I'm closing it now, since it is resolved.

For the scenario you mentioned, with multiple windows open to the same conversation, one solution might be:

  • start a new conversation in the new window
  • send a BackChannel event containing the old window's conversationId in ChannelData
  • server side reply to the event, sending the old window's conversation history to the new window's new conversation

EricDahlvang avatar Feb 19 '19 00:02 EricDahlvang