简体   繁体   English

在基于 botframework v4 node.js 的机器人中查看 Azure blob 存储中保存的聊天记录

[英]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我正在保存基于 core-bot 示例并用 node.js 编写的机器人的成绩单

I used this solution to do it : https://stackoverflow.com/a/55011499/12456146我用这个解决方案来做到这一点: 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.我试图弄清楚如何从 blob 中提取聊天记录并以一种很好的格式呈现或查看保存的聊天记录,但到目前为止我一直无法做到。

I haven't found any references at all for this, so please help me out if you can.我还没有找到任何参考资料,所以如果可以的话,请帮助我。

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> .如果您使用AzureBlobTranscriptStoreTranscriptLoggerMiddleware来记录您的机器人聊天历史记录,日志将存储在您的 blob 存储中的文件夹中: <channel name>/<conversation ID|channel> And each activity will be logged as a .json file.每个活动都将记录为 .json 文件。

For instance, I use bot emulator to test it, all logs are stored as below :例如,我使用机器人模拟器对其进行测试,所有日志存储如下: 在此处输入图片说明

You can use Azure nodejs storage SDK or Azure Az Powershell to read them.您可以使用Azure nodejs 存储 SDKAzure Az Powershell来读取它们。

In this case I use Azure powershell to get chat logs , try the powershell below :在这种情况下,我使用 Azure powershell 来获取聊天记录,请尝试下面的 powershell:

$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 :您可以在此处在模拟器中找到对话 ID: 在此处输入图片说明

Result :结果 :

在此处输入图片说明

Hope it helps.希望能帮助到你。

Update :更新 :

Try the code below to get chatlogs content by storage nodejs SDK :尝试以下代码以通过存储 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 :结果 :

在此处输入图片说明

More samples about nodejs storage SDK see here .有关 nodejs 存储 SDK 的更多示例, 请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM