using CallCenter.Caches; using CallCenter.Calls; using CallCenter.Devices; using CallCenter.Ivrs; using CallCenter.Notifications; using CallCenter.Share.Enums; using MediatR; using Microsoft.Extensions.Options; using NewRock.Sdk; namespace CallCenter.Application.Handlers { public class EndOfAnnOuterToMenuNotificationHandler:BaseHandler,INotificationHandler { private readonly ICallRepository _callRepository; private readonly ICallDetailRepository _callDetailRepository; private readonly IIvrDomainService _ivrDomainService; private readonly ICallCacheManager _callCacheManager; public EndOfAnnOuterToMenuNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository, IIvrDomainService ivrDomainService, INewRockClient newRockClient, IOptionsSnapshot options,ICallCacheManager callCacheManager) : base(newRockClient, options,callCacheManager, callRepository) { _callRepository = callRepository; _callDetailRepository = callDetailRepository; _ivrDomainService = ivrDomainService; } public async Task Handle(EndOfAnnOuterToMenuNotification notification, CancellationToken cancellationToken) { var model =await _callRepository.GetAsync( x => x.ConversationId == notification.Outer.Id && x.FromNo == notification.Outer.From && x.ToNo == notification.Outer.To && x.CreationTime >= DateTime.Now.AddHours(-2), cancellationToken); if (model!=null) { model.CallStatus = ECallStatus.EndOfAnn; await _callRepository.UpdateAsync(model,cancellationToken); var detail = new CallDetail() { CallId = model.Id, CallStatus = ECallStatus.EndOfAnn, OMCallId = notification.Outer.CallId, ConversationId = notification.Outer.Id, EventName = notification.Attribute, FromNo = notification.Outer.From, ToNo = notification.Outer.To }; await _callDetailRepository.AddAsync(detail, cancellationToken); var runModel = await _ivrDomainService.GetVoiceEndAnswerAsync(notification.MenuId,cancellationToken); await HandlerIvr(runModel, model, cancellationToken); } } } }