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

CustomWebAPIController.cs 1.7 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
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Net.Http;
  6. using System.Threading.Tasks;
  7. using System.Web;
  8. using System.Web.Http;
  9. namespace simpleSendMessage.Controllers
  10. {
  11. //This controller exists just to prove that we can trigger that proactive conversation even from compeltely outside the bot's code
  12. //Let's say you have a web service or some backend system that needs to trigger it, this is how you would do that
  13. public class CustomWebAPIController : ApiController
  14. {
  15. [HttpGet]
  16. [Route("api/CustomWebAPI")]
  17. public async Task<HttpResponseMessage> SendMessage()
  18. {
  19. try
  20. {
  21. if (!string.IsNullOrEmpty(ConversationStarter.fromId))
  22. {
  23. await ConversationStarter.Resume(ConversationStarter.conversationId, ConversationStarter.channelId); //We don't need to wait for this, just want to start the interruption here
  24. var resp = new HttpResponseMessage(HttpStatusCode.OK);
  25. resp.Content = new StringContent($"<html><body>Message sent, thanks.</body></html>", System.Text.Encoding.UTF8, @"text/html");
  26. return resp;
  27. }
  28. else
  29. {
  30. var resp = new HttpResponseMessage(HttpStatusCode.OK);
  31. resp.Content = new StringContent($"<html><body>You need to talk to the bot first so it can capture your details.</body></html>", System.Text.Encoding.UTF8, @"text/html");
  32. return resp;
  33. }
  34. }
  35. catch (Exception ex)
  36. {
  37. return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
  38. }
  39. }
  40. }
  41. }
Tip!

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

Comments

Loading...