MessageRequest.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
  2. //
  3. // 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
  4. //
  5. // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
  6. using Admin.Net.Plugin.DingTalk.RequestProxy.Message.DTO;
  7. using NewLife;
  8. using static Admin.Net.Plugin.DingTalk.RequestProxy.Message.DTO.MsgActionCardDomain;
  9. namespace Admin.Net.Plugin.DingTalk.RequestProxy.Message;
  10. public class MessageRequest : IScoped
  11. {
  12. private readonly IMessageRequestProxy _request;
  13. public MessageRequest(IMessageRequestProxy request)
  14. {
  15. _request = request;
  16. }
  17. public async Task<SendCorpConversationResponse> SendCorpMarkdown(string accessToken, long agentId, List<string>? useridList, List<long> deptIdList
  18. , string mdTitle, string mdText, bool toAllUser = false)
  19. {
  20. var resStr = await _request.SendCorpConversation(accessToken, new SendCorpConversationRequest
  21. {
  22. AgentId = agentId,
  23. UserIdList = useridList?.ToArray().Join(),
  24. DeptIdList = deptIdList?.ToArray().Join(),
  25. ToAllUser = toAllUser,
  26. Msg = new MsgDomain
  27. {
  28. MsgType = MsgTypeEnum.markdown,
  29. Markdown = new MsgMarkdownDomain
  30. {
  31. Title = mdTitle,
  32. Text = mdText,
  33. }
  34. }
  35. });
  36. var res = resStr.ToObject<SendCorpConversationResponse>();
  37. return res;
  38. }
  39. public async Task<SendCorpConversationResponse> SendCorpActionCard(string accessToken, long agentId, List<string>? useridList, List<long>? deptIdList
  40. , string markdown, string? title = null, string? singleTitle = null, string? singleUrl = null
  41. , BenOrientationEnum? btnOrientation = null, MsgActionCardBtnJsonListDomain[]? btnJsonList = null
  42. , bool toAllUser = false)
  43. {
  44. var resStr = await _request.SendCorpConversation(accessToken, new SendCorpConversationRequest
  45. {
  46. AgentId = agentId,
  47. UserIdList = useridList?.ToArray().Join(),
  48. DeptIdList = deptIdList?.ToArray().Join(),
  49. ToAllUser = toAllUser,
  50. Msg = new MsgDomain
  51. {
  52. MsgType = MsgTypeEnum.action_card,
  53. ActionCard = new MsgActionCardDomain
  54. {
  55. Markdown = markdown,
  56. Title = title,
  57. SingleTitle = singleTitle,
  58. SingleUrl = singleUrl,
  59. BtnOrientation = btnOrientation,
  60. BtnJsonList = btnJsonList
  61. }
  62. }
  63. });
  64. var res = resStr.ToObject<SendCorpConversationResponse>();
  65. return res;
  66. }
  67. }