如何在Azure中检索保存的会话数据(Tablelogger) [英] How to retrieve Saved Conversation Data in Azure (Tablelogger)
问题描述
i was able to saved conversation data using the tablelogger.cs implementation TableLogger.cs
我遵循了本教程来保存对话历史记录. 记录对话历史记录
I followed this tutorial to save the conversation history. Logging Conversation History
我用来保存聊天记录的代码是:
The code i used to save the chat history was:
var tableName = ConfigurationManager.AppSettings["TableName"].ToString();
var account = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
Conversation.UpdateContainer(
builder =>
{
account.CreateCloudTableClient().GetTableReference(tableName).DeleteIfExists();
builder.RegisterModule(new TableLoggerModule(account, tableName));
});
检查Azure表存储浏览器后,我可以确认信息已保存.
After checking the Azure table storage explorer I can confirm that information was saved.
我的问题是现在如何检索对话数据并将其作为字符串返回,以便可以将其发送给代理进行审核?
My question is now how to retrieve the conversation data and return it as a string so that I can send it to an agent for review?
推荐答案
所有对话消息(假设消息而不是数据,因为Bot Framework词汇表中的对话数据是另一回事,它与状态有关)存储在Azure表中,因此,如果要获取这些消息,只需查询表即可.
All your conversation messages (let's say messages and not data as Conversation Data is a different thing in Bot Framework vocabulary, it's about state) are stored in an Azure Table, so if you want to get these messages, you just have to query the table.
例如,您有几个查询表的选项
You have several options to query the table, for example
- .NET的Microsoft Azure存储客户端库: https://www.nuget.org/packages/WindowsAzure.Storage/
从文档中采样以按分区获取所有行:
Sample from the doc to get all rows by partition:
// Retrieve the storage account from the connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
// Create the CloudTable object that represents the "people" table.
CloudTable table = tableClient.GetTableReference("people");
// Construct the query operation for all customer entities where PartitionKey="Smith".
TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Smith"));
// Print the fields for each customer.
foreach (CustomerEntity entity in table.ExecuteQuery(query))
{
Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey,
entity.Email, entity.PhoneNumber);
}
文档以进行更个性化的请求以满足您的需求: https://docs.microsoft.com/zh-CN/azure/cosmos-db/table-storage-how-to-use-dotnet
Documentation to do a more customized request that will fit your needs: https://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-dotnet
在您的捕获中,您可以看到表的PartitionKey
由您的channel
的串联组成,并且看起来像一个对话ID.它由TableLogger
此处:
In your capture you can see that the PartitionKey
of the table is made of a concatenation of your channel
and something that looks like a conversation Id. It is confirmed by the sources of TableLogger
here:
/// <summary>
/// Construct from an IActivity.
/// </summary>
/// <param name="activity"></param>
public ActivityEntity(IActivity activity)
{
PartitionKey = GeneratePartitionKey(activity.ChannelId, activity.Conversation.Id);
RowKey = GenerateRowKey(activity.Timestamp.Value);
From = activity.From.Id;
Recipient = activity.Recipient.Id;
Activity = activity;
Version = 3.0;
}
因此,您可能会对获取给定partitionKey的所有行感兴趣.
So you will probably be interested in getting all the lines for a given partitionKey.
对于其他字段:RowKey
是一个时间戳,而Activity
映射到您的机器人Activity
对象,因此它是一个包含多个信息的对象.您必须做一些JsonConvert.DeserializeObject<Activity>
来获得有趣的信息.
For the other fields: the RowKey
is a Timestamp, and Activity
is mapped to your bot Activity
object so it's an object which contains several informations. You will have to do some JsonConvert.DeserializeObject<Activity>
to get the interesting information.
这篇关于如何在Azure中检索保存的会话数据(Tablelogger)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!