DeltaCore.SMSService
1.1.0
dotnet add package DeltaCore.SMSService --version 1.1.0
NuGet\Install-Package DeltaCore.SMSService -Version 1.1.0
<PackageReference Include="DeltaCore.SMSService" Version="1.1.0" />
<PackageVersion Include="DeltaCore.SMSService" Version="1.1.0" />
<PackageReference Include="DeltaCore.SMSService" />
paket add DeltaCore.SMSService --version 1.1.0
#r "nuget: DeltaCore.SMSService, 1.1.0"
#:package DeltaCore.SMSService@1.1.0
#addin nuget:?package=DeltaCore.SMSService&version=1.1.0
#tool nuget:?package=DeltaCore.SMSService&version=1.1.0
SMSService
DeltaCore.SMSService
Overview 📚
DeltaCore.SMSService is a lightweight .NET 8 library that simplifies sending and verifying OTPs via SMS or call using Twilio Verify API, and sending custom messages using Twilio Messaging API.
It also includes a simple throttling mechanism to prevent sending OTPs within 60 seconds to the same number.
✅ Send OTPs via SMS or call
✅ Verify OTPs easily
✅ Send custom text messages
✅ Prevent spamming (resending OTP within 60 seconds)
✅ Built-in error handling and logging
Install from NuGet 📦
You can install the package from NuGet:
dotnet add package DeltaCore.SMSService
or via the Package Manager Console:
Install-Package DeltaCore.SMSService
Using in Your App 🚀
- Configure TwilioSettings
In your
appsettings.json, add:
{
"TwilioSettings": {
"AccountSID": "your_account_sid",
"AuthToken": "your_auth_token",
"TwilioPhoneNumber": "your_twilio_phone_number",
"VerifyServiceSID": "your_verify_service_sid"
}
}
- Register the Service in
Startup.csorProgram.cs
builder.Services.Configure<TwilioSettings>(builder.Configuration.GetSection("TwilioSettings"));
builder.Services.AddSingleton<ISMSService, TwilioService>();
- Using
ISMSServicein Your Application Inject ISMSService where needed, for example in a controller or service:
public class AccountController : ControllerBase
{
private readonly ISMSService _smsService;
public AccountController(ISMSService smsService)
{
_smsService = smsService;
}
[HttpPost("send-otp")]
public async Task<IActionResult> SendOtp(string phoneNumber)
{
var verificationSid = await _smsService.SendOTPAsync(phoneNumber);
if (verificationSid == null)
return BadRequest("OTP was sent recently. Please wait.");
return Ok(new { verificationSid });
}
[HttpPost("verify-otp")]
public async Task<IActionResult> VerifyOtp(string phoneNumber, string code)
{
var isValid = await _smsService.VerifyOTPAsync(phoneNumber, code);
if (!isValid)
return BadRequest("Invalid or expired OTP.");
return Ok("OTP verified successfully.");
}
[HttpPost("send-message")]
public async Task<IActionResult> SendMessage(string phoneNumber, string message)
{
var isSent = await _smsService.SendMessageAsync(phoneNumber, message);
if (!isSent)
return BadRequest("Failed to send message.");
return Ok("Message sent successfully.");
}
}
Important Notes 📝
OTP requests are rate-limited: the same number cannot request a new OTP within 60 seconds.
Errors during sending/verification are logged using ILogger.
Supports both SMS and voice calls when sending OTPs by specifying the channel parameter.
License 🛡️
This project is licensed under the MIT License.
Support
If you encounter any issues or have questions about using DeltaCore.SMSService, feel free to create an issue on GitHub or reach out to us.
Author
👤 Ahmed Nady
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Options (>= 9.0.4)
- Twilio (>= 7.10.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.