forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CardsDialog.cs
231 lines (205 loc) · 9.69 KB
/
CardsDialog.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
namespace CardsBot
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
[Serializable]
public class CardsDialog : IDialog<object>
{
private const string HeroCard = "Hero card";
private const string ThumbnailCard = "Thumbnail card";
private const string ReceiptCard = "Receipt card";
private const string SigninCard = "Sign-in card";
private const string AnimationCard = "Animation card";
private const string VideoCard = "Video card";
private const string AudioCard = "Audio card";
private IEnumerable<string> options = new List<string> { HeroCard, ThumbnailCard, ReceiptCard, SigninCard, AnimationCard, VideoCard, AudioCard };
public async Task StartAsync(IDialogContext context)
{
context.Wait(this.MessageReceivedAsync);
}
public async virtual Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var message = await result;
PromptDialog.Choice<string>(
context,
this.DisplaySelectedCard,
this.options,
"What card would like to test?",
"Ooops, what you wrote is not a valid option, please try again",
3,
PromptStyle.PerLine);
}
public async Task DisplaySelectedCard(IDialogContext context, IAwaitable<string> result)
{
var selectedCard = await result;
var message = context.MakeMessage();
var attachment = GetSelectedCard(selectedCard);
message.Attachments.Add(attachment);
await context.PostAsync(message);
context.Wait(this.MessageReceivedAsync);
}
private static Attachment GetSelectedCard(string selectedCard)
{
switch (selectedCard)
{
case HeroCard:
return GetHeroCard();
case ThumbnailCard:
return GetThumbnailCard();
case ReceiptCard:
return GetReceiptCard();
case SigninCard:
return GetSigninCard();
case AnimationCard:
return GetAnimationCard();
case VideoCard:
return GetVideoCard();
case AudioCard:
return GetAudioCard();
default:
return GetHeroCard();
}
}
private static Attachment GetHeroCard()
{
var heroCard = new HeroCard
{
Title = "BotFramework Hero Card",
Subtitle = "Your bots — wherever your users are talking",
Text = "Build and connect intelligent bots to interact with your users naturally wherever they are, from text/sms to Skype, Slack, Office 365 mail and other popular services.",
Images = new List<CardImage> { new CardImage("https://sec.ch9.ms/ch9/7ff5/e07cfef0-aa3b-40bb-9baa-7c9ef8ff7ff5/buildreactionbotframework_960.jpg") },
Buttons = new List<CardAction> { new CardAction(ActionTypes.OpenUrl, "Get Started", value: "https://docs.microsoft.com/bot-framework") }
};
return heroCard.ToAttachment();
}
private static Attachment GetThumbnailCard()
{
var heroCard = new ThumbnailCard
{
Title = "BotFramework Thumbnail Card",
Subtitle = "Your bots — wherever your users are talking",
Text = "Build and connect intelligent bots to interact with your users naturally wherever they are, from text/sms to Skype, Slack, Office 365 mail and other popular services.",
Images = new List<CardImage> { new CardImage("https://sec.ch9.ms/ch9/7ff5/e07cfef0-aa3b-40bb-9baa-7c9ef8ff7ff5/buildreactionbotframework_960.jpg") },
Buttons = new List<CardAction> { new CardAction(ActionTypes.OpenUrl, "Get Started", value: "https://docs.microsoft.com/bot-framework") }
};
return heroCard.ToAttachment();
}
private static Attachment GetReceiptCard()
{
var receiptCard = new ReceiptCard
{
Title = "John Doe",
Facts = new List<Fact> { new Fact("Order Number", "1234"), new Fact("Payment Method", "VISA 5555-****") },
Items = new List<ReceiptItem>
{
new ReceiptItem("Data Transfer", price: "$ 38.45", quantity: "368", image: new CardImage(url: "https://github.com/amido/azure-vector-icons/raw/master/renders/traffic-manager.png")),
new ReceiptItem("App Service", price: "$ 45.00", quantity: "720", image: new CardImage(url: "https://github.com/amido/azure-vector-icons/raw/master/renders/cloud-service.png")),
},
Tax = "$ 7.50",
Total = "$ 90.95",
Buttons = new List<CardAction>
{
new CardAction(
ActionTypes.OpenUrl,
"More information",
"https://account.windowsazure.com/content/6.10.1.38-.8225.160809-1618/aux-pre/images/offer-icon-freetrial.png",
"https://azure.microsoft.com/en-us/pricing/")
}
};
return receiptCard.ToAttachment();
}
private static Attachment GetSigninCard()
{
var signinCard = new SigninCard
{
Text = "BotFramework Sign-in Card",
Buttons = new List<CardAction> { new CardAction(ActionTypes.Signin, "Sign-in", value: "https://login.microsoftonline.com/") }
};
return signinCard.ToAttachment();
}
private static Attachment GetAnimationCard()
{
var animationCard = new AnimationCard
{
Title = "Microsoft Bot Framework",
Subtitle = "Animation Card",
Image = new ThumbnailUrl
{
Url = "https://docs.microsoft.com/en-us/bot-framework/media/how-it-works/architecture-resize.png"
},
Media = new List<MediaUrl>
{
new MediaUrl()
{
Url = "http://i.giphy.com/Ki55RUbOV5njy.gif"
}
}
};
return animationCard.ToAttachment();
}
private static Attachment GetVideoCard()
{
var videoCard = new VideoCard
{
Title = "Big Buck Bunny",
Subtitle = "by the Blender Institute",
Text = "Big Buck Bunny (code-named Peach) is a short computer-animated comedy film by the Blender Institute, part of the Blender Foundation. Like the foundation's previous film Elephants Dream, the film was made using Blender, a free software application for animation made by the same foundation. It was released as an open-source film under Creative Commons License Attribution 3.0.",
Image = new ThumbnailUrl
{
Url = "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Big_buck_bunny_poster_big.jpg/220px-Big_buck_bunny_poster_big.jpg"
},
Media = new List<MediaUrl>
{
new MediaUrl()
{
Url = "http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4"
}
},
Buttons = new List<CardAction>
{
new CardAction()
{
Title = "Learn More",
Type = ActionTypes.OpenUrl,
Value = "https://peach.blender.org/"
}
}
};
return videoCard.ToAttachment();
}
private static Attachment GetAudioCard()
{
var audioCard = new AudioCard
{
Title = "I am your father",
Subtitle = "Star Wars: Episode V - The Empire Strikes Back",
Text = "The Empire Strikes Back (also known as Star Wars: Episode V – The Empire Strikes Back) is a 1980 American epic space opera film directed by Irvin Kershner. Leigh Brackett and Lawrence Kasdan wrote the screenplay, with George Lucas writing the film's story and serving as executive producer. The second installment in the original Star Wars trilogy, it was produced by Gary Kurtz for Lucasfilm Ltd. and stars Mark Hamill, Harrison Ford, Carrie Fisher, Billy Dee Williams, Anthony Daniels, David Prowse, Kenny Baker, Peter Mayhew and Frank Oz.",
Image = new ThumbnailUrl
{
Url = "https://upload.wikimedia.org/wikipedia/en/3/3c/SW_-_Empire_Strikes_Back.jpg"
},
Media = new List<MediaUrl>
{
new MediaUrl()
{
Url = "http://www.wavlist.com/movies/004/father.wav"
}
},
Buttons = new List<CardAction>
{
new CardAction()
{
Title = "Read More",
Type = ActionTypes.OpenUrl,
Value = "https://en.wikipedia.org/wiki/The_Empire_Strikes_Back"
}
}
};
return audioCard.ToAttachment();
}
}
}