Anamitra Das
Anamitra Das

Reputation: 53

Reviewing saved chats in Azure blob storage in bot based on botframework v4 node.js

I am saving transcripts from my bot that is based on the core-bot sample and written in node.js

I used this solution to do it : https://stackoverflow.com/a/55011499/12456146

I'm trying to figure out how I can extract the chats from the blob and present or review the saved chat in a nice format, but I have been unable to so far.

I haven't found any references at all for this, so please help me out if you can.

Upvotes: 1

Views: 463

Answers (1)

Stanley Gong
Stanley Gong

Reputation: 12153

If you use AzureBlobTranscriptStore and TranscriptLoggerMiddleware to log your bot chatting history, logs will be stored in your blob storage under folder: <channel name>/<conversation ID|channel>. And each activity will be logged as a .json file.

For instance, I use bot emulator to test it, all logs are stored as below : enter image description here

You can use Azure nodejs storage SDK or Azure Az Powershell to read them.

In this case I use Azure powershell to get chat logs , try the powershell below :

$storageAccount = "<your storage account name>"
$resourceGroup = "<your resource group name>"
$containerName = "<your container name>"
$storage = Get-AzStorageAccount -name $storageAccount -ResourceGroupName $resourceGroup
$channel="emulator"
$conversationID = "<conversationID>"
$prefix = $channel+"/"+$conversationID 

$chatlogs = Get-AzStorageBlob -Prefix $prefix -Container $containerName -Context $storage.Context 

$tempPath = "d:/temp/"
mkdir $tempPath
foreach($log in $chatlogs){
    $jsonFile = Get-AzStorageBlobContent -Blob $log.Name -Container $containerName -Context $storage.Context -Destination $tempPath -Force
    Get-Content -Raw -Path ($tempPath+$jsonFile.Name) | ConvertFrom-Json | select type,timestamp,from,recipient,text
}

Remove-Item -Recurse -Force $tempPath 

You can find conversation ID in emulator here : enter image description here

Result :

enter image description here

Hope it helps.

Update :

Try the code below to get chatlogs content by storage nodejs SDK :

var azure = require('azure-storage');

var storageAccount = "<storage account name>"
var key = "<storage key>"
var container ="chatlog"
var conversationID = "<conversation ID>"
var channel = "emulator"
var prefix = channel + "/" + conversationID

var blobService = azure.createBlobService(storageAccount,key);

 blobService.listBlobsSegmentedWithPrefix(container,prefix,null,function(err, results, resp){

    results.entries.forEach(element => {

     blobService.getBlobToText(container,element.name,function(err, results, resp){console.log(results);
     });

  });
 });

Result :

enter image description here

More samples about nodejs storage SDK see here .

Upvotes: 2

Related Questions