4

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));
            });

After checking the Azure table storage explorer I can confirm that information was saved.

enter image description here

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?

anonymous1110
  • 885
  • 4
  • 14
  • 28
  • Duplicate of unanswered question from same user: https://stackoverflow.com/questions/48313703/how-to-get-chat-history-from-azure-table-storage but this question is more detailed – Nicolas R Jan 22 '18 at 12:23

1 Answers1

4

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.

Getting the table items

You have several options to query the table, for example

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);
}

Documentation to do a more customized request that will fit your needs: https://learn.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-dotnet

Data organization

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;
}

So you will probably be interested in getting all the lines for a given partitionKey.

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Nicolas R
  • 13,812
  • 2
  • 28
  • 57
  • sorry, but where can i get the TableQuery ? should i create an internal class? can i simply call the azure table instead? – anonymous1110 Jan 22 '18 at 09:44
  • It's a sample for the doc as I said. Yes you have to customize to get it working for you, sorry I don't have a running sample exactly matching your need nor the time to do it right now. I added a link to the doc that will guide you to the right method creation that will fit your needs – Nicolas R Jan 22 '18 at 09:49
  • And you can use `ActivityEntity` from TableLogger – Nicolas R Jan 22 '18 at 11:42
  • Thank you man, you're a savior! thanks for helping me out always! God bless! – anonymous1110 Jan 23 '18 at 00:25
  • hey man encountered a 409 storageexception error. https://stackoverflow.com/questions/48395464/tablelogger-cs-throwing-storageexception-409-conflict – anonymous1110 Jan 23 '18 at 06:26
  • @NicolasR in the sample there is a query operation for all customer entities with partitionkey 'Smith'. Do you know how to get all entities (so it does not matter what the value of partitionkey is)? – axbeit Aug 05 '19 at 14:20