private void Validate() { _isValid = true; _smsErrors = new List <SMSError>(); if (string.IsNullOrEmpty(_destinationNumber)) { SMSError smsError = new SMSError() { Code = "0", Message = "Need a number to send the message to.", Status = "0", MoreInfo = "Validation Error" }; _smsErrors.Add(smsError); } if (string.IsNullOrEmpty(_text)) { SMSError smsError = new SMSError() { Code = "0", Message = "Need a text to send.", Status = "0", MoreInfo = "Validation Error" }; _smsErrors.Add(smsError); } _hasBeenValidated = true; _isValid = _smsErrors.Count == 0; }
public void Send(string text, string number) { SMSText = text; DestinationNumber = number; if (IsValid) { try { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; var twilio = new TwilioRestClient(_accountSid, _authToken); var message = twilio.SendMessage(_teamSupportTwilioNumber, DestinationNumber, SMSText); if (message.RestException != null) { SMSError smsError = new SMSError() { Code = message.RestException.Code, Message = message.RestException.Message, Status = message.RestException.Status, MoreInfo = message.RestException.MoreInfo }; _smsErrors.Add(smsError); } else { _messageId = message.Sid; } } catch (Exception ex) { SMSError smsError = new SMSError() { Code = "0", Message = ex.Message, Status = "0", MoreInfo = ex.StackTrace }; _smsErrors.Add(smsError); } } IsSuccessful = SMSErrors.Count == 0 && !string.IsNullOrEmpty(MessageId); }