-
-
Save dcomartin/22107f2c3060985f37de90a58dffbe0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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