Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created March 11, 2025 14:58
Show Gist options
  • Save dcomartin/22107f2c3060985f37de90a58dffbe0a to your computer and use it in GitHub Desktop.
Save dcomartin/22107f2c3060985f37de90a58dffbe0a to your computer and use it in GitHub Desktop.
public interface ISmsService
{
public Task Send(string from, string to, string body);
}
public class Twilio : ISmsService
{
public Twilio()
{
TwilioClient.Init("ACCOUNT_SID", "AUTH_TOKEN");
}
public async Task Send(string from, string to, string body)
{
await MessageResource.CreateAsync(
body: body,
from: new PhoneNumber(from),
to: new PhoneNumber(to)
);
}
}
public class EventHandlerExample2
{
private readonly ISmsService _smsService;
private readonly SmsOptions _options;
private readonly GetShipmentContact _getShipmentContact;
public EventHandlerExample2(ISmsService smsService, IOptions<SmsOptions> options, GetShipmentContact getShipmentContact)
{
_smsService = smsService;
_options = options.Value;
_getShipmentContact = getShipmentContact;
}
public async Task Handle(Delivered delivered)
{
var contact = await _getShipmentContact(delivered.ReferenceNumber);
await _smsService.Send(
body: $"{delivered.ReferenceNumber} Package Delivered!",
from: _options.From,
to: contact.PhoneNumber);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment