forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectLineBotDialog.cs
58 lines (48 loc) · 1.92 KB
/
DirectLineBotDialog.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
namespace DirectLineBot
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
[Serializable]
public class DirectLineBotDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(this.MessageReceivedAsync);
}
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var message = await result;
var reply = context.MakeMessage();
reply.Attachments = new List<Attachment>();
switch (message.Text.ToLower())
{
case "show me a hero card":
reply.Text = $"Sample message with a HeroCard attachment";
var heroCardAttachment = new HeroCard
{
Title = "Sample Hero Card",
Text = "Displayed in the DirectLine client"
}.ToAttachment();
reply.Attachments.Add(heroCardAttachment);
break;
case "send me a botframework image":
reply.Text = $"Sample message with an Image attachment";
var imageAttachment = new Attachment()
{
ContentType = "image/png",
ContentUrl = "https://docs.microsoft.com/en-us/bot-framework/media/how-it-works/architecture-resize.png",
};
reply.Attachments.Add(imageAttachment);
break;
default:
reply.Text = $"You said '{message.Text}'";
break;
}
await context.PostAsync(reply);
context.Wait(this.MessageReceivedAsync);
}
}
}