DtmfNotificationHandler.cs 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using Hotline.Caching.Interfaces;
  2. using Hotline.CallCenter.Calls;
  3. using Hotline.CallCenter.Configs;
  4. using Hotline.CallCenter.Ivrs;
  5. using Hotline.Realtimes;
  6. using Hotline.Share.Enums.CallCenter;
  7. using Hotline.Share.Notifications.NewRockCallCenter;
  8. using MediatR;
  9. using Microsoft.Extensions.Options;
  10. using NewRock.Sdk;
  11. namespace Hotline.Application.Handlers.CallCenter.CallState
  12. {
  13. public class DtmfNotificationHandler : NewRockBaseHandler, INotificationHandler<DtmfNotification>
  14. {
  15. private readonly IIvrDomainService _ivrDomainService;
  16. private readonly ICallRepository _callRepository;
  17. private readonly ICallDetailRepository _callDetailRepository;
  18. public DtmfNotificationHandler(IIvrDomainService ivrDomainService, ICallDetailRepository callDetailRepository, ICallRepository callRepository, INewRockClient newRockClient, IOptionsSnapshot<CallCenterConfiguration> callcenterOptions,ICallCacheManager callCacheManager,IRealtimeService realtimeService) :base(newRockClient, callcenterOptions,callRepository, callCacheManager,realtimeService)
  19. {
  20. _ivrDomainService = ivrDomainService;
  21. _callDetailRepository = callDetailRepository;
  22. _callRepository = callRepository;
  23. }
  24. public async Task Handle(DtmfNotification notification, CancellationToken cancellationToken)
  25. {
  26. bool isvis = true;
  27. string menuId = string.Empty;
  28. string info = string.Empty;
  29. var model = await _callRepository.GetAsync(
  30. x => x.ConversationId == notification.Visitor.Id && x.FromNo == notification.Visitor.From &&
  31. x.ToNo == notification.Visitor.To,true,x=>x.CreationTime, cancellationToken);
  32. if (model == null)
  33. {
  34. model = await _callRepository.GetAsync(
  35. x => x.ConversationId == notification.Outer.Id && x.FromNo == notification.Outer.From &&
  36. x.ToNo == notification.Outer.To,true,x=>x.CreationTime, cancellationToken);
  37. isvis = false;
  38. }
  39. if (model != null)
  40. {
  41. var detail = new CallDetail()
  42. {
  43. CallId = model.Id,
  44. CallStatus = ECallStatus.Dtmf,
  45. EventName = notification.Attribute,
  46. };
  47. if (isvis)
  48. {
  49. detail.OMCallId = notification.Visitor.CallId;
  50. detail.ConversationId = notification.Visitor.Id;
  51. detail.FromNo = notification.Visitor.From;
  52. detail.ToNo = notification.Visitor.To;
  53. menuId = notification.Visitor.MenuId;
  54. info = notification.Visitor.Info;
  55. }
  56. else
  57. {
  58. detail.OMCallId = notification.Outer.CallId;
  59. detail.ConversationId = notification.Outer.Id;
  60. detail.FromNo = notification.Outer.From;
  61. detail.ToNo = notification.Outer.To;
  62. menuId = notification.Outer.MenuId;
  63. info = notification.Outer.Info;
  64. }
  65. detail.Remark = info;
  66. await _callDetailRepository.AddAsync(detail, cancellationToken);
  67. #region 处理评价
  68. var callDetail = await _callDetailRepository.GetAsync(x => x.CallId == model.Id && x.EventName == "EVALUATE", cancellationToken);
  69. if (callDetail != null)
  70. {
  71. callDetail.Remark = info;
  72. await _callDetailRepository.UpdateAsync(callDetail, cancellationToken);
  73. }
  74. #endregion
  75. //调用事件处理
  76. var dtmfResult = await _ivrDomainService.GetDtmfAnswerAsync(menuId, info, cancellationToken);
  77. await base.HandlerIvr(dtmfResult, model, cancellationToken);
  78. }
  79. }
  80. }
  81. }