public override async Task <SystemNotification> SendAsync(string receiver, string message, string subject) { var completed = true; if (string.IsNullOrEmpty(receiver)) { return(SystemNotification.InvalidOperation); } var service = new RahyabSmsService(Username, Password, SenderNumber); foreach (var phone in receiver.Split(new[] { ",", ";", " " }, StringSplitOptions.RemoveEmptyEntries)) { var cellphone = CellphoneNumber.Normalize(phone); try { if (cellphone == null) { throw new Exception($"Invalid Phone: {phone}"); } await service.SendSmsAsync(cellphone.PhoneNumber, subject.CleanText() + "\n\n" + message.CleanText()); Logger.Info($"SMS Sent successfully to: {cellphone.PhoneNumber}"); } catch (Exception ex) { Logger.Fatal(ex, $"Send SMS failed for sending message to {phone}"); completed = false; } } return(completed ? SystemNotification.SuccessfullyDone : SystemNotification.InternalError); }
public static CellphoneNumber Normalize(string number) { CellphoneNumber cellphone; try { cellphone = new CellphoneNumber(number); } catch (Exception exp) { Logger.Warn($"Invalid send SMS request received. {exp.Message}"); return(null); } return(cellphone); }