Search code examples
botframework

Does TranscriptStore only store 20 Activities?


I am creating a bot in Microsoft Bot Framework v4.I want to store the conversation history in a storage. The botsamples (https://github.com/Microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/22.conversation-history) helped me with this. But when I implemented the sample in me code, I only get max. 20 activities to store.

        var activity = turnContext.Activity;
        // Download the activities from the Transcript (blob store) and send them over to the channel when a request to upload history arrives.
        // This could be an event or a special message acctivity as above.
        var connectorClient = turnContext.TurnState.Get<ConnectorClient>(typeof(IConnectorClient).FullName);

        // Get all the message type activities from the Transcript.
        //string continuationToken = null;
        var count = 0;
       // do
        try
        {
            var pagedTranscript = await _transcriptStore.GetTranscriptActivitiesAsync(activity.ChannelId, activity.Conversation.Id);

            var activities = pagedTranscript.Items
                .Where(a => a.Type == ActivityTypes.Message)
                .Select(ia => (Activity)ia)
                .ToList();

            // This count takes only 20 activities max
            var activityCount = activities.Count;

            var user = await _accessors.UserProfile.GetAsync(turnContext);

            var transcriptContents = new StringBuilder();


            foreach (var transcript1 in pagedTranscript.Items.Where(i => i.Type == ActivityTypes.Message))
            {
                transcriptContents.AppendLine("<div><b>(" + transcript1.Timestamp + ") " + transcript1.From.Name + "</b>: " + transcript1.AsMessageActivity().Text + "</div>");
            }

            emailContent = transcriptContents.ToString();

            var transcript = new Transcript(activities);

            await connectorClient.Conversations.SendConversationHistoryAsync(activity.Conversation.Id, transcript, cancellationToken: cancellationToken);

           // continuationToken = pagedTranscript.ContinuationToken;
        }catch(Exception ex)
        // while (continuationToken != null);
        {
            await HandleDialogExceptionsAsync(sc, ex);
        }

By debugging, pagedTranscript gives me only 20 activities. But in the blobstorage there are more json files.

Me question is, is there a maximum activities to store into the TranscriptStore? And is there another way to receive the messages of the bot and user?

thank you


Solution

  • Nicolas R is correct. You need to use the continuation token to get the other pages. Please see here for a sample.