【问题标题】:How to retrieve Saved Conversation Data in Azure (Tablelogger)如何在 Azure 中检索保存的对话数据(Tablelogger)
【发布时间】:2018-06-30 15:56:50
【问题描述】:

我能够使用 tablelogger.cs 实现 TableLogger.cs 保存对话数据

我按照本教程保存了对话历史记录。 Logging Conversation History

我用来保存聊天记录的代码是:

 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 表存储资源管理器后,我可以确认信息已保存。

我现在的问题是如何检索对话数据并将其作为字符串返回,以便我可以将其发送给代理进行审查?

【问题讨论】:

标签: c# botframework azure-table-storage


【解决方案1】:

您的所有对话消息(假设是消息而不是数据,因为对话数据在 Bot Framework 词汇表中是不同的东西,它与状态有关)都存储在 Azure 表中,因此如果您想获取这些消息,您只需要查询表。

获取表格项

你有几个选项来查询表,例如

从文档中获取按分区获取所有行的示例:

// 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/en-us/azure/cosmos-db/table-storage-how-to-use-dotnet

数据组织

在您的捕获中,您可以看到表格的PartitionKey 由您的channel 和看起来像对话ID 的东西组成。经TableLoggerhere的消息来源证实:

/// <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 的所有行感兴趣。

对于其他字段:RowKey 是时间戳,Activity 映射到您的机器人 Activity 对象,因此它是一个包含多个信息的对象。你将不得不做一些JsonConvert.DeserializeObject&lt;Activity&gt; 来获取有趣的信息。

【讨论】:

  • 抱歉,我在哪里可以获得 TableQuery ?我应该创建一个内部类吗?我可以简单地调用 azure 表吗?
  • 正如我所说,这是文档的示例。是的,您必须对其进行自定义才能使其为您工作,抱歉,我没有完全符合您需求的运行示例,也没有时间立即执行此操作。我添加了指向文档的链接,该链接将指导您创建适合您需求的正确方法
  • 你可以使用 TableLogger 中的ActivityEntity
  • 谢谢你,你是救世主!谢谢你一直帮助我!上帝保佑!
  • 嘿伙计遇到了 409 存储异常错误。 stackoverflow.com/questions/48395464/…
猜你喜欢
  • 2018-09-27
  • 1970-01-01
  • 1970-01-01
  • 2015-07-30
  • 2012-10-24
  • 1970-01-01
  • 2014-11-05
  • 2017-04-04
  • 1970-01-01
相关资源
最近更新 更多