Ejemplo n.º 1
0
        public SmsSendMessageResponse SendMessage(string to, string from, string message)
        {
            var requestMessage = new AqlMessageBuilder().Build(to, from, message);
            var rawResponse    = CallAqlApiForSend(requestMessage);
            var statusCode     = GetStatusCode(rawResponse);

            if (statusCode == null)
            {
                return(new SmsSendMessageResponse {
                    ErrorMessage = "Invalid API response, check logs for details"
                });
            }
            if (statusCode.Substring(0, 1) != "2" && statusCode.Substring(0, 1) != "1")
            {
                _logger.Error($"AQL status code was [{statusCode}], response was [{rawResponse}]", null);
                return(new SmsSendMessageResponse {
                    ErrorMessage = $"Received status code {statusCode} from AQL, check logs for details"
                });
            }
            var json = GetJson(rawResponse);

            if (json == null)
            {
                return(new SmsSendMessageResponse {
                    ErrorMessage = "Invalid API response body, check logs for details"
                });
            }

            return(new SmsSendMessageResponse {
                IsSuccess = true
            });
        }
Ejemplo n.º 2
0
        public SmsSendMessageResponse SendMessage(string to, string from, string message)
        {
            var requestMessage = new AqlMessageBuilder().Build(to, from, message);
            var client         = new WebClient();

            client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
            client.Headers.Add("x-auth-token", _authToken);

            string json;

            try
            {
                json = client.UploadString("https://api.aql.com/v2/sms/send", "POST", requestMessage);
            }
            catch (Exception ex)
            {
                _logger.Error($"Error Sending SMS via AQL. Body is [{requestMessage}]", ex);
                return(new SmsSendMessageResponse {
                    ErrorMessage = "Error sending messages, see log for details"
                });
            }
            _logger.Debug($"AQL Send Response [{json}]");
            //var response = JsonConvert.DeserializeObject<SmsSendResponse>(json);
            return(new SmsSendMessageResponse {
                IsSuccess = true
            });
        }