forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChannelDataDialog.cs
84 lines (76 loc) · 2.92 KB
/
ChannelDataDialog.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
namespace ChannelDataBot
{
using System;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using Models;
[Serializable]
public class ChannelDataDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(this.MessageReceivedAsync);
}
public async virtual Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var message = await result;
await context.PostAsync("Looking into your upcoming flights to see if you can check-in on any of those...");
var flightAttachment = GetFlightAttachment();
var reply = context.MakeMessage();
if (message.ChannelId != "facebook")
{
reply.Text = flightAttachment.ToString();
}
else
{
reply.ChannelData = new FacebookChannelData()
{
Attachment = flightAttachment
};
}
await context.PostAsync(reply);
context.Wait(this.MessageReceivedAsync);
}
private static FacebookAttachment GetFlightAttachment()
{
return new FacebookAttachment()
{
Payload = new AirlineCheckIn()
{
IntroMessage = "Check-in is available now",
Locale = "en_US",
PnrNumber = "ABCDEF",
CheckInUrl = "http://www.airline.com/check_in",
FlightInfo = new[]
{
new FlightInfo()
{
FlightNumber = "F001",
DepartureAirport = new Airport()
{
AirportCode = "SFO",
City = "San Francisco",
Terminal = "T4",
Gate = "G8"
},
ArrivalAirport = new Airport()
{
AirportCode = "EZE",
City = "Buenos Aires",
Terminal = "C",
Gate = "A2"
},
FlightSchedule = new FlightSchedule()
{
BoardingTime = DateTime.Now.AddDays(1).ToString("yyyy-MM-ddTH:mm"),
DepartureTime = DateTime.Now.AddDays(1).AddHours(1.5).ToString("yyy-MM-ddTH:mm"),
ArrivalTime = DateTime.Now.AddDays(2).ToString("yyyy-MM-ddTH:mm")
}
}
}
}
};
}
}
}