123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- using CallCenter.Calls;
- using CallCenter.Share.Enums;
- using NewRock.Sdk.Control.Request;
- using NewRock.Sdk.Transfer.Connect.Request;
- using NewRock.Sdk.Transfer.Queue.Request;
- using CallCenter.Share.Dtos;
- using NewRock.Sdk;
- using CallCenter.Devices;
- using Microsoft.Extensions.Options;
- using CallCenter.Caches;
- using CallCenter.Repository.SqlSugar;
- using CallCenter.Realtimes;
- using MediatR;
- using NewRock.Sdk.Control.Response;
- namespace CallCenter.Application.Handlers
- {
- public class BaseHandler
- {
- private readonly INewRockClient _newRockClient;
- private readonly IOptionsSnapshot<DeviceConfigs> _options;
- private readonly IOptionsSnapshot<QueueVoiceConfig> _queueVoiceConfig;
- private readonly ICallCacheManager _callCacheManager;
- private readonly ICallRepository _callRepository;
- private readonly IRealtimeService _realtimeService;
- public BaseHandler(INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options, IOptionsSnapshot<QueueVoiceConfig> queueVoiceConfig,ICallCacheManager callCacheManager, ICallRepository callRepository,IRealtimeService realtimeService)
- {
- _newRockClient = newRockClient;
- _options = options;
- _queueVoiceConfig = queueVoiceConfig;
- _callCacheManager = callCacheManager;
- _callRepository = callRepository;
- _realtimeService = realtimeService;
- }
- public async Task HandlerIvr(IvrAnswer? runResult,Call model,CancellationToken cancellationToken)
- {
- if (runResult != null)
- {
- var ivrAnswer = runResult;
- switch (ivrAnswer.IvrAnswerType)
- {
- case EIvrAnswerType.Voice:
- var tomenuId = ivrAnswer.Content;
- switch (model?.CallType)
- {
- case ECallType.ExtToOuter:
- await _newRockClient.OuterToMenu(new OuterToMenuRequest()
- {
- Attribute = "Connect",
- Menu = new OuterToMenuMenu() { Id = tomenuId },
- Outer = new OuterToMenuOuter() { Id = model.ConversationId },
- //VoiceFile = string.IsNullOrEmpty(ivrAnswer.PreVoice) ? "" : ivrAnswer.PreVoice,
- }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
- break;
- case ECallType.VisitorCallIn:
- await _newRockClient.VisitorToMenu(new VisitorToMenuRequest()
- {
- Attribute = "Connect",
- Menu = new VisitorToMenuMenu() { Id = tomenuId },
- Visitor = new VisitorToMenuVisitor() { Id = model.ConversationId },
- //VoiceFile = string.IsNullOrEmpty(ivrAnswer.PreVoice) ? "" : ivrAnswer.PreVoice,
- }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- break;
- case EIvrAnswerType.Tel:
- var telNo = ivrAnswer.Content;
- switch (model.CallType)
- {
- case ECallType.VisitorCallIn:
- //await _newRockClient.VisitorToExt(new VisitorToExtRequest()
- //{
- // Attribute = "Connect",
- // Ext = new VisitorToExtExt() { Id = telNo },
- // VoiceFile = string.IsNullOrEmpty(ivrAnswer.PreVoice) ? "" : ivrAnswer.PreVoice,
- // AutoAnswer = "",
- //}, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
- //来电去队列
- await _newRockClient.VisitorToExtQueue(new VisitorToExtQueueRequest()
- {
- Attribute = "Queue",
- Ext = new VisitorToExtQueueExt() { Id = telNo },
- Visitor = new VisitorToExtQueueVisitor() { Id = model.ConversationId }
- }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
- break;
- case ECallType.ExtToOuter:
- await _newRockClient.OuterToExt(new OuterToExtRequest()
- {
- Attribute = "Connect",
- Ext = new OuterToExtExt() { Id = telNo },
- Outer = new OuterToExtOuter() { Id = model.ConversationId }
- }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- break;
- case EIvrAnswerType.TelGroup:
- var groupId = ivrAnswer.Content;
- if (model.InIvrTime!=null)
- {
- model.OutIvrTime = DateTime.Now;
- }
- model.InGroupTime = DateTime.Now;
- await _callRepository.UpdateAsync(model,cancellationToken);
- await _newRockClient.VisitorToGroupQueue(new VisitorToGroupQueueRequest()
- {
- Attribute = "Queue",
- Group = new VisitorToGroupQueueGroup() { Id = groupId },
- Visitor = new VisitorToGroupQueueVisitor() { Id = model.ConversationId }
- }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
- //处理队列记录 TODO
- _callCacheManager.AddCallCache(model,groupId);
- await _realtimeService.CallQueueAsync(_callCacheManager.GetCallQueueList(), cancellationToken);
- // TODO 插播排队语音
- //var groupResult = await _newRockClient.QueryExtGroup(new QueryExtGroupRequest() { Attribute = "Query", Group = new QueryExtGroup() { Id = groupId } }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
- //if (groupResult.Group[0].Visitor.Count > 0)
- //{
- // string voiceStr = _queueVoiceConfig.Value.QueueVoice;
- // voiceStr = String.Format(voiceStr, groupResult.Group[0].Visitor.Count, groupResult.Group[0].Visitor.Count);
- // await _newRockClient.VoiceNewsFlash(new VoiceNewsFlashRequest() { Attribute = "Connect", Visitor = new VoiceNewsFlashVisitor() { Id = model.ConversationId }, VoiceFile = voiceStr }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
- //}
- break;
- case EIvrAnswerType.Out:
- var phoneNo = ivrAnswer.Content;
- switch (model.CallType)
- {
- case ECallType.VisitorCallIn:
- await _newRockClient.VisitorToOuter(new VisitorToOuterRequest()
- {
- Attribute = "Connect",
- Visitor = new VisitorToOuterVisitor() { Id = model.ConversationId },
- Outer = new VisitorToOuterOuter()
- {
- To = phoneNo,
- //TODO DISPLAY属性待定
- }
- },
- _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
- break;
- case ECallType.ExtToOuter:
- await _newRockClient.OuterToOuter(new OuterToOuterRequest()
- {
- Attribute = "Connect",
- Outer = new List<OuterToOuterOuterModel>(){
- new(){Id = model.ConversationId},
- new(){To = phoneNo},
- }
- }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- break;
- case EIvrAnswerType.HangUp:
- var id = ivrAnswer.Content;
- switch (model?.CallType)
- {
- case ECallType.VisitorCallIn:
- await _newRockClient.ClearCall(new ClearCallRequest()
- {
- Attribute = "Clear",
- Visitor = new ClearCallVisitor() { Id = model.ConversationId },
- }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
- break;
- case ECallType.ExtToOuter:
- await _newRockClient.ClearCall(new ClearCallRequest()
- {
- Attribute = "Clear",
- Outer = new ClearCallOuter() { Id = model.ConversationId },
- }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
- break;
- }
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- }
- }
- }
- }
|