TwitchLib.EventSub.Webhooks 3.0.0-preview.1.2c180de

This is a prerelease version of TwitchLib.EventSub.Webhooks.
dotnet add package TwitchLib.EventSub.Webhooks --version 3.0.0-preview.1.2c180de
                    
NuGet\Install-Package TwitchLib.EventSub.Webhooks -Version 3.0.0-preview.1.2c180de
                    
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="TwitchLib.EventSub.Webhooks" Version="3.0.0-preview.1.2c180de" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TwitchLib.EventSub.Webhooks" Version="3.0.0-preview.1.2c180de" />
                    
Directory.Packages.props
<PackageReference Include="TwitchLib.EventSub.Webhooks" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TwitchLib.EventSub.Webhooks --version 3.0.0-preview.1.2c180de
                    
#r "nuget: TwitchLib.EventSub.Webhooks, 3.0.0-preview.1.2c180de"
                    
#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.
#:package TwitchLib.EventSub.Webhooks@3.0.0-preview.1.2c180de
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TwitchLib.EventSub.Webhooks&version=3.0.0-preview.1.2c180de&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=TwitchLib.EventSub.Webhooks&version=3.0.0-preview.1.2c180de&prerelease
                    
Install as a Cake Tool

TwitchLib.EventSub.Webhooks

Provides an easy way to setup a Twitch EventSub Webhooks Server

Setting up a Twitch EventSub server can be daunting and has some moving parts that you could get wrong. TwitchLib.EventSub.Webhooks was build with that in mind and makes it as easy as it can get. You only need a few lines of code to add and configure it.

Installation

NuGet TwitchLib.EventSub.Webhooks
Package Manager PM> Install-Package TwitchLib.EventSub.Webhooks -Version 3.0.0
.NET CLI > dotnet add package TwitchLib.EventSub.Webhooks --version 3.0.0
PackageReference <PackageReference Include="TwitchLib.EventSub.Webhooks" Version="3.0.0" />
Paket CLI > paket add TwitchLib.EventSub.Webhooks --version 3.0.0

Breaking Changes in Version 3.0

  • Removed deprecated versions of .NET.
  • Events are now asynchronous (return value changed from void to Task)
  • Events dropped the On prefix (OnChannelChatMessageChannelChatMessage)
  • All EventSub events were moved to TwitchLib.EventSub.Core Nuget Package, for better management across future EventSub transport Client libraries. That means their namespace changed from TwitchLib.EventSub.Webhooks.Core.EventArgs.* to TwitchLib.EventSub.Core.EventArgs.*.
  • Like Events, all EventSub Models were moved to the TwitchLib.EventSub.Core package, (namespace changed from TwitchLib.EventSub.Webhooks.Core.Models to TwitchLib.EventSub.Core.Models) but to ensure that the models can be used across projects some changes had to be made:
    • Notification in TwitchLibEventSubEventArgs<T> were renamed to Payload
    • Headers(Dictionary<string,string>) in TwitchLibEventSubEventArgs<T> were replaced with Metadata(EventSubMetadata) and before you can access the values you have to cast it to WebhookEventSubMetadata
    • EventSubSubscriptionTransport was renamed to EventSubTransport

Breaking Changes in Version 2.0

Version 2.0 contains some breaking changes.

  • Subscription Types and their models were moved to their own shared Nuget Package TwitchLib.EventSub.Core for better management across future EventSub transport Client libraries That means their namespace changed from TwitchLib.EventSub.Webhooks.Core.SubscriptionTypes / TwitchLib.EventSub.Webhooks.Core.Models to TwitchLib.EventSub.Core.SubscriptionTypes / TwitchLib.EventSub.Core.Models
  • Every use of DateTime internally and in models was changed to use DateTimeOffset instead
  • ITwitchEventSubWebhooks / TwitchEventSubWebhooks were renamed to IEventSubWebhooks/ EventSubWebhooks

Disclaimer

The usual requirements that Twitch has for EventSub webhooks do still apply!

  • Your callback url needs to be publicly accessible (localhost wont work!)
  • You need to have SSL on port 443 for the domain used as a callback.

Setup

Step 1: Create a new ASP.NET Core project (.NET 8.0 and up)

Step 2: Install the TwitchLib.EventSub.Webhooks nuget package. (See above on how to do that)

Step 3: Add necessary services and config to the DI Container

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddTwitchLibEventSubWebhooks(config =>
{
    config.CallbackPath = "/eventsub/";
    config.Secret = "supersecuresecret";
});
builder.Services.AddHostedService<EventSubHostedService>();

!!! If you follow these steps your callback url will https://{your_domain}/eventsub/ !!!

Step 4: Put the TwitchLib.EventSub.Webhooks middleware in the request pipeline

var app = builder.Build();

app.UseTwitchLibEventSubWebhooks();

app.Run();

Step 5: Create the HostedService and listen for events

using TwitchLib.EventSub.Core.EventArgs.Channel;
using TwitchLib.EventSub.Webhooks.Core;
using TwitchLib.EventSub.Webhooks.Core.EventArgs;
using TwitchLib.EventSub.Webhooks.Core.Models;

namespace TwitchLib.EventSub.Webhooks.Example
{
    public class EventSubHostedService : IHostedService
    {
        private readonly ILogger<EventSubHostedService> _logger;
        private readonly IEventSubWebhooks _eventSubWebhooks;

        public EventSubHostedService(ILogger<EventSubHostedService> logger, IEventSubWebhooks eventSubWebhooks)
        {
            _logger = logger;
            _eventSubWebhooks = eventSubWebhooks;
        }

        public Task StartAsync(CancellationToken cancellationToken)
        {
            _eventSubWebhooks.OnError += OnError;
            _eventSubWebhooks.UnknownEventSubNotification += OnUnknownEventSubNotification;
            _eventSubWebhooks.ChannelChatMessage += OnChannelChatMessage;
            return Task.CompletedTask;
        }

        public Task StopAsync(CancellationToken cancellationToken)
        {
            _eventSubWebhooks.OnError -= OnError;
            _eventSubWebhooks.UnknownEventSubNotification -= OnUnknownEventSubNotification;
            _eventSubWebhooks.ChannelChatMessage -= OnChannelChatMessage;
            return Task.CompletedTask;
        }

        private async Task OnChannelChatMessage(object? sender, ChannelChatMessageArgs e)
        {
            _logger.LogInformation($"@{e.Payload.Event.ChatterUserName} #{e.Payload.Event.BroadcasterUserName}: {e.Payload.Event.Message.Text}");
        }

        private async Task OnError(object? sender, OnErrorArgs e)
        {
            _logger.LogError($"Reason: {e.Reason} - Message: {e.Message}");
        }

        // Handling notifications that are not (yet) implemented
        private async Task OnUnknownEventSubNotification(object? sender, UnknownEventSubNotificationArgs e)
        {
            var metadata = (WebhookEventSubMetadata)e.Metadata;
            _logger.LogInformation("Received event that has not yet been implemented: type:{type}, version:{version}", metadata.SubscriptionType, metadata.SubscriptionVersion);

            switch ((metadata.SubscriptionType, metadata.SubscriptionVersion))
            {
                case ("channel.chat.message", "1"): /*code to handle the event*/ break;
                default: break;
            }
        }
    }
}

That is all that you need to do to setup a Twitch EventSub Webhook Server with TwitchLib.EventSub.Webhooks. Easy isn't it?

Alternatively you can also just clone the https://github.com/TwitchLib/TwitchLib.EventSub.Webhooks/tree/master/TwitchLib.EventSub.Webhooks.Example

Product 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
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
3.0.0-preview.1.2c180de 69 8/31/2025
2.3.0 9,770 2/12/2023
2.2.0 1,377 11/21/2022
2.1.0 397 11/8/2022
2.0.0 490 10/19/2022
1.3.1 494 9/21/2022
1.3.0 468 8/28/2022
1.2.0 481 8/9/2022
1.1.1 1,109 11/22/2021
1.1.0 427 9/1/2021
1.0.0 413 8/25/2021

Added .NET 8 build target, Updated TwitchLib.EventSub.Core to the latest version to include the latest subscription type changes