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

RichCardScorable.cs 2.1 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  1. namespace TestBot.Scorables
  2. {
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using Microsoft.Bot.Builder.Dialogs.Internals;
  8. using Microsoft.Bot.Connector;
  9. public abstract class RichCardScorable : ExtractCodeScorable
  10. {
  11. private const string CSharpSamplesRoot = "https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/";
  12. private const string NodeJsSamplesRoot = "https://github.com/Microsoft/BotBuilder-Samples/tree/master/Node/";
  13. private const string RichCardsSample = "cards-RichCards";
  14. private const string CarouselSample = "cards-CarouselCards";
  15. private const string RichCardsText = "Rich Cards";
  16. private const string CarouselText = "Carousel";
  17. public RichCardScorable(IBotToUser botToUser, IBotData botData) : base(botToUser, botData)
  18. {
  19. }
  20. protected abstract IList<Attachment> GetCardAttachments();
  21. protected override async Task PostAsync(IActivity item, bool state, CancellationToken token)
  22. {
  23. await base.PostAsync(item, state, token);
  24. var message = this.BotToUser.MakeMessage();
  25. message.Attachments = this.GetCardAttachments();
  26. var sample = RichCardsSample;
  27. var text = RichCardsText;
  28. // should display carousel?
  29. if (message.Attachments.Count() > 1)
  30. {
  31. message.AttachmentLayout = AttachmentLayoutTypes.Carousel;
  32. sample = CarouselSample;
  33. text = CarouselText;
  34. }
  35. await this.BotToUser.PostAsync(message);
  36. var moreMessage = this.BotToUser.MakeMessage();
  37. moreMessage.Text = $"To know more about {text} check these [C#]({CSharpSamplesRoot + sample}) & [NodeJs]({NodeJsSamplesRoot + sample}) samples. Type **{Constants.JsonTrigger}** to view attachment details; or type **{Constants.CSharpTrigger}** or **{Constants.NodeJsTrigger}** for the source code that generated this card.";
  38. await this.BotToUser.PostAsync(moreMessage);
  39. }
  40. }
  41. }
Tip!

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

Comments

Loading...