/// <summary> /// Intercepts messages between BuddyBot and the user, logging them to the /// <see cref="IChatHistoryWriter"/>. /// </summary> /// <param name="activity">Mandatory. Shared properties for all activities.</param> /// <returns></returns> public async Task LogAsync(IActivity activity) { if (activity.AsMessageActivity() != null) { ChatHistoryEntity chatHistoryEntity = new ChatHistoryEntity($"{activity.ChannelId}:{activity.Type}", Guid.NewGuid().ToString()) { From = activity.From.Id, Recipient = activity.Recipient.Id, Message = activity.AsMessageActivity().Text }; await _chatHistoryWriter.SaveMessage(chatHistoryEntity); } }
public async Task SaveMessage(ChatHistoryEntity chatHistoryEntity) { RepositorySettings repositorySettings = new RepositorySettings(); // Retrieve the storage account from the connection string. CloudStorageAccount storageAccount = CloudStorageAccount.Parse( repositorySettings.ConnectionString); // Create the table client. CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); // Create the CloudTable object that represents the "people" table. CloudTable table = tableClient.GetTableReference(repositorySettings.ChatHistoryTableName); // Create the table if it doesn't exist. await table.CreateIfNotExistsAsync(); // Create the TableOperation object that inserts the chat history entity. TableOperation insertOperation = TableOperation.Insert(chatHistoryEntity); // Execute the insert operation. await table.ExecuteAsync(insertOperation); }