A library for .NET that converts Twilio SendGrid delivery and engagment events into Azure Event Grid events and publishes them to a topic.
dotnet add package Moosesoft.SendGrid.Azure.EventGrid
Working version of the sample code below is found here. Note: The Azure Event Grid topic configuration settings in the sample are fakes.
public class SendGridEventHandler
{
private readonly IEventGridEventPublisher _eventGridEventPublisher;
public SendGridEventHandler(IEventGridEventPublisher eventGridEventPublisher)
{
_eventGridEventPublisher = eventGridEventPublisher ?? throw new ArgumentNullException(nameof(eventGridEventPublisher));
}
[FunctionName(nameof(HandleSendGridEventsAsync))]
public async Task<IActionResult> HandleSendGridEventsAsync(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest request,
CancellationToken cancellationToken)
{
await _eventGridEventPublisher.PublishEventsAsync(request.Body, cancellationToken).ConfigureAwait(false);
return new OkResult();
}
}