botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Bot c#: How can I store and load all conversations from iframe

Open msBot1111 opened this issue 9 years ago • 5 comments

I've inserted my Bot in xamarin app, and I'm using iframe for that. But when I start conversation with the bot it always starts new conversation. I want to keep the whole history in the chat. My question is where should I store the conversation and how can I load them when user opens the chat?

msBot1111 avatar Apr 07 '17 08:04 msBot1111

hi @msBot1111 - can you provide more detail about your issue? for example:

Environment

  • Operating System:
    • Windows
    • macOS
    • Linux
  • SDK Platform:
    • C#/.NET
    • Node.js
  • SDK version:
  • Development environment:
    • localhost
    • Azure Web App
    • Azure Bot Service App
    • other
  • If you are using the Node.js SDK:
    • Node.js version:
    • NPM version:

Issue

What the issue is, in broad strokes. Link to Stack Overflow post.

Example Code

The code snippet or complete bot example (preferred) that demonstrates the issue.

Steps to Reproduce

Please provide the shortest amount of steps to reproduce your issue.

Expected Behavior

What you expected to happen.

Actual Results

What actually happened. Please give examples and support it with screenshots, copied output or error messages.

nwhitmont avatar Apr 10 '17 16:04 nwhitmont

I'm using Bot Framework c# for my Bot, and development environment is Azure Web App. I have also Xamarin Forms App and I've added my Bot into my app with iframe. When I open the chat with Bot it's working well, my Bot returns the answers. My problem is that I'm not keeping the conversations. Every time I reopen the chat it gives me new conversation. Is it possible to keep history of conversations per user and when I reopen the chat to load all conversations with that user as it is in skype channel. @nwhitmont I was following this link: https://nowayshecodes.com/2016/09/21/xamarin-forms-tip-implementing-a-chatbot-in-your-xamarin-app/

msBot1111 avatar Apr 11 '17 09:04 msBot1111

@msBot1111 This may help you get started on the right path here. I believe these will help you with what you are trying to accomplish: Documentation Source code Saving bot activities blog by @EricDahlvang Please continue the conversation by telling us how they work out for you. I am going to close this issue for now, we can always reopen it if needed

JasonSowers avatar May 24 '17 17:05 JasonSowers

https://blog.botframework.com/2017/05/05/Saving-Bot-Actions-On-Azure-Sql-Server/ I've stored the conversation as it is in the example, but now how can I load the conversation when the chat is opened?

msBot1111 avatar Jun 08 '17 12:06 msBot1111

@msBot1111 I do not have an exact code example but, in your messageController, in the HandleSystemMessage() method you could load it all up and display it instead of a welcome message like below

            else if (message.Type == ActivityTypes.ConversationUpdate)
            {
                // Handle conversation state changes, like members being added and removed
                // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
                // Not available in all channels
                IConversationUpdateActivity iConversationUpdated = message as IConversationUpdateActivity;
                if (iConversationUpdated != null)
                {
                    ConnectorClient connector = new ConnectorClient(new System.Uri(message.ServiceUrl));

                    foreach (var member in iConversationUpdated.MembersAdded ?? System.Array.Empty<ChannelAccount>())
                    {
                        // if the bot is added, then
                        if (member.Id == iConversationUpdated.Recipient.Id)
                        {
                            var reply = ((Activity) iConversationUpdated).CreateReply(
                                $"Welcome Message");
                            await connector.Conversations.ReplyToActivityAsync(reply);
                        }
                    }
                }
            }

JasonSowers avatar Jun 08 '17 16:06 JasonSowers