public async Task <IActionResult> SendSMS([FromBody] TextMessage _smsdata) { try { OutboundSMS _SMS = new OutboundSMS(); string response = await _SMS.SendSMSNotification(_smsdata, _iconfiguration); if (response != "failure") { return(Ok(new ServerResponse { HasSucceeded = true, Message = StatusMessages.SuccessMessage })); } else { return(Ok(new OperationResponse { HasSucceeded = false, Message = StatusMessages.FailureMessage, IsDomainValidationErrors = false })); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); return(Ok(new OperationResponse { HasSucceeded = false, Message = StatusMessages.ServerError, IsDomainValidationErrors = false })); } }
public async void ProcessNotification(object message) { try { Amazon.SQS.Model.Message msg = (Amazon.SQS.Model.Message)message; string queMessage = msg.Body; //LogInfo.Information("8 - bsubscription is {" + msg.MessageId + "} object"); SNSSubscription subscription = JsonConvert.DeserializeObject <SNSSubscription>(queMessage); //LogInfo.Information("8 - bsubscription is {" + subscription.MessageId + "} object"); NotificationMessage NotMessage = JsonConvert.DeserializeObject <NotificationMessage>(subscription.Message); //LogInfo.Information("9 - NotMessage is {" + NotMessage.Message +" "+ NotMessage.MessageType + "} object"); // SNSSubscription messageObject= new SNSSubscription { Message=me}; // NotificationMessage notification= JsonConvert.DeserializeObject<NotificationMessage>(messageObject.Message); if (NotMessage.MessageType == NotificationMsgType.Email.GetDescription()) { OutboundEmail _email = new OutboundEmail(); ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration); DatabaseResponse emailTemplate = await _configAccess.GetEmailNotificationTemplate(NotMessage.Message.messagetemplate.ToString()); EmailTemplate template = (EmailTemplate)emailTemplate.Results; var responses = await _email.SendEmail(NotMessage, _iconfiguration, template); foreach (Mandrill.Model.MandrillSendMessageResponse response in responses) { foreach (NotificationParams param in NotMessage.Message.parameters) { if (response.Email == param.emailaddress) { DatabaseResponse notificationLogResponse = await _configAccess.CreateEMailNotificationLog(new NotificationLog { Status = response.Status.ToString() == "Sent" ? 1 : 0, Email = response.Email, EmailTemplateID = template.EmailTemplateID, EmailBody = template.EmailBody, EmailSubject = template.EmailSubject, ScheduledOn = subscription.Timestamp, SendOn = DateTime.Now }); } } } } else if (NotMessage.MessageType == NotificationMsgType.SMS.GetDescription()) { OutboundSMS _SMS = new OutboundSMS(); TextMessage smsData = new TextMessage(); ConfigDataAccess _configAccess = new ConfigDataAccess(_iconfiguration); DatabaseResponse smsTemplate = await _configAccess.GetSMSNotificationTemplate(NotMessage.Message.messagetemplate.ToString()); SMSTemplates template = (SMSTemplates)smsTemplate.Results; foreach (var item in NotMessage.Message.parameters) { smsData.PhoneNumber = item.mobilenumber; smsData.SMSText = template.SMSTemplate.Replace("*|NAME|*", item.name) .Replace("*|PARAM1|*", item.param1) .Replace("*|PARAM2|*", item.param2) .Replace("*|PARAM3|*", item.param3) .Replace("*|PARAM4|*", item.param4) .Replace("*|PARAM5|*", item.param5) .Replace("*|PARAM6|*", item.param6) .Replace("*|PARAM7|*", item.param7) .Replace("*|PARAM8|*", item.param8) .Replace("*|PARAM9|*", item.param9) .Replace("*|PARAM10|*", item.param10); //LogInfo.Information("10 - SendSMS is { "+ smsData+ "}"); string response = await _SMS.SendSMSNotification(smsData, _iconfiguration); await _configAccess.CreateSMSNotificationLog(new SMSNotificationLog() { Email = NotMessage.Message.parameters.Select(x => x.emailaddress).FirstOrDefault(), Mobile = smsData.PhoneNumber, SMSTemplateID = template.SMSTemplateID, SMSText = smsData.SMSText, Status = response != "failure" ? 1 : 0, ScheduledOn = subscription.Timestamp, SendOn = DateTime.Now }); } //LogInfo.Information("10 - SendSMSLog is { " + NotMessage.Message.parameters.Select(x => x.emailaddress).FirstOrDefault() + " " + smsData.PhoneNumber + " "+ response + "}"); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); } }