Пример #1
0
        public async Task <string> GetNumberDetailsAsync(string requestBody)
        {
            ValidateHostUrls();
            Response responseResult;

            try
            {
                IncomingCall call = ParseCallParameters(requestBody);
                if (call == null)
                {
                    _logger.LogWarning($"Returning Twilio Disconnect Call response. Incoming call is null.");
                    responseResult = CallResponseService.DisconnectCallResponse();
                }
                else
                {
                    responseResult = await ProcessNumberRoutingAsync(call);
                }

                var resultJson = JsonConvert.SerializeObject(responseResult);
                _logger.LogInformation($"GetNumberDetailsAsync Success");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"GetNumberDetailsAsync Exception. Details: {ex.Message}");
                responseResult = CallResponseService.DisconnectCallResponse();
            }

            _logger.LogDebug($"{JsonConvert.SerializeObject(responseResult)}");

            var result = TwilioXmlSerializer.XmlSerialize(responseResult);

            _logger.LogInformation($"GetNumberRouteAsync response: {result}");

            return(result);
        }
Пример #2
0
        private async Task <Response> ProcessNumberRoutingAsync(IncomingCall call)
        {
            if (string.IsNullOrEmpty(call?.To))
            {
                _logger.LogWarning($"Returning Twilio Reject response for callSid: '{call.CallSid}'");
                return(CallResponseService.RejectResponse());
            }

            try
            {
                var numberRouteInfo = await GetNumberRouteDataAsync(call.To);

                if (numberRouteInfo == null)
                {
                    _logger.LogInformation($"Returning Twilio Hangup response for callSid: '{call.CallSid}', StatusId is 'Error'");
                    await LogCallAsync(call, CallStatus.NotAssigned);

                    return(CallResponseService.HangupResponse());
                }

                await LogCallAsync(call, CallStatus.Accepted, true);

                return(HandleBasicRoute(numberRouteInfo.routeDetails.routes[0]));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"ProcessNumberRoutingAsync Exception. Details: {ex.Message}");
                await LogCallAsync(call, CallStatus.Error);

                throw;
            }
        }