Curiosus.Notifications.SMS
SMS channel for Curiosus.Notifications.
It sends SmsNotifications through the ISmsSender registered in the container (smsc.ru, iqsms.ru, ...).
Installation
dotnet add package Curiosus.Notifications.SMS
Usage
Register an SMS sender, the channel and a builder that turns your metadata into SMS:
services.AddSmscSmsSender(smscOptions); // any ISmsSender implementation
services.AddCuriosusSmsChannel(); // also registers INotificator
services.AddCuriosusNotificationBuilder<LoginCodeSmsBuilder>();
public class LoginCodeRequested : INotificationMetadata
{
public string Phone { get; init; } = null!;
public string Code { get; init; } = null!;
}
public class LoginCodeSmsBuilder : SmsNotificationBuilderBase<LoginCodeRequested>
{
protected override Task<IReadOnlyList<INotification>> BuildNotificationsAsync(
LoginCodeRequested metadata,
CancellationToken cancellationToken = default)
{
var sms = new SmsNotification(metadata.Phone, $"Your code: {metadata.Code}");
return Task.FromResult<IReadOnlyList<INotification>>(new[] { sms });
}
}
await notificator.NotifyAsync(new LoginCodeRequested { Phone = "+71234567890", Code = "1234" }, cancellationToken);
The channel type is SmsNotification.Type (curiosus.notifications.sms). Sender errors are thrown as
NotificationException with a mapped NotificationErrorCode (Auth, Communication, RateLimit, NoMoney,
DeliveryError, Unknown). Provider-specific options (e.g. other credentials) can be passed as ISmsExtraParams
in the SmsNotification constructor.
To act on every sending result (e.g. store SmsSentResult.Cost), implement ISmsNotificationPostProcessor
and register it with services.AddSmsNotificationPostProcessor<MyPostProcessor>().
See also
- Curiosus.Notifications — notificator and base classes
- Curiosus.SMS —
ISmsSenderabstraction; providers: Curiosus.SMS.Smsc, Curiosus.SMS.Iqsms - SMS notifications documentation
- Curiosus.Utils — all packages