5MInnov.Tools.WebhookNotification.Ports
1.0.2
dotnet add package 5MInnov.Tools.WebhookNotification.Ports --version 1.0.2
NuGet\Install-Package 5MInnov.Tools.WebhookNotification.Ports -Version 1.0.2
<PackageReference Include="5MInnov.Tools.WebhookNotification.Ports" Version="1.0.2" />
paket add 5MInnov.Tools.WebhookNotification.Ports --version 1.0.2
#r "nuget: 5MInnov.Tools.WebhookNotification.Ports, 1.0.2"
// Install 5MInnov.Tools.WebhookNotification.Ports as a Cake Addin #addin nuget:?package=5MInnov.Tools.WebhookNotification.Ports&version=1.0.2 // Install 5MInnov.Tools.WebhookNotification.Ports as a Cake Tool #tool nuget:?package=5MInnov.Tools.WebhookNotification.Ports&version=1.0.2
5M Innov Webhook Notification Ports
Description
5M Innov Webhook Notification Ports allows you to create your own adapter and use it within 5MInnov.Tools.WebhookNotification.Domain by injecting it.
Prerequisites
- .NET 8.0 or later
Installation
You can install this package via the NuGet Package Manager Console:
Install-Package 5MInnov.Tools.WebhookNotification.Ports
or via the .NET CLI:
dotnet add package 5MInnov.Tools.WebhookNotification.Ports
Example of Use
Here is a basic example :
using _5MInnov.Tools.WebhookNotification.Enums;
using _5MInnov.Tools.WebhookNotification.Ports;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Net.Http.Headers;
namespace CustomWebhook.Adapters
{
// Defines a class for sending notifications to webhooks.
public class CustomWebhookNotification : IWebhookNotification
{
#region Public Properties
// Logger instance for logging errors or critical information.
public readonly ILogger? Logger;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the CustomWebhookNotification class with a logger.
/// </summary>
/// <param name="logger">The logger to use for logging information or errors.</param>
public CustomWebhookNotification(ILogger<CustomWebhookNotification> logger)
{
Logger = logger;
}
#endregion
#region Public Methods
/// <summary>
/// Asynchronously posts a notification message to a webhook.
/// </summary>
/// <param name="webHookUri">The URI of the webhook.</param>
/// <param name="message">The message to post, encapsulated in an IMessage interface.</param>
/// <param name="raiseError">Indicates whether to throw an exception on failure.</param>
/// <returns>A task that represents the asynchronous operation, containing a boolean indicating success or failure.</returns>
public async Task<bool> PostNotificationAsync(Uri webHookUri, IMessage message, bool raiseError)
{
//To implements
}
/// <summary>
/// Overload of PostNotificationAsync that constructs a CustomNotification object from provided parameters and posts it.
/// </summary>
/// <param name="webHookUri">The URI of the webhook.</param>
/// <param name="notificationType">The type of notification.</param>
/// <param name="title">The title of the notification.</param>
/// <param name="message">The message body of the notification.</param>
/// <param name="subject">Optional subject of the notification.</param>
/// <param name="description">Optional description of the notification.</param>
/// <param name="themeColor">Optional theme color of the notification card.</param>
/// <param name="icon">Optional URI of an icon for the notification.</param>
/// <param name="informationLink">Optional URI for more information related to the notification.</param>
/// <param name="raiseError">Indicates whether to throw an exception on failure.</param>
/// <returns>A task that represents the asynchronous operation, containing a boolean indicating success or failure.</returns>
public async Task<bool> PostNotificationAsync(Uri webHookUri, NotificationType notificationType, string title, string message, string? subject = null, string? description = null, string? themeColor = null, Uri? icon = null, Uri? informationLink = null, bool raiseError = false)
{
// Create a notification object and post it
CustomNotification notification = new CustomNotification(notificationType, title, message, subject, description, themeColor, icon, informationLink);
bool result = await PostNotificationAsync(webHookUri, notification, raiseError);
return result;
}
#endregion
}
}
Contributors
License
This project is licensed under 5M Innov.
Other Relevant Information
For any questions or suggestions, please contact mtrezieres@5minnov.fr.
Useful Links
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on 5MInnov.Tools.WebhookNotification.Ports:
Package | Downloads |
---|---|
5MInnov.Tools.WebhookNotification.Domain
Allow to push webhook notification |
|
5MInnov.Tools.WebhookNotification.MicrosoftTeams.Adapters
Microsoft Teams adapter to use with 5MInnov.Tools.WebhookNotification.Domain |
GitHub repositories
This package is not used by any popular GitHub repositories.
Fix webhook settings