forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActivityLogger.cs
32 lines (28 loc) · 1.17 KB
/
ActivityLogger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
namespace TestBot
{
using System.Threading.Tasks;
using System.Web.Configuration;
using Microsoft.Bot.Builder.Dialogs.Internals;
using Microsoft.Bot.Builder.History;
using Microsoft.Bot.Connector;
using Newtonsoft.Json;
public sealed class ActivityLogger : IActivityLogger
{
private readonly IBotData botData;
public ActivityLogger(IBotData botData)
{
this.botData = botData;
}
public async Task LogAsync(IActivity activity)
{
var message = activity.AsMessageActivity();
if (message != null && message.From.Name.Equals(WebConfigurationManager.AppSettings["BotId"]) && message.Attachments.Count > 0)
{
var jsonAttachments = JsonConvert.SerializeObject(message.Attachments, Formatting.Indented);
// we access and update the received instance cause if get/save from bot state,
// the ETag changes and saving this cached instance later fails (with this we are using the loaded data)
this.botData.PrivateConversationData.SetValue(Constants.LastJsonKey, jsonAttachments);
}
}
}
}