Skip to content

Commit

Permalink
Documentation and license headers
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutomi committed Apr 30, 2023
1 parent e65f72f commit 9df2495
Show file tree
Hide file tree
Showing 78 changed files with 1,435 additions and 64 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ The libraries currently provided by the framework are the following:
| **Deveel.Webhooks.DynamicLinq** | The webhook subscription filtering engine that uses the [Dynamic LINQ](https://dynamic-linq.net/) expressions | [![Nuget](https://img.shields.io/nuget/v/Deveel.Webhooks.DynamicLinq?label=NuGet&logo=nuget)](https://www.nuget.org/packages/Deveel.Webhooks.DynamicLinq) | [![GitHub](https://img.shields.io/static/v1?label=GitHub&message=preview&color=yellow&logo=github)](https://github.com/deveel/deveel.webhooks/pkgs/nuget/Deveel.Webhooks.DynamicLinq) |
| **Deveel.Webhooks.Receiver.AspNetCore** | An implementation of the webhook receiver that is backed by [ASP.NET Core](https://dotnet.microsoft.com/apps/aspnet) | [![Nuget](https://img.shields.io/nuget/v/Deveel.Webhooks.Receiver.AspNetCore?label=NuGet&logo=nuget)](https://www.nuget.org/packages/Deveel.Webhooks.Receiver.AspNetCore) | [![GitHub](https://img.shields.io/static/v1?label=GitHub&message=preview&color=yellow&logo=github)](https://github.com/deveel/deveel.webhooks/pkgs/nuget/Deveel.Webhooks.Receiver.AspNetCore) |

The following libraries extend the framework with receivers for specific providers:

| Library | Description | NuGet | GitHub (prerelease) |
| ----------------------------------------| ---------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------- |---------------------|
| **Deveel.Webhooks.Receiver.Twilio** | An implementation of the webhook receiver that is backed by [Twilio](https://twilio.com) SMS and WhatsApp messages | [![Nuget](https://img.shields.io/nuget/v/Deveel.Webhooks.Receiver.Twilio?label=NuGet&logo=nuget)](https://www.nuget.org/packages/Deveel.Webhooks.Receiver.Twilio) | [![GitHub](https://img.shields.io/static/v1?label=GitHub&message=preview&color=yellow&logo=github)](https://github.com/deveel/deveel.webhooks/pkgs/nuget/Deveel.Webhooks.Receiver.Twilio) |
| **Deveel.Webhooks.Receiver.SendGrid** | An implementation of the webhook and email receiver that is backed by [SendGrid](https://sendgrid.com) email messages | [![Nuget](https://img.shields.io/nuget/v/Deveel.Webhooks.Receiver.SendGrid?label=NuGet&logo=nuget)](https://www.nuget.org/packages/Deveel.Webhooks.Receiver.SendGrid) | [![GitHub](https://img.shields.io/static/v1?label=GitHub&message=preview&color=yellow&logo=github)](https://github.com/deveel/deveel.webhooks/pkgs/nuget/Deveel.Webhooks.Receiver.SendGrid) |
| **Deveel.Webhooks.Receiver.Facebook** | An implementation of the webhook receiver that is backed by [Facebook](https://facebook.com) Messenger messages | [![Nuget](https://img.shields.io/nuget/v/Deveel.Webhooks.Receiver.Facebook?label=NuGet&logo=nuget)](https://www.nuget.org/packages/Deveel.Webhooks.Receiver.Facebook) | [![GitHub](https://img.shields.io/static/v1?label=GitHub&message=preview&color=yellow&logo=github)](https://github.com/deveel/deveel.webhooks/pkgs/nuget/Deveel.Webhooks.Receiver.Facebook) |

You can obtain the stable versions of these libraries from the [NuGet Official](https://nuget.org) channel.

To get the latest pre-release versions of the packages you can restore from the [Deveel Package Manager](https://github.com/orgs/deveel/packages).
Expand Down
36 changes: 26 additions & 10 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Here you can find a documentation of the `Deveel Webhooks` framework, to help yo

## Basic Concepts

To set the domain model of the framework, we need to introduce some basic concepts that are used in the framework.

| Topic | Description |
| ---------------------------------------------------- | ------------------------------------------ |
| **[Webhook](concept_webhook.md)** | What is it a 'Webhook' and why I need it? |
Expand All @@ -29,21 +31,35 @@ Here you can find a documentation of the `Deveel Webhooks` framework, to help yo
| **[Receivers](concept_webhook_receiver.md)** | What is a receiver of webooks? |
| **[Notifications](concept_webhook_notification.md)** | What is a notification of events? |

## Tutorials
## Basic Usage

The following tutorials will guide you through the basic usage of the framework, showing how to use the different components to send, receive and manage webhooks.

| Topic | Description |
| ---------------------------------------------------------------------- | --------------------------------------------------------------------- |
| **[Getting Started](getting_started.md)** | Getting started with `Deveel Webhooks` |
| **[Basic Usage - Sending Webhooks](basic_usage_send.md)** | Manually sending webhooks (no subscriptions) |
| **[Basic Usage - Subscription Management](basic_usage_management.md)** | Manage subscriptions to events (no sending) |
| **[Basic Usage - Notify Webhooks](basic_usage_notify.md)** | Notify webhooks subscribers (management, transformations and sending) |
| **[Basic Usage - Receiving Webhooks](basic_usage_receive.md)** | Receive webhooks from external sources |
| **[Sending Webhooks](basic_usage_send.md)** | Manually sending webhooks (no subscriptions) |
| **[Subscription Management](basic_usage_management.md)** | Manage subscriptions to events (no sending) |
| **[Notify Webhooks](basic_usage_notify.md)** | Notify webhooks subscribers (management, transformations and sending) |
| **[Receiving Webhooks](basic_usage_receive.md)** | Receive webhooks from external sources |

## Advanced Usage

## Extending
A more advanced usage of the framework is possible by implementing custom components that can be used to extend the framework functionalities.

| Topic | Description |
| ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| **[Advanced Usage - Filtering Subscriptions](advanced_usage_filters.md)** | Allow subscribers to filter webhooks on dynamic parameters |
| **[Advanced Usage - Custom Data Factories](advanced_usage_custom_datafactory.md)** | Implement a component that transforms event data |
| **[Advanced Usage - Custom Receivers](advanced_usage_custom_receiver.md)** | Implement parsers for receiving webhooks |
| **[Advanced Usage - Using Data Layers](advanced_usage_data_layer.md)** | Use different data layers for the persistence of the webhook information model |
| **[Filtering Subscriptions](advanced_usage_filters.md)** | Allow subscribers to filter webhooks on dynamic parameters |
| **[Custom Data Factories](advanced_usage_custom_datafactory.md)** | Implement a component that transforms event data |
| **[Custom Receivers](advanced_usage_custom_receiver.md)** | Implement parsers for receiving webhooks |
| **[Using Data Layers](advanced_usage_data_layer.md)** | Use different data layers for the persistence of the webhook information model |

## Receivers

The framework provides a set of libraries that can be used to receive webhooks from external sources.

| Receiver | Description |
| -------- | ----------- |
| **[Facebook](facebook_receiver.md)** | Receive webhooks from Facebook Messenger |
| **[SendGrid](sendgrid_receiver.md)** | Receive webhooks and emails from SendGrid |
| **[Twilio](twilio_receiver.md)** | Receive webhooks and SMS/WhatsApp messages from Twilio |
93 changes: 93 additions & 0 deletions docs/sendgrid_receiver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# SendGrid Webhook and E-Mail Receiver

The framework provides a set of configurations and extensions to support the capabilities for receiving and processing SendGrid webhooks and e-mails.

## Installation

You can install the package from NuGet, running the following command in the console:

```bash
dotnet add package Deveel.Webhooks.Receiver.SendGrid
```

## Configuration

### Receiving Webhooks

To activate the SendGrid receiver you don't need many cerimonies or configurations, just add the following line to the `ConfigureServices` method of your `Startup` class (assuming you are using a classic ASP.NET Core application):

```csharp
public void ConfigureServices(IServiceCollection services) {
// ...
services.AddSendGridReceiver()
.AddHandler<SendGridWebhookHandler>();
// ...
}
```

The above line will register the required services and configurations to the DI container, using the default configurations, so that the receiver can be used in the application.

If you need to customize directly the configurations, you can use the following overload of the `AddSendGridReceiver` method:

```csharp
public void ConfigureServices(IServiceCollection services) {
// ...
services.AddSendGridReceiver(options => {
options.VerifySignatures = true;
options.Secret = "my-secret";
});
// ...
}
```

If your configurations reside in a configuration section of the `appsettings.json` file, you can use the following overload:

```csharp
public void ConfigureServices(IServiceCollection services) {
// ...
services.AddSendGridReceiver("Webhooks:SendGrid")
.AddHandler<SendGridWebhookHandler>();
// ...
}
```

_Note: the above overload will use the `Webhooks:SendGrid` section of the configuration file to load the configurations, but any can be used_

### Receiving E-Mails

SendGrid and other providers of e-mail services support the capability to forward e-mails to a specific endpoint, so that the application can process them, using alternative methods than the classic SMTP protocol.

By nature, these HTTP requests are not considered as webhooks, but they are still HTTP requests that can be processed by the framework: in fact the receiver library provides a specific handler that can be used to process e-mails.

Since thes e-mails are not following the practices of webhooks, the receiver will not validate the signature of the request, but it will process it as it is, requiring no additional configurations.

To activate the e-mail receiver, you can use the following overload of the `AddSendGridEmailReceiver` method:

```csharp
public void ConfigureServices(IServiceCollection services) {
// ...
services.AddSendGridEmailReceiver("/email/sendgrid")
.AddHandler<SendGridEmailHandler>();
// ...
}
```


## Mapping Webhook Events

To map the events received from SendGrid to the handlers provided by the framework, you can use the `MapSendGridWebhook` and `MapSendGridEmail` extension methods of the `IApplicationBuilder` contract:

```csharp
public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
// ...
app.MapSendGridWebhook("/webhook/sendgrid");
app.MapSendGridEmail("/email/sendgrid");

app.MapSendGridWebhook("/webhook/sendgrid/handled", webhook => {});

app.MapSendGridEmail("/email/sendgrid/handled", email => {});
// ...
}
```

The framework will bind the incoming webhooks and emails to instances of the `SendGridWebhook` and `SendGridEmail` classes, that can be used to process the data received from the provider.
4 changes: 4 additions & 0 deletions docs/twilio_receiver.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Then, you need to configure the receiver in the `Configure` method of the `Start
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
// ...
app.MapTwilioWebhook("/twilio/webhook");

app.MapTwilioWebhook("/twilio/other", webhook => {
// ...
});
// ...
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@
<ProjectReference Include="..\Deveel.Webhooks.Receiver.SendGrid\Deveel.Webhooks.Receiver.SendGrid.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\apl-2.licenseheader" Link="apl-2.licenseheader" />
</ItemGroup>
</Project>
14 changes: 14 additions & 0 deletions src/Deveel.Webhooks.Receiver.SendGrid.XUnit/Usings.cs
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
// Copyright 2022-2023 Deveel
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

global using Xunit;
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using System.Reflection.Metadata;
// Copyright 2022-2023 Deveel
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Reflection.Metadata;
using System.Text;

using Deveel.Webhooks.SendGrid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using Deveel.Webhooks.SendGrid;
// Copyright 2022-2023 Deveel
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Deveel.Webhooks.SendGrid;

using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using System;
// Copyright 2022-2023 Deveel
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using System.Diagnostics.CodeAnalysis;
// Copyright 2022-2023 Deveel
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Diagnostics.CodeAnalysis;

using Deveel.Webhooks.SendGrid;

Expand Down
Loading

0 comments on commit 9df2495

Please sign in to comment.