-
Notifications
You must be signed in to change notification settings - Fork 0
/
AgentListener.cs
56 lines (51 loc) · 1.89 KB
/
AgentListener.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
namespace EmergencyServicesBot
{
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Bot.Connector;
public class AgentListener
{
// This will send an adhoc message to the user
public static async Task Resume(
string toId,
string toName,
string fromId,
string fromName,
string conversationId,
string message,
string serviceUrl = "https://smba.trafficmanager.net/apis/",
string channelId = "skype")
{
if (!MicrosoftAppCredentials.IsTrustedServiceUrl(serviceUrl))
{
MicrosoftAppCredentials.TrustServiceUrl(serviceUrl);
}
try
{
var userAccount = new ChannelAccount(toId, toName);
var botAccount = new ChannelAccount(fromId, fromName);
var connector = new ConnectorClient(new Uri(serviceUrl));
IMessageActivity activity = Activity.CreateMessageActivity();
if (!string.IsNullOrEmpty(conversationId) && !string.IsNullOrEmpty(channelId))
{
activity.ChannelId = channelId;
}
else
{
conversationId = (await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount)).Id;
}
activity.From = botAccount;
activity.Recipient = userAccount;
activity.Conversation = new ConversationAccount(id: conversationId);
activity.Text = message;
activity.Locale = "en-Us";
await connector.Conversations.SendToConversationAsync((Activity)activity);
}
catch (Exception exp)
{
Debug.WriteLine(exp);
}
}
}
}