forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchHitStyler.cs
37 lines (35 loc) · 1.28 KB
/
SearchHitStyler.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
namespace Search.Dialogs
{
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using Search.Models;
[Serializable]
public class SearchHitStyler : PromptStyler
{
public override void Apply<T>(ref IMessageActivity message, string prompt, IReadOnlyList<T> options, IReadOnlyList<string> descriptions = null, string speak = null)
{
var hits = options as IList<SearchHit>;
if (hits != null)
{
var cards = hits.Select(h => new ThumbnailCard
{
Title = h.Title,
Images = new[] { new CardImage(h.PictureUrl) },
Buttons = new[] { new CardAction(ActionTypes.ImBack, "Pick this one", value: h.Key) },
Text = h.Description
});
message.AttachmentLayout = AttachmentLayoutTypes.Carousel;
message.Attachments = cards.Select(c => c.ToAttachment()).ToList();
message.Text = prompt;
message.Speak = speak;
}
else
{
base.Apply<T>(ref message, prompt, options, descriptions, speak);
}
}
}
}