Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

AgentListener.cs 1.9 KB

You have to be logged in to leave a comment. Sign In
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
  1. namespace EmergencyServicesBot
  2. {
  3. using System;
  4. using System.Diagnostics;
  5. using System.Threading.Tasks;
  6. using Microsoft.Bot.Connector;
  7. public class AgentListener
  8. {
  9. // This will send an adhoc message to the user
  10. public static async Task Resume(
  11. string toId,
  12. string toName,
  13. string fromId,
  14. string fromName,
  15. string conversationId,
  16. string message,
  17. string serviceUrl = "https://smba.trafficmanager.net/apis/",
  18. string channelId = "skype")
  19. {
  20. if (!MicrosoftAppCredentials.IsTrustedServiceUrl(serviceUrl))
  21. {
  22. MicrosoftAppCredentials.TrustServiceUrl(serviceUrl);
  23. }
  24. try
  25. {
  26. var userAccount = new ChannelAccount(toId, toName);
  27. var botAccount = new ChannelAccount(fromId, fromName);
  28. var connector = new ConnectorClient(new Uri(serviceUrl));
  29. IMessageActivity activity = Activity.CreateMessageActivity();
  30. if (!string.IsNullOrEmpty(conversationId) && !string.IsNullOrEmpty(channelId))
  31. {
  32. activity.ChannelId = channelId;
  33. }
  34. else
  35. {
  36. conversationId = (await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount)).Id;
  37. }
  38. activity.From = botAccount;
  39. activity.Recipient = userAccount;
  40. activity.Conversation = new ConversationAccount(id: conversationId);
  41. activity.Text = message;
  42. activity.Locale = "en-Us";
  43. await connector.Conversations.SendToConversationAsync((Activity)activity);
  44. }
  45. catch (Exception exp)
  46. {
  47. Debug.WriteLine(exp);
  48. }
  49. }
  50. }
  51. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...