This library aims to provide easy way in sending sms
using mnotify sms gateway , etc.. in your .netcore >= 3.1
applications.
-
Dashboard - Resend failed SMS Message.
- SMS
eazy-sms
repository is work in progress...
- Install-Package eazy-sms
AddEazySms(Configuration)
& UseEazySmsUI(Configuration)
which accepts IConfiguration object must be injected in ConfigureServices
and Configure
method in the Startup
class.
ConfigureServices
//ConfigureServices Method.
public void ConfigureServices(IServiceCollection services)
{
services.AddEazySms(Configuration);
}
// Configure Method.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseEazySmsUI(Configuration);;
}
Once you have configured the
AddEazySms()
andUseEazySms
middleware in the Program.cs file, you're ready to define theEazyOptions
in theapp.settings.json
.
"EazyOptions": {
"SMS": {
"Enable": true,
"Database": {
"Persist": true,
"Name": "CacheSMS",
"Instance": "DESKTOP-6BR1LOC",
"UserName": "sa",
"Password": "root",
"Encrypt": "False",
"TrustedConnection": "False",
"TrustServerCertificate": "True"
},
"ApiKey": "4n4uhOxPhvTeesTlC3ef7jLCGX5mLEIU1MpiAW8Ss16GtZ",
"ApiSecret": "",
"From": "Melteck"
}
}
- Options
Enable
-- Enable SMS option. which takes either a true or fale.Database
-- Enabled by default. SMS are been stored in a database table before they are sent to the recepient.ApiKey
-- unique api key.ApiSecret
-- unique api secret. Not required by other providers.From
-- Name of the server. visit provider for senderId or Name.
Every notification class has a Boot
method for building the notification message and
each notification is represented by a single class and stored in the Notifications
directory.
public class AccountCreatedNotifiable : Notifiable<AccountDto>
{
protected override void Boot()
{
//logic...
From("Melteck")
.Subject("Account Created")
.Recipient(new[]
{
"0276002658",
"0553771219"
}
)
//.Content(new Content("message body}"))
.Schedule(false, "2021-04-08 06:00")
.Attach(new Attachment {File = "ringtone.mp3"})
.Template("AccountRegistration.txt", "pass dto to a template")
.Channel(SMSChannel.Mnotify);
}
}
- Available Methods that can be used in the
boot method
of every notification class.
From
- sender name or sender IdSubject
- message titleRecipient
- an array of number to recieve the sms messageSchedule
- accept the state & a date[YYY-MM-DD h:mm]
for scheduling sms.Content
- body of the messageAttach
- voice file (path:wwwroot/Template/Voice
).Template
- template name (path :wwwroot/Template
)Channel
- specifying delivery channels
The NotifyAsync
method that is provided by INotification
interface expects to
receive a notification instance.
In other to use the NotifyAsync
method you need to inject the INotification
interface in your contructor.
public class RegistrationController : ControllerBase
{
private readonly INotification _notification;
public RegistrationController(INotification notification)
{
_notification = notification;
}
[HttpGet("Register")]
public async Task<IActionResult> Register()
{
//Create new user
var accountUser = new AccountDto {Username = "Michael Ameyaw"};
//removed for brevity....
//call this after creating user to send email
await _notification.NotifyAsync(new AccountCreatedNotifiable(accountUser));
return Ok("Message has been processed");
}
}
Note that
NotifyAsync
does not return an response