|
@@ -0,0 +1,860 @@
|
|
|
+using CallCenter.Calls;
|
|
|
+using CallCenter.Devices;
|
|
|
+using CallCenter.Share.Dtos;
|
|
|
+using CallCenter.Tels;
|
|
|
+using MapsterMapper;
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
+using NewRock.Sdk;
|
|
|
+using NewRock.Sdk.Accept.Request;
|
|
|
+using NewRock.Sdk.Control.Request;
|
|
|
+using NewRock.Sdk.Control.Request.Base;
|
|
|
+using NewRock.Sdk.Manage.Request;
|
|
|
+using NewRock.Sdk.Transfer.Conference.Request;
|
|
|
+using NewRock.Sdk.Transfer.Connect.Request;
|
|
|
+using NewRock.Sdk.Transfer.Queue.Request;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
+using NewRock.Sdk.Control.Response;
|
|
|
+using XF.Domain.Dependency;
|
|
|
+using XF.Domain.Exceptions;
|
|
|
+using Group = NewRock.Sdk.Control.Request.Group;
|
|
|
+using CallCenter.Share.Enums;
|
|
|
+
|
|
|
+namespace CallCenter.NewRock
|
|
|
+{
|
|
|
+ public class DeviceManager : IDeviceManager, IScopeDependency
|
|
|
+ {
|
|
|
+ private readonly INewRockClient _newRockClient;
|
|
|
+ private readonly ICallRepository _callRepository;
|
|
|
+ private readonly IOptionsSnapshot<DeviceConfigs> _options;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+
|
|
|
+ public DeviceManager(INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options, IMapper mapper, ICallRepository callRepository)
|
|
|
+ {
|
|
|
+ _newRockClient = newRockClient;
|
|
|
+ _options = options;
|
|
|
+ _mapper = mapper;
|
|
|
+ _callRepository = callRepository;
|
|
|
+ }
|
|
|
+
|
|
|
+ #region 查询
|
|
|
+
|
|
|
+ public async Task<TelDto> QueryTelAsync(string TelNo, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var result = await _newRockClient.QueryExt(
|
|
|
+ new QueryExtRequest() { Attribute = "Query", Ext = new Ext { Id = TelNo } },
|
|
|
+ _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
|
|
|
+
|
|
|
+ if (result?.Ext.Outer != null)
|
|
|
+ {
|
|
|
+ var telDto = new TelDto();
|
|
|
+ telDto.CPN = result.Ext.Outer.From;
|
|
|
+ telDto.CDPN = result.Ext.Outer.To;
|
|
|
+ telDto.TelStatusInfo = ETelStatusInfo.Out;
|
|
|
+ telDto.ConversationId = result.Ext.Outer.Id;
|
|
|
+ if (result.Ext.Outer.State == "talk")
|
|
|
+ {
|
|
|
+ telDto.TelStatus = Share.Enums.ETelStatus.Talk;
|
|
|
+ return telDto;
|
|
|
+ }
|
|
|
+ else if (result.Ext.Outer.State == "wait")
|
|
|
+ {
|
|
|
+ telDto.TelStatus = Share.Enums.ETelStatus.Wait;
|
|
|
+ }
|
|
|
+ return telDto;
|
|
|
+ }
|
|
|
+ if (result?.Ext.Visitor != null)
|
|
|
+ {
|
|
|
+ var telDto = new TelDto();
|
|
|
+ telDto.CPN = result.Ext.Visitor.From;
|
|
|
+ telDto.CDPN = result.Ext.Visitor.To;
|
|
|
+ telDto.TelStatusInfo = ETelStatusInfo.Into;
|
|
|
+ telDto.ConversationId = result.Ext.Visitor.Id;
|
|
|
+ if (result.Ext.Visitor.State == "talk")
|
|
|
+ {
|
|
|
+ telDto.TelStatus = Share.Enums.ETelStatus.Talk;
|
|
|
+ return telDto;
|
|
|
+ }
|
|
|
+ else if (result.Ext.Visitor.State == "wait")
|
|
|
+ {
|
|
|
+ telDto.TelStatus = Share.Enums.ETelStatus.Wait;
|
|
|
+ }
|
|
|
+ return telDto;
|
|
|
+ }
|
|
|
+ if (result?.Ext.Ext != null)
|
|
|
+ {
|
|
|
+ var telDto = new TelDto();
|
|
|
+ telDto.CPN = result.Ext.Ext.Id;
|
|
|
+ telDto.CDPN = result.Ext.Id;
|
|
|
+ telDto.TelStatusInfo = ETelStatusInfo.Ext;
|
|
|
+ if (result.Ext.Ext.State == "talk")
|
|
|
+ {
|
|
|
+ telDto.TelStatus = Share.Enums.ETelStatus.Talk;
|
|
|
+ return telDto;
|
|
|
+ }
|
|
|
+ else if (result.Ext.Ext.State == "wait")
|
|
|
+ {
|
|
|
+ telDto.TelStatus = Share.Enums.ETelStatus.Wait;
|
|
|
+ }
|
|
|
+ return telDto;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询所有分机
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<List<Tel>> QueryTelsAsync(CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var result = await _newRockClient.QueryDeviceInfo(
|
|
|
+ new QueryDeviceInfoRequest { Attribute = "Query", DeviceInfo = string.Empty },
|
|
|
+ _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ var exts = result.Devices.Ext;
|
|
|
+ return _mapper.Map<List<Tel>>(exts);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询所有分机组
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<List<TelGroup>> QueryTelGroupsAsync(CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var result = await _newRockClient.QueryDeviceInfo(
|
|
|
+ new QueryDeviceInfoRequest { Attribute = "Query", DeviceInfo = string.Empty },
|
|
|
+ _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+
|
|
|
+ var groups = result.Devices.Group;
|
|
|
+ return _mapper.Map<List<TelGroup>>(groups);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询语音文件
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<string> VoiceQueryListAsync(CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var result = await _newRockClient.VoiceQueryList(new VoiceQueryListRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Query",
|
|
|
+ VoiceFile = "",
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ return result?.VoiceFile;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task QueryGroupAsync(string groupId, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.QueryExtGroup(new QueryExtGroupRequest()
|
|
|
+ { Attribute = "Query", Group = new QueryExtGroup() { Id = groupId } },
|
|
|
+ _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 配置
|
|
|
+ /// <summary>
|
|
|
+ /// 分机休息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="telNo">分机号</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task TelRestAsync(string telNo, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var telModel = await _newRockClient.QueryExt(new QueryExtRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Query",
|
|
|
+ Ext = new Ext() { Id = telNo }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+
|
|
|
+ if (telModel == null)
|
|
|
+ throw new UserFriendlyException("未知分机");
|
|
|
+
|
|
|
+ await _newRockClient.ConfigExt(
|
|
|
+ new AssginConfigExtRequest() { Attribute = "Assign", Ext = new ConfigExt() { Lineid = telModel.Ext.LineId, Groups=telModel.Ext.Group.Select(x=>x.Id).ToList(), No_Disturb = "On" } },
|
|
|
+ _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 分机结束休息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="telNo">分机号</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task TelEndRestAsync(string telNo, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var telModel = await _newRockClient.QueryExt(new QueryExtRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Query",
|
|
|
+ Ext = new Ext() { Id = telNo }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+
|
|
|
+ if (telModel == null)
|
|
|
+ throw new UserFriendlyException("未知分机");
|
|
|
+
|
|
|
+ await _newRockClient.ConfigExt(
|
|
|
+ new AssginConfigExtRequest() { Attribute = "Assign", Ext = new ConfigExt() { Lineid = telModel.Ext.LineId, Groups = telModel.Ext.Group.Select(x => x.Id).ToList(), No_Disturb = "Off" } },
|
|
|
+ _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 删除语音文件
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="voiceName"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task RemoveVoiceFileAsync(string voiceName, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.RemoveVoiceFile(new RemoveVoiceFileRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Remove",
|
|
|
+ VoiceFile = voiceName
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 配置语音菜单
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="menuId"></param>
|
|
|
+ /// <param name="voiceFile"></param>
|
|
|
+ /// <param name="repeat"></param>
|
|
|
+ /// <param name="infoLength"></param>
|
|
|
+ /// <param name="exit"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task AssginConfigMenuAsync(string menuId, string voiceFile, string repeat, string infoLength,
|
|
|
+ string exit,
|
|
|
+ CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (!int.TryParse(menuId, out int mId))
|
|
|
+ throw new UserFriendlyException("请输入数字");
|
|
|
+
|
|
|
+ if (mId < 1 || mId > 50)
|
|
|
+ throw new UserFriendlyException("菜单只允许在1-50范围内");
|
|
|
+
|
|
|
+ if (exit!="")
|
|
|
+ {
|
|
|
+ Regex r = new Regex(@"^[a-d]|[A-D]|[1-9]|[*]|[#]$");
|
|
|
+ if (!r.IsMatch(exit))
|
|
|
+ throw new UserFriendlyException("输入指令不合法,合法值:A-D、1-9、*、#");
|
|
|
+ }
|
|
|
+
|
|
|
+ var resp = await _newRockClient.ConfigMenu(new AssginConfigMenuRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Assign",
|
|
|
+ Menu = new AssginConfigMenuMenu()
|
|
|
+ {
|
|
|
+ Id = menuId,
|
|
|
+ VoiceFile = voiceFile,
|
|
|
+ InfoLength = infoLength,
|
|
|
+ Exit = exit,
|
|
|
+ Repeat = repeat,
|
|
|
+ }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 配置分机组
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="groupId"></param>
|
|
|
+ /// <param name="voiceFile"></param>
|
|
|
+ /// <param name="distribution"></param>
|
|
|
+ /// <param name="ext"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task AssginConfigGroupAsync(string groupId, string distribution, List<string> ext, string? voiceFile = "",CancellationToken cancellationToken=default)
|
|
|
+ {
|
|
|
+ if (!int.TryParse(groupId, out int mId))
|
|
|
+ throw new UserFriendlyException("请输入数字");
|
|
|
+
|
|
|
+ if (mId < 1 || mId > 50)
|
|
|
+ throw new UserFriendlyException("分机组只允许在1-50范围内");
|
|
|
+
|
|
|
+ var groupModel = new Group()
|
|
|
+ {
|
|
|
+ Id = groupId,
|
|
|
+ Distribution = distribution,
|
|
|
+ Ext = ext,
|
|
|
+ };
|
|
|
+ if (!string.IsNullOrEmpty(voiceFile))
|
|
|
+ groupModel.Voicefile = voiceFile;
|
|
|
+
|
|
|
+ var resp = await _newRockClient.ConfigExtGroup(new AssginConfigGroupRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Assign",
|
|
|
+ Group = groupModel
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 更新分机组
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="groupId"></param>
|
|
|
+ /// <param name="ext"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <param name="isAdd"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task ModifyGroupExtAsync(string groupId, List<string> ext,string voicefile="",bool isAdd=true,CancellationToken cancellationToken = default)
|
|
|
+ {
|
|
|
+ if (!int.TryParse(groupId, out int mId))
|
|
|
+ throw new UserFriendlyException("请输入数字");
|
|
|
+
|
|
|
+ if (mId < 1 || mId > 50)
|
|
|
+ throw new UserFriendlyException("分机组只允许在1-50范围内");
|
|
|
+
|
|
|
+ //查询原设备数据
|
|
|
+ var result = await _newRockClient.QueryExtGroup(
|
|
|
+ new QueryExtGroupRequest() { Attribute = "Query", Group = new QueryExtGroup() { Id = groupId } },
|
|
|
+ _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken
|
|
|
+ );
|
|
|
+ //更新
|
|
|
+ var exts = result.Group[0].Ext;
|
|
|
+ var groupModel = new Group()
|
|
|
+ {
|
|
|
+ Id = groupId,
|
|
|
+ Voicefile = voicefile
|
|
|
+ };
|
|
|
+
|
|
|
+ if (isAdd)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < ext.Count; i++)
|
|
|
+ {
|
|
|
+ exts.Add(new QueryExtGroupExt(){ Id = ext[i] });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ for (int i = 0; i < ext.Count; i++)
|
|
|
+ {
|
|
|
+ exts.Remove(exts.First(x=>x.Id == ext.First()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ groupModel.Ext = exts.Select(x=>x.Id).ToList();
|
|
|
+ await _newRockClient.ConfigExtGroup(
|
|
|
+ new AssginConfigGroupRequest() { Attribute = "Assign", Group = groupModel, },
|
|
|
+ _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 上班/下班
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="telNo"></param>
|
|
|
+ /// <param name="staffNo"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task UpdateStaffNoAsync(string telNo, string staffNo,string lineId, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var telModel = await _newRockClient.QueryExt(new QueryExtRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Query",
|
|
|
+ Ext = new Ext() { Id = telNo }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+
|
|
|
+ if (telModel == null)
|
|
|
+ throw new UserFriendlyException("未知分机");
|
|
|
+
|
|
|
+ await _newRockClient.ConfigExt(
|
|
|
+ new AssginConfigExtRequest() { Attribute = "Assign", Ext = new ConfigExt() { Id = telNo,Lineid = lineId, Staffid = staffNo } },
|
|
|
+ _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 通话控制
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 保持通话
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="telNo">分机号</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task HoldAsync(string telNo, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.HoldOrUnHold(
|
|
|
+ new HoldSetRequest() { Attribute = "Hold", Ext = new Ext() { Id = telNo } }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 恢复通话(解除hold状态)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="telNo">分机号</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task UnHoldAsync(string telNo, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.HoldOrUnHold(
|
|
|
+ new HoldSetRequest() { Attribute = "Unhold", Ext = new Ext() { Id = telNo } }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 静音开启
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="telNo">分机号</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task MuteAsync(string telNo, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.MuteOrUnMute(
|
|
|
+ new MuteSetRequest() { Attribute = "Mute", Ext = new Ext() { Id = telNo } }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 解除静音
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="telNo">分机号</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task UnMuteAsync(string telNo, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.MuteOrUnMute(
|
|
|
+ new MuteSetRequest() { Attribute = "Unmute", Ext = new Ext() { Id = telNo } },
|
|
|
+ _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 强拆分机
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="extId"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task ClearExtAsync(string extId, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.ClearCall(new ClearCallRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Clear",
|
|
|
+ Ext = new Ext()
|
|
|
+ {
|
|
|
+ Id = extId
|
|
|
+ }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 强拆来电
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="visitorId"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task ClearVisitorAsync(string visitorId, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.ClearCall(new ClearCallRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Clear",
|
|
|
+ Visitor = new ClearCallVisitor() { Id = visitorId }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 强拆去电
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="outerId"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task ClearOuterAsync(string outerId, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.ClearCall(new ClearCallRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Clear",
|
|
|
+ Outer = new ClearCallOuter() { Id = outerId }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 来电受理
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="visitorId"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task AcceptVisitorAsync(string visitorId, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.AcceptVisitor(new AcceptVisitorRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Accept",
|
|
|
+ Visitor = new AcceptVisitorModel() { Id = visitorId }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 连接呼叫
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 分机呼分机
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="from">主叫分机号</param>
|
|
|
+ /// <param name="to">被叫分机号</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task ExtToExtAsync(string from, string to, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.ExtensionToExtension(
|
|
|
+ new ExtensionToExtensionRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Connect",
|
|
|
+ Exts = new List<ExtToExtExt>() { new ExtToExtExt() { Id = from }, new ExtToExtExt() { Id = to } }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 分机呼外部电话
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="from">分机号</param>
|
|
|
+ /// <param name="to">外部电话,外地电话加拨0</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <param name="trunkid">指定中继线路(可为空),为空时默认由OM分配</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task ExtToOuterAsync(string from, string to, CancellationToken cancellationToken, string trunkid = "")
|
|
|
+ {
|
|
|
+ await _newRockClient.ExtToOuter(
|
|
|
+ new ExtToOuterRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Connect",
|
|
|
+ Ext = new ExtToOuterExtRequest() { Id = from },
|
|
|
+ Outer = new ExtToOuterOuterRequest() { To = to },
|
|
|
+ Trunk = new ExtToOuterTrunkRequest() { Id = trunkid }
|
|
|
+ },
|
|
|
+ _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 来电转分机
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="visitorId">来电会话ID</param>
|
|
|
+ /// <param name="telNo">分机号</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task VisitorToExtAsync(string visitorId, string telNo, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.VisitorToExt(new VisitorToExtRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Connect",
|
|
|
+ Visitor = new VisitorToExtVisitor() { Id = visitorId },
|
|
|
+ Ext = new VisitorToExtExt() { Id = telNo }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 来电转外部电话
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="visitorId">来电会话ID</param>
|
|
|
+ /// <param name="outerPhoneNum">外部电话,外地电话加拨0</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <param name="display">来电号码,用来透传主叫号码,使去电方的来电显示号码为实际来电号码。</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task VisitorToOuterAsync(string visitorId, string outerPhoneNum, CancellationToken cancellationToken,
|
|
|
+ string display = "")
|
|
|
+ {
|
|
|
+ await _newRockClient.VisitorToOuter(new VisitorToOuterRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Connect",
|
|
|
+ Visitor = new VisitorToOuterVisitor() { Id = visitorId },
|
|
|
+ Outer = new VisitorToOuterOuter() { To = outerPhoneNum, Display = display },
|
|
|
+
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 来电转语音菜单
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="visitorId">来电会话ID</param>
|
|
|
+ /// <param name="menuId">菜单ID</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task VisitorToMenuAsync(string visitorId, string menuId, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.VisitorToMenu(new VisitorToMenuRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Connect",
|
|
|
+ Visitor = new VisitorToMenuVisitor() { Id = visitorId },
|
|
|
+ Menu = new VisitorToMenuMenu() { Id = menuId }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 来电转分机组
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="visitorId"></param>
|
|
|
+ /// <param name="groupId"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task VisitorToGroupAsync(string visitorId, string groupId, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.VisitorToGroupQueue(new VisitorToGroupQueueRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Queue",
|
|
|
+ Visitor = new VisitorToGroupQueueVisitor() { Id = visitorId },
|
|
|
+ Group = new VisitorToGroupQueueGroup() { Id = groupId }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 去电转分机
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="outerId">去电会话ID</param>
|
|
|
+ /// <param name="telNo">分机号</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task OuterToExtAsync(string outerId, string telNo, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.OuterToExt(new OuterToExtRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Connect",
|
|
|
+ Outer = new OuterToExtOuter() { Id = outerId },
|
|
|
+ Ext = new OuterToExtExt() { Id = telNo }
|
|
|
+ },
|
|
|
+ _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 去电转外部电话
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="outerId">去电会话ID</param>
|
|
|
+ /// <param name="outerPhoneNum">外部电话,外地电话加拨0</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task OuterToOuterAsync(string outerId, string outerPhoneNum, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.OuterToOuter(new OuterToOuterRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Connect",
|
|
|
+ Outer = new List<OuterToOuterOuterModel>()
|
|
|
+ {
|
|
|
+ new OuterToOuterOuterModel() { Id = outerId },
|
|
|
+ new OuterToOuterOuterModel() { To = outerPhoneNum }
|
|
|
+ },
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 语音菜单呼叫分机
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="menuId">语音菜单ID</param>
|
|
|
+ /// <param name="telNo">分机号</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task MenuToExtAsync(string menuId, string telNo, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.MenuToExt(new MenuToExtRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Connect",
|
|
|
+ Menu = new MenuToExtMenu() { Id = menuId },
|
|
|
+ Ext = new MenuToExtExt() { Id = telNo }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 语音菜单呼外部电话
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="menuId">语音菜单ID</param>
|
|
|
+ /// <param name="outerPhoneNum">外部电话,外地电话加拨0</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task MenuToOuterAsync(string menuId, string outerPhoneNum, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.MenuToOuter(new MenuToOuterRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Connect",
|
|
|
+ Menu = new MenuToOuterMenu() { Id = menuId },
|
|
|
+ Outer = new MenuToOuterOuter() { To = outerPhoneNum }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 双向呼叫(回拨)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="outerOne">主叫外部电话,外地电话加拨0</param>
|
|
|
+ /// <param name="outerTwo">被叫外部电话,外地电话加拨0</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task TwoWayOuterAsync(string outerOne, string outerTwo, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.TwoWayOuter(new TwoWayOuterRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Connect",
|
|
|
+ Outer = new List<TwoWayOuterOuter>()
|
|
|
+ {
|
|
|
+ new TwoWayOuterOuter(){ To = outerOne},
|
|
|
+ new TwoWayOuterOuter(){ To = outerTwo}
|
|
|
+ }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 语音插播(分机)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="voiceFileName">语音名称</param>
|
|
|
+ /// <param name="telNo">分机号</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task VoiceNewsFlashExtAsync(string voiceFileName, string telNo, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.VoiceNewsFlash(new VoiceNewsFlashRequest
|
|
|
+ {
|
|
|
+ Attribute = "Connect",
|
|
|
+ VoiceFile = voiceFileName,
|
|
|
+ Ext = new VoiceNewsFlashExt() { Id = telNo }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 语音插播(来电)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="voiceFileName">语音名称</param>
|
|
|
+ /// <param name="visitorId">来电会话ID</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task VoiceNewsFlashVisitorAsync(string voiceFileName, string visitorId,
|
|
|
+ CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.VoiceNewsFlash(
|
|
|
+ new VoiceNewsFlashRequest
|
|
|
+ {
|
|
|
+ Attribute = "Connect",
|
|
|
+ VoiceFile = voiceFileName,
|
|
|
+ Visitor = new VoiceNewsFlashVisitor() { Id = visitorId }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 语音插播(去电)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="voiceFileName">语音名称</param>
|
|
|
+ /// <param name="outerId">去电会话ID</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task VoiceNewsFlashOuterAsync(string voiceFileName, string outerId, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.VoiceNewsFlash(
|
|
|
+ new VoiceNewsFlashRequest
|
|
|
+ {
|
|
|
+ Attribute = "Connect",
|
|
|
+ VoiceFile = voiceFileName,
|
|
|
+ Outer = new VoiceNewsFlashOuter() { Id = outerId }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 会议
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="telNo">发起方分机号</param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task ConferenceMeetingAsync(string telNo, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ await _newRockClient.ConferenceMeeting(new ConferenceMeetingRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Conference",
|
|
|
+ Ext = new ConferenceMeetingExt() { Id = telNo }
|
|
|
+ }, _options.Value.ReceiveKey,
|
|
|
+ _options.Value.Expired,
|
|
|
+ cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 处理IVR响应
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="callDetail"></param>
|
|
|
+ /// <param name="ivrAnswer"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task HandleIvrAnswerAsync(CallDetail callDetail, IvrAnswer ivrAnswer, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(ivrAnswer.Content))
|
|
|
+ throw new UserFriendlyException("无效IVR应答参数");
|
|
|
+
|
|
|
+ //获取是来电或去电
|
|
|
+ var model = await _callRepository.GetAsync(x => x.Id == callDetail.CallId, cancellationToken);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+}
|