コード例 #1
0
        private static async Task <IncomingInboxIntegrationEvent> MakeCommonCall(
            this ServiceProvider serviceProvider,
            string callerExtension,
            string smsText = null)
        {
            var callManagementService = serviceProvider.GetScopedService <CallManagementService>();

            var newCall = new IncomingInboxIntegrationEvent
            {
                ItemId          = Guid.NewGuid(),
                CallerExtension = callerExtension,
                Sms             = new Sms
                {
                    Message = smsText
                },
                ContractInboxItemType = smsText == null ? ContractInboxItemType.Call : ContractInboxItemType.Sms
            };
            await callManagementService.AddIncomingCall(newCall);

            return(newCall);
        }
コード例 #2
0
        /// <summary>
        /// Добавить вызов в очередь и сообщить об этом оператору.
        /// </summary>
        public async Task AddIncomingCall(IncomingInboxIntegrationEvent incomingInboxIntegrationEvent)
        {
            var itemId = incomingInboxIntegrationEvent.ItemId;

            if (itemId == default)
            {
                _logger.Warning($"Empty {nameof(itemId)}: {itemId}");
                return;
            }

            var extension = incomingInboxIntegrationEvent.CallerExtension;

            if (string.IsNullOrWhiteSpace(extension))
            {
                _logger.Warning($"AddIncomingCall. Empty CallerExtension. {nameof(itemId)}: {itemId}");
                return;
            }

            using UnitOfWork unitOfWork = _unitOfWork.Begin();

            bool isSms = incomingInboxIntegrationEvent.ContractInboxItemType == ContractInboxItemType.Sms;

            var smsMessageData = _mapper.Map <SmsMessageData>(incomingInboxIntegrationEvent.Sms);
            var caller         = await GetCaller(extension);

            if (isSms)
            {
                var locationMetadata = JsonConvert.SerializeObject(smsMessageData.Location ?? new SmsLocationData {
                    Position = new SmsPositionData()
                });
                var sms = new Sms(itemId)
                {
                    Status           = SmsStatus.New,
                    ArrivalDateTime  = incomingInboxIntegrationEvent.ArrivalDateTime,
                    Text             = smsMessageData.Message,
                    Applicant        = caller,
                    LocationMetadata = locationMetadata,
                    Timestamp        = smsMessageData.Timestamp
                };

                await _smsRepository.Add(sms);

                await unitOfWork.CommitAsync();

                _logger.Debug($"Added incoming sms with id: {itemId}");
            }
            else
            {
                var result = await _callManagementServiceClient.AddIncomingCall(
                    itemId,
                    caller.Id,
                    incomingInboxIntegrationEvent.ArrivalDateTime);

                if (result.IsFailure)
                {
                    _logger.Error($"AddIncomingCall. {result.ErrorMessage}");
                    return;
                }

                await _participantRepository.Add(caller);

                await unitOfWork.CommitAsync();
            }

            await _phoneHubMessageService.NotifyUsersAboutInboxUpdate(incomingInboxIntegrationEvent.InboxId);
        }