Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nexmo send SMS
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
You can’t perform that action at this time.