gtmoose32 / sendgrid-azure-eventgrid

A library for .NET that converts Twilio SendGrid web hook events into EventGrid events and publishes them.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Moosesoft.SendGrid.Azure.EventGrid

Build status nuget Nuget

What is it?

A library for .NET that converts Twilio SendGrid delivery and engagment events into Azure Event Grid events and publishes them to a topic.

Installing Moosesoft.SendGrid.Azure.EventGrid

dotnet add package Moosesoft.SendGrid.Azure.EventGrid

Azure Function Sample

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();
    }
}

About

A library for .NET that converts Twilio SendGrid web hook events into EventGrid events and publishes them.

License:MIT License


Languages

Language:C# 100.0%