-
-
Save dcomartin/a9f94f953194ca1264bec734d3998b8f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 class SendSmsWhenDelivered | |
| { | |
| private readonly GetShipmentContact _getShipmentContact; | |
| private readonly SmsOptions _options; | |
| public SendSmsWhenDelivered(IOptions<SmsOptions> options, GetShipmentContact getShipmentContact) | |
| { | |
| _getShipmentContact = getShipmentContact; | |
| _options = options.Value; | |
| } | |
| public async Task Handle(Delivered delivered) | |
| { | |
| var contact = await _getShipmentContact(delivered.ReferenceNumber); | |
| await MessageResource.CreateAsync( | |
| body: $"{delivered.ReferenceNumber} Package Delivered!", | |
| from: new PhoneNumber(_options.From), | |
| to: new PhoneNumber(contact.PhoneNumber) | |
| ); | |
| } | |
| } | |
| public class SendEmailWhenDelivered | |
| { | |
| private readonly GetShipmentContact _getShipmentContact; | |
| private readonly SendGridClient _sendGridClient; | |
| private readonly EmailOptions _options; | |
| public SendEmailWhenDelivered(IOptions<EmailOptions> options, GetShipmentContact getShipmentContact, SendGridClient sendGridClient) | |
| { | |
| _getShipmentContact = getShipmentContact; | |
| _sendGridClient = sendGridClient; | |
| _options = options.Value; | |
| } | |
| public async Task Handle(Delivered delivered) | |
| { | |
| var contact = await _getShipmentContact(delivered.ReferenceNumber); | |
| var from = new EmailAddress(_options.From); | |
| var subject = $"{delivered.ReferenceNumber} Package Delivered!"; | |
| var to = new EmailAddress(contact.Email); | |
| var plainTextContent = ""; | |
| var htmlContent = ""; | |
| var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent); | |
| await _sendGridClient.SendEmailAsync(msg); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment