123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using Hotline.Caching.Interfaces;
- using Hotline.CallCenter.BlackLists;
- using Hotline.CallCenter.Calls;
- using Hotline.CallCenter.Devices;
- using Hotline.Settings;
- using Hotline.Share.Enums.CallCenter;
- using Hotline.Share.Notifications;
- using Hotline.Tools;
- using MediatR;
- using Microsoft.Extensions.Options;
- using NewRock.Sdk;
- using NewRock.Sdk.Accept.Request;
- using NewRock.Sdk.Control.Request;
- namespace Hotline.Application.Handlers.CallCenter.FlowControl
- {
- public class InviteNotificationHandler : INotificationHandler<InviteNotification>
- {
- private readonly ICallRepository _callRepository;
- private readonly ICallDetailRepository _callDetailRepository;
- private readonly IUserCacheManager _userCacheManager;
- private readonly IBlacklistDomainService _blacklistDomainService;
- private readonly INewRockClient _newRockClient;
- private readonly IOptionsSnapshot<CallCenterConfiguration> _options;
- private readonly IOptionsSnapshot<WorkTimeSettings> _workTimeOptions;
- public InviteNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository, IUserCacheManager userCacheManager, IBlacklistDomainService blacklistDomainService, INewRockClient newRockClient, IOptionsSnapshot<CallCenterConfiguration> options, IOptionsSnapshot<WorkTimeSettings> workTimeOptions)
- {
- _callRepository = callRepository;
- _callDetailRepository = callDetailRepository;
- _userCacheManager = userCacheManager;
- _blacklistDomainService = blacklistDomainService;
- _newRockClient = newRockClient;
- _options = options;
- _workTimeOptions = workTimeOptions;
- }
- public bool IsInWrokTime()
- {
- return false;
- }
- public async Task Handle(InviteNotification notification, CancellationToken cancellationToken)
- {
- //验证来电是否在黑名单中
- bool isblacklist = _blacklistDomainService.IsInBlacklist(notification.Visitor.From);
- //获取星期数
- //string weeekNum = WeekTool.GetWeekNum();
- //TODO 去掉绑定用户信息
- //var workModel = _userCacheManager.GetWorkByTel(notification.Visitor.To);
- var isp = PhoneIspTool.GetPhoneIsp(notification.Visitor.From);
- var model = new Call()
- {
- CallStatus = ECallStatus.PreIncoming,
- CallDirection = ECallDirection.In,
- CallType = ECallType.VisitorCallIn,
- ConversationId = notification.Visitor.Id,
- FromNo = notification.Visitor.From,
- ToNo = notification.Visitor.To,
- Trunk = notification.TrunkId,
- //UserId = workModel.UserId,
- //UserName = workModel.UserName,
- PhoneIsp = isp,
- };
- if (isblacklist)
- model.RingOffType = ERingOffType.BlackList;
- model.Modified();
- var callid = await _callRepository.AddAsync(model, cancellationToken);
- var detail = new CallDetail()
- {
- CallId = callid,
- CallStatus = ECallStatus.PreIncoming,
- OMCallId = notification.Visitor.CallId,
- ConversationId = notification.Visitor.Id,
- EventName = notification.Attribute,
- FromNo = notification.Visitor.From,
- ToNo = notification.Visitor.To,
- };
- await _callDetailRepository.AddAsync(detail, cancellationToken);
- //如果是在黑名单中直接挂断
- if (isblacklist)
- {
- await _newRockClient.ClearCall(new ClearCallRequest()
- {
- Attribute = "Clear",
- Visitor = new ClearCallVisitor()
- {
- Id = notification.Visitor.Id
- }
- }, _options.Value.DeviceConfigs.ReceiveKey, _options.Value.DeviceConfigs.Expired, cancellationToken);
- }
- else
- {
- await _newRockClient.AcceptVisitor(
- new AcceptVisitorRequest()
- { Attribute = "Accept", Visitor = new AcceptVisitorModel() { Id = notification.Visitor.Id } },
- _options.Value.DeviceConfigs.ReceiveKey, _options.Value.DeviceConfigs.Expired, cancellationToken);
- }
- }
- }
- }
|