Thursday, January 11, 2024

How to send SMS in C# using Unifonic

 How to send SMS in C# using Unifonic?


        public static async Task UniFonicSendConfirmVisitSMSAsync(string mobile)
{ try { using (var httpClient = new HttpClient()) { var url = "https://el.cloud.unifonic.com/rest/SMS/messages"; var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("AppSid", "******************"), new KeyValuePair<string, string>("SenderID", "xxx"), new KeyValuePair<string, string>("Body", "xxxxxxxxxxxxxxxxxxxxxx"), new KeyValuePair<string, string>("Recipient", mobile), new KeyValuePair<string, string>("responseType", "JSON"), new KeyValuePair<string, string>("CorrelationID", UniqueID), new KeyValuePair<string, string>("baseEncode", "true"), new KeyValuePair<string, string>("MessageType", "6"), new KeyValuePair<string, string>("statusCallback", "sent"), new KeyValuePair<string, string>("async", "false") }); var response = await httpClient.PostAsync(url, formContent); if (response.IsSuccessStatusCode) { Console.WriteLine("SMS sent successfully."); } else { Console.WriteLine("Failed to send SMS."); } } } catch { // $"Please enter a valid phone number. Current Phone number is {patient.mobile}."; } }

No comments: