Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

ActivityLogger.cs 1.2 KB

You have to be logged in to leave a comment. Sign In
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
  1. namespace TestBot
  2. {
  3. using System.Threading.Tasks;
  4. using System.Web.Configuration;
  5. using Microsoft.Bot.Builder.Dialogs.Internals;
  6. using Microsoft.Bot.Builder.History;
  7. using Microsoft.Bot.Connector;
  8. using Newtonsoft.Json;
  9. public sealed class ActivityLogger : IActivityLogger
  10. {
  11. private readonly IBotData botData;
  12. public ActivityLogger(IBotData botData)
  13. {
  14. this.botData = botData;
  15. }
  16. public async Task LogAsync(IActivity activity)
  17. {
  18. var message = activity.AsMessageActivity();
  19. if (message != null && message.From.Name.Equals(WebConfigurationManager.AppSettings["BotId"]) && message.Attachments.Count > 0)
  20. {
  21. var jsonAttachments = JsonConvert.SerializeObject(message.Attachments, Formatting.Indented);
  22. // we access and update the received instance cause if get/save from bot state,
  23. // the ETag changes and saving this cached instance later fails (with this we are using the loaded data)
  24. this.botData.PrivateConversationData.SetValue(Constants.LastJsonKey, jsonAttachments);
  25. }
  26. }
  27. }
  28. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...