private TwilioSmsCredentials GetCredentials(ISiteSettings site) { if (site == null) { return(null); } if (string.IsNullOrEmpty(site.SmsClientId)) { return(null); } if (string.IsNullOrEmpty(site.SmsSecureToken)) { return(null); } if (string.IsNullOrEmpty(site.SmsFrom)) { return(null); } TwilioSmsCredentials creds = new TwilioSmsCredentials(); creds.AccountSid = site.SmsClientId; creds.AuthToken = site.SmsSecureToken; creds.FromNumber = site.SmsFrom; return(creds); }
private async Task <bool> SendMessage( TwilioSmsCredentials credentials, string toPhoneNumber, string message) { if (string.IsNullOrWhiteSpace(toPhoneNumber)) { throw new ArgumentException(nameof(toPhoneNumber)); } if (string.IsNullOrWhiteSpace(message)) { throw new ArgumentException(nameof(message)); } var client = _clientFactory.GetHttpClient(); client.DefaultRequestHeaders.Authorization = CreateBasicAuthenticationHeader( credentials.AccountSid, credentials.AuthToken); // https://api.twilio.com/2010-04-01/Accounts/{0}/Messages // /2010-04-01/Accounts/{AccountSid}/Messages // To // From // Body var keyValues = new List <KeyValuePair <string, string> >(); keyValues.Add(new KeyValuePair <string, string>("To", toPhoneNumber)); keyValues.Add(new KeyValuePair <string, string>("From", credentials.FromNumber)); keyValues.Add(new KeyValuePair <string, string>("Body", message)); var content = new FormUrlEncodedContent(keyValues); var postUrl = string.Format( CultureInfo.InvariantCulture, TwilioSmsEndpointFormat, credentials.AccountSid); var response = await client.PostAsync( postUrl, content).ConfigureAwait(false); var xxx = await response.Content.ReadAsStringAsync().ConfigureAwait(false); if (response.IsSuccessStatusCode) { return(true); } else { return(false); } }
public SmsAuthenticationOptions() { Message = "The confirmation code is {0}"; TwilioSmsCredentials = new TwilioSmsCredentials(); }
public SmsAuthenticationOptions() { Message = "The confirmation code is {0}"; TwilioSmsCredentials = new TwilioSmsCredentials(); IsSelfProvisioningEnabled = false; }