Skip to content

socketlabs/SocketLabs.EventWebhooks.Extensions

Repository files navigation

SocketLabs Logo

Build status

SocketLabs.EventWebhooks.Extensions

Library to make consuming SocketLabs webhooks easier.

Getting Started

Prerequisites

  • Visual Studio or VSCode
  • .NET 8

Usage

Import using dotnet CLI or the Package Manager console in Visual Studio

dotnet cli

dotnet add package SocketLabs.EventWebhooks.Extensions

Package Manager

Install-Package SocketLabs.EventWebhooks.Extensions

Event Webhooks

Inject the webhook services

var builder = WebApplication.CreateBuilder(args);

// Code removed for brevity ...

// Add the webhook endpoints
builder.Services.AddWebhookEndpoints(builder.Configuration);

// Add custom implementation of IWebhookEventHandler
builder.Services.AddSingleton<IWebhookEventHandler, WebhookEventHandler>();

Add webhook configuration options

Note

Name can be any string. We've chosen a Guid for this example. The name is used in the endpoint URL you will configure in the portal.

appsettings.json

{
  "WebhookOptions": {
    "WebhookEndpoints": [
      {
        "Name": "cc0b4dc6-d867-49f5-9d8e-8357997789af",
        "SecretKey": "Z123456AbcD1234563Ef"
      }
    ]
  }
}

Configure Endpoint URL in portal

https://example.com/api/v1/webhookevents/cc0b4dc6-d867-49f5-9d8e-8357997789af

Inbound Parse Webhooks

Inject the webhook services

Important

Kestrel's default MaxRequestBodySize is 28.6MB which is smaller then our maximum email message of 50MB

var builder = WebApplication.CreateBuilder(args);

// Code removed for brevity ...

// Add the webhook endpoints
builder.Services.AddInboundParseEndpoints(builder.Configuration);

// Add custom implementation of IParsedMessagesEventHandler
builder.Services.AddSingleton<IParsedMessagesEventHandler, ParsedMessageEventHandler>();

// Increase the max body size.
builder.WebHost.ConfigureKestrel(options =>
{
    options.Limits.MaxRequestBodySize = 50 * 1024 * 1024; //50Mib
});

Add inbound configurations

appsettings.json

{
  "InboundOptions": {
    "InboundEndpoints": [
      {
        "Name": "8c49fad7-7897-4cc7-bbd5-5c26d29dcb7b",
        "SecretKey": "Z123456AbcD1234563Ef"
      }
    ]
  }
}

Configure Endpoint URL in portal

https://example.com/api/v1/parsedmessages/8c49fad7-7897-4cc7-bbd5-5c26d29dcb7b

Release History

  • 1.0.0 Initial Release

License

MIT License

Contributing

Contributor Guidelines