/// <summary> /// Send multiple SMS message /// </summary> /// <param name="infomation">A required parameter for send multiple SMS</param> /// <returns>Response of sent SMS</returns> /// <exception cref="ValidationException"></exception> /// <exception cref="InvalidOperationException"></exception> public virtual Task <SendSmsListResponse> SendSMSListAsycn(SendSmsListRequest infomation) { var listOfPhoneNo = infomation.Data.Select(_ => _.PhoneNo).ToArray(); Log.Debug("{ApiClient} Attempt to send SMS [PhoneNo={PhoneNo}]", _clientTitle, String.Join(",", listOfPhoneNo)); return(SendSMSListAsycn(infomation, System.Threading.CancellationToken.None)); }
private async Task <SendSmsListResponse> SendSMSListAsycn(SendSmsListRequest infomation, CancellationToken none) { // Validation Information var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(infomation); Validator.ValidateObject(infomation, validationContext); var listOfPhoneNo = string.Join(",", infomation.Data.Select(_ => _.PhoneNo).ToArray()); SendSmsListResponse responseObject; // If Configulation is in SMS disable mode if (!_configulation.SendSmsApiEnable) { Log.Information("{ApiClient} Configulation is in SMS disable mode", _clientTitle); // Mockup data SMS Response var mockUpString = "{\"status\": \"000\",\"detail\": \"OK\",\"referenceHeaderID\": \"150605222\"}"; responseObject = JsonConvert.DeserializeObject <SendSmsListResponse>(mockUpString); } else { // Create request var request = new RestRequest(_SendSMSListEndpoint, DataFormat.Json); request.AddJsonBody(infomation); // Attemp request to Send SMS List var response = await Task.FromResult(_client.Post <SendSmsListResponse>(request)); Log.Verbose("{ApiClient} Requested to API", _clientTitle); // Check data is valid if (response.Data is null) { Log.Error(response.ErrorException, "{ApiClient} Got an error [Message={ErrorMessage}]", _clientTitle, response.ErrorMessage); throw new InvalidOperationException(response.ErrorMessage, response.ErrorException); } Log.Debug("{ApiClient} [Response={Response}]", _clientTitle, JsonConvert.SerializeObject(response.Data)); responseObject = response.Data; } // Return response Log.Information("{ApiClient} SMS have been sent [PhoneNo={PhoneNo},Status={Status}, Detail={Detail}, Transaction={Transaction}]", _clientTitle, listOfPhoneNo, responseObject.Status, responseObject.Detail, responseObject.ReferenceHeaderID); return(responseObject); }