Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
{
private readonly RestClient _client;
private readonly IConfiguration _configuration;
public SMSService(IConfiguration configuration)
{
_configuration = configuration;
_client = new RestClient(configuration["SMSApi:Url"]);
}
public async Task<SMSResponse> SendSms(string phoneNumber, string textMessage)
{
var controlId = GenerateControlId();
// Create the XML structure as per the example
var requestBody = new XElement("request",
new XElement("head",
new XElement("operation", "submit"),
new XElement("login", _configuration["SMSApi:Username"]), // Use dynamic username
new XElement("password", _configuration["SMSApi:Password"]), // Use dynamic password
new XElement("title", "Smart Elect"), // Dynamic sender name
new XElement("bulkmessage", textMessage), // Set text message
new XElement("scheduled", "now"), // Always set to "now"
new XElement("isbulk", "false"), // Always set to "false"
new XElement("controlid", controlId) // Unique controlId
),
new XElement("body",
new XElement("msisdn", phoneNumber), // Set phone number
new XElement("message", textMessage) // Set message
)
);
var request = new RestRequest();
request.AddHeader("Content-Type", "application/xml");
request.AddParameter("application/xml", requestBody.ToString(), ParameterType.RequestBody);
RestResponse response = await _client.ExecuteAsync(request, Method.Post);
if (!response.IsSuccessful)
{
throw new Exception($"Failed to send SMS. Status code: {response.StatusCode}, Message: {response.ErrorMessage}");
}
var responseData = XDocument.Parse(response.Content);
var responseCode = responseData.Root.Element("head").Element("responsecode").Value;
if (responseCode == "000")
{
return new SMSResponse
{
Message = "SMS sent successfully",
TransId = responseData.Root.Element("body").Element("taskid").Value
};
}
else
{
return new SMSResponse
{
Message = "Failed to send SMS",
ErrorCode = responseCode
};
}
}
private string GenerateControlId()
{
var ticks = DateTime.Now.Ticks;
var random = new Random();
var randomNumber = random.Next(1000, 9999);
return $"{ticks}{randomNumber}"; // Unique controlid as numbers
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team