TraceLd.DiscordWebhook 1.0.4

dotnet add package TraceLd.DiscordWebhook --version 1.0.4
NuGet\Install-Package TraceLd.DiscordWebhook -Version 1.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TraceLd.DiscordWebhook" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TraceLd.DiscordWebhook --version 1.0.4
#r "nuget: TraceLd.DiscordWebhook, 1.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TraceLd.DiscordWebhook as a Cake Addin
#addin nuget:?package=TraceLd.DiscordWebhook&version=1.0.4

// Install TraceLd.DiscordWebhook as a Cake Tool
#tool nuget:?package=TraceLd.DiscordWebhook&version=1.0.4

DiscordWebhook

Actions Status nuget

Extremely simple and lightweight library for hooking up a Discord webhook meant to be used with ASP.NET Core or the Generic Host.

Usage example

The following example will use ASP.NET Core but the setup is almost identical with the Generic Host.

  1. Add WebhookSettings as a singleton. Where it comes from is up to you - it can be config files, environment variables etc. In this simple example we will use appsettings.json. (It is not the most secure option as the credentials are stored in plaintext, but it's very simple).
  • Add the following section to appsettings.json and fill it in with your credentials:
"WebhookSettings": {
    "Id": 0000000,
    "Token": "token"
}
  • Add the following code to the ConfigureServices method in Startup.cs:
services.Configure<WebhookSettings>(Configuration.GetSection(nameof(WebhookSettings)));
services.AddSingleton(provider => provider.GetRequiredService<IOptions<WebhookSettings>>().Value);
  1. Add IWebhookService:
  • Add the following code to Startup.cs below the previously added code:
services.AddHttpClient<IWebhookService, WebhookService>();
  1. Now you can use the webhook service in your own services, for example:
  • Create the service:
public interface IHelloService
{
    Task SendHelloAsync();
}

public class HelloService : IHelloService
{
    private readonly ILogger<HelloService> _logger;
    private readonly IWebhookService _webhookService;

    public HelloService(ILogger<HelloService> logger, IWebhookService webhookService)
    {
        _logger = logger;
        _webhookService = webhookService;
    }

    public async Task SendHelloAsync()
    {
        await _webhookService.ExecuteWebhookAsync("Hello from C#");
    }
}
  • Add the service in Startup.cs (below the previous code):
services.AddScoped<IHelloService, HelloService>();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 633 8/4/2020
1.0.3 246 8/4/2020
1.0.2 244 8/4/2020
1.0.1 408 8/4/2020