Bot Transcript in Azure Bot Composer

Viewed 222

I want to retrieve bot transcript, for bots built using composer , for conversation made till that particular point for a user and send it to an API for downstream processing.

Is there a way to retrieve the transcript

1 Answers

You can enable the bot SDK transcript logger. You'll need to configure the transcript store. Example to use the MemoryTranscriptStore (which is not recommended for production).

public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
    services.AddSingleton<ITranscriptLogger, MemoryTranscriptStore>();
    services.AddSingleton<IMiddleware, TranscriptLoggerMiddleware>();
}

You can also configure Azure blob storage via BlobsTranscriptStore as mentioned here.

To read the transcript, on the OnTurnAsync , inject the ITranscriptLogger transcriptLogger, and then you can use it:

var transcriptStore = transcriptLogger as ITranscriptStore;
var transcript = await transcriptStore?.GetTranscriptActivitiesAsync(turnContext.Activity.ChannelId, turnContext.Activity.Conversation.Id);
if (transcript?.Items != null)
{
    foreach (var iactivity in transcript.Items)
    {
        var activity = iactivity as Activity;
        if (activity != null && activity.Type == "message")
        {
            var message2 = MakeMessage(
                conversationId,
                $"{activity.From.Name}: {activity.Text}");
        }
    }
}
Related