Created
August 26, 2014 13:45
-
-
Save ReubenBond/c8406be708057c3bb14e to your computer and use it in GitHub Desktop.
Nexmo send SMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task SendSms(string phoneNumber, string body) | |
{ | |
// Sanitize the phone number. | |
phoneNumber = Regex.Replace(phoneNumber, "[^0-9]", string.Empty); | |
// Build the request. | |
var builder = new UriBuilder("https://rest.nexmo.com/sms/json"); | |
var parameters = new Dictionary<string, string> | |
{ | |
{ "api_key", this.apiKey }, | |
{ "api_secret", this.apiSecret }, | |
{ "from", this.smsSenderName }, | |
{ "to", phoneNumber }, | |
{ "text", body } | |
}; | |
builder.Query = string.Join("&", parameters.Select(_ => string.Format("{0}={1}", HttpUtility.UrlEncode(_.Key), HttpUtility.UrlEncode(_.Value)))); | |
// Send the request and log the result. | |
var request = builder.Uri; | |
var result = await this.webClient.DownloadStringTaskAsync(request); | |
this.log.Info("{0} -> {1}", request, result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment