forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RichCardScorable.cs
53 lines (41 loc) · 2.1 KB
/
RichCardScorable.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
namespace TestBot.Scorables
{
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs.Internals;
using Microsoft.Bot.Connector;
public abstract class RichCardScorable : ExtractCodeScorable
{
private const string CSharpSamplesRoot = "https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/";
private const string NodeJsSamplesRoot = "https://github.com/Microsoft/BotBuilder-Samples/tree/master/Node/";
private const string RichCardsSample = "cards-RichCards";
private const string CarouselSample = "cards-CarouselCards";
private const string RichCardsText = "Rich Cards";
private const string CarouselText = "Carousel";
public RichCardScorable(IBotToUser botToUser, IBotData botData) : base(botToUser, botData)
{
}
protected abstract IList<Attachment> GetCardAttachments();
protected override async Task PostAsync(IActivity item, bool state, CancellationToken token)
{
await base.PostAsync(item, state, token);
var message = this.BotToUser.MakeMessage();
message.Attachments = this.GetCardAttachments();
var sample = RichCardsSample;
var text = RichCardsText;
// should display carousel?
if (message.Attachments.Count() > 1)
{
message.AttachmentLayout = AttachmentLayoutTypes.Carousel;
sample = CarouselSample;
text = CarouselText;
}
await this.BotToUser.PostAsync(message);
var moreMessage = this.BotToUser.MakeMessage();
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.";
await this.BotToUser.PostAsync(moreMessage);
}
}
}