![]() |
VOOZH | about |
dotnet add package TwitchLib.EventSub.Websockets --version 0.8.0
NuGet\Install-Package TwitchLib.EventSub.Websockets -Version 0.8.0
<PackageReference Include="TwitchLib.EventSub.Websockets" Version="0.8.0" />
<PackageVersion Include="TwitchLib.EventSub.Websockets" Version="0.8.0" />Directory.Packages.props
<PackageReference Include="TwitchLib.EventSub.Websockets" />Project file
paket add TwitchLib.EventSub.Websockets --version 0.8.0
#r "nuget: TwitchLib.EventSub.Websockets, 0.8.0"
#:package TwitchLib.EventSub.Websockets@0.8.0
#addin nuget:?package=TwitchLib.EventSub.Websockets&version=0.8.0Install as a Cake Addin
#tool nuget:?package=TwitchLib.EventSub.Websockets&version=0.8.0Install as a Cake Tool
TwitchLib component to connect to Twitch's EventSub service via Websockets also known as EventSockets
EventSub via Websockets is still in open beta. You can use it in production but Twitch may introduce breaking changes without prior notice. The same goes for this implementation until it reaches Version 1.0.0
If you need help on how to setup Dependency Injection in your Console or WPF Application you can have a look at these guides:
You can also find a console app example for .NET 8 and for .NET Framework 4.8 in the repo.
| NuGet | 👁 TwitchLib.EventSub.Websockets |
|
|---|---|---|
| Package Manager | PM> |
Install-Package TwitchLib.EventSub.Websockets -Version 0.6.0 |
| .NET CLI | > |
dotnet add package TwitchLib.EventSub.Websockets --version 0.6.0 |
| PackageReference | <PackageReference Include="TwitchLib.EventSub.Websockets" Version="0.6.0" /> |
|
| Paket CLI | > |
paket add TwitchLib.EventSub.Websockets --version 0.6.0 |
TwitchLib.EventSub.Core Nuget Package, for better management across future EventSub transport Client libraries.
That means their namespace changed from TwitchLib.EventSub.Websockets.Core.EventArgs.* to TwitchLib.EventSub.Core.EventArgs.*.TwitchLib.EventSub.Core package, (namespace changed from TwitchLib.EventSub.Websockets.Core.Models to TwitchLib.EventSub.Core.Models)
but to ensure that the models can be used across projects some changes had to be made:
EventSubNotification<T> were moved to TwitchLibEventSubEventArgs<T>.Notification was removed from TwitchLibEventSubEventArgs<T>.EventSubMetadata was renamed to WebsocketEventSubMetadata.WebsocketDisconnected and WebsocketReconnected now contain more specific EventArgs.Step 1: Create a new project (Console, WPF, ASP.NET)
Step 2: Install the TwitchLib.EventSub.Websockets nuget package. (See above on how to do that)
Step 3: Step 3: Add necessary services and config to the DI Container
services.AddTwitchLibEventSubWebsockets();
services.AddHostedService<WebsocketHostedService>();
(The location of where to put this and the naming of variables might differ depending on what kind of project and general setup you have)
Step 4: Create the HostedService we just added to the DI container and connect to EventSub and listen to Events
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using TwitchLib.Api;
using TwitchLib.Api.Core.Enums;
using TwitchLib.EventSub.Websockets.Core.EventArgs;
using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel;
namespace TwitchLib.EventSub.Websockets.Test
{
public class WebsocketHostedService : IHostedService
{
private readonly ILogger<WebsocketHostedService> _logger;
private readonly EventSubWebsocketClient _eventSubWebsocketClient;
private readonly TwitchApi _twitchApi = new();
private string _userId;
public WebsocketHostedService(ILogger<WebsocketHostedService> logger, EventSubWebsocketClient eventSubWebsocketClient)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_eventSubWebsocketClient = eventSubWebsocketClient ?? throw new ArgumentNullException(nameof(eventSubWebsocketClient));
_eventSubWebsocketClient.WebsocketConnected += OnWebsocketConnected;
_eventSubWebsocketClient.WebsocketDisconnected += OnWebsocketDisconnected;
_eventSubWebsocketClient.WebsocketReconnected += OnWebsocketReconnected;
_eventSubWebsocketClient.ErrorOccurred += OnErrorOccurred;
_eventSubWebsocketClient.ChannelChatMessage += OnChannelChatMessage;
// Get ClientId and ClientSecret by register an Application here: https://dev.twitch.tv/console/apps
// https://dev.twitch.tv/docs/authentication/register-app/
_twitchApi.Settings.ClientId = "YOUR_APP_CLIENT_ID";
// Get Application Token with Client credentials grant flow.
// https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#client-credentials-grant-flow
_twitchApi.Settings.AccessToken = "YOUR_APPLICATION_ACCESS_TOKEN";
// You need the UserID for the User/Channel you want to get Events from.
// You can use await _api.Helix.Users.GetUsersAsync() for that.
_userId = "USER_ID";
}
public async Task StartAsync(CancellationToken cancellationToken)
{
await _eventSubWebsocketClient.ConnectAsync();
}
public async Task StopAsync(CancellationToken cancellationToken)
{
await _eventSubWebsocketClient.DisconnectAsync();
}
private async Task OnWebsocketConnected(object sender, WebsocketConnectedArgs e)
{
_logger.LogInformation($"Websocket {_eventSubWebsocketClient.SessionId} connected!");
if (!e.IsRequestedReconnect)
{
// subscribe to topics
// create condition Dictionary
// You need BOTH broadcaster and moderator values or EventSub returns an Error!
var condition = new Dictionary<string, string> { { "broadcaster_user_id", _userId }, { "user_id", _userId} };
// Create and send EventSubscription
await _twitchApi.Helix.EventSub.CreateEventSubSubscriptionAsync("channel.chat.message", "1", condition, EventSubTransportMethod.Websocket, _eventSubWebsocketClient.SessionId);
// If you want to get Events for special Events you need to additionally add the AccessToken of the ChannelOwner to the request.
// https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/
}
}
private async Task OnWebsocketDisconnected(object sender, WebsocketDisconnectedArgs e)
{
_logger.LogError($"Websocket {_eventSubWebsocketClient.SessionId} disconnected!");
// Don't do this in production. You should implement a better reconnect strategy with exponential backoff
while (!await _eventSubWebsocketClient.ReconnectAsync())
{
_logger.LogError("Websocket reconnect failed!");
await Task.Delay(1000);
}
}
private async Task OnWebsocketReconnected(object sender, WebsocketReconnectedArgs e)
{
_logger.LogWarning($"Websocket {_eventSubWebsocketClient.SessionId} reconnected");
}
private async Task OnErrorOccurred(object sender, ErrorOccuredArgs e)
{
_logger.LogError($"Websocket {_eventSubWebsocketClient.SessionId} - Error occurred!");
}
private async Task OnChannelChatMessage(object? sender, ChannelChatMessageArgs e)
{
_logger.LogInformation($"@{e.Payload.Event.ChatterUserName} #{e.Payload.Event.BroadcasterUserName}: {e.Payload.Event.Message.Text}");
}
}
}
Alternatively you can also just clone the examples:
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 3 NuGet packages that depend on TwitchLib.EventSub.Websockets:
| Package | Downloads |
|---|---|
|
TwitchLib
Twitch C# library for accessing Twitch chat and whispers with events, Twitch API wrapper with every available API endpoint, PubSub wrapper and an Eventsub Websocket implementation |
|
|
Strem.Twitch
Package Description |
|
|
VolcanicArts.VRCOSC.SDK
VRCOSC's SDK for developing VRCOSC modules |
Showing the top 3 popular GitHub repositories that depend on TwitchLib.EventSub.Websockets:
| Repository | Stars |
|---|---|
|
baffler/Transparent-Twitch-Chat-Overlay
Twitch chat on top of windowed games for single monitor streamers
|
|
|
VolcanicArts/VRCOSC
A modular node-programming language, program creator, animation system, toolkit, router, and debugger made for VRChat
|
|
|
songify-rocks/Songify
A simple tool that gets the current track from Spotify, YouTube and Nightbot.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 0.8.0 | 4,548 | 11/22/2025 |
| 0.8.0-preview.89.6e10e27 | 125 | 1/24/2026 |
| 0.8.0-preview.87.3ff8932 | 297 | 11/13/2025 |
| 0.8.0-preview.86.edf4f1c | 274 | 11/13/2025 |
| 0.8.0-preview.85.9f998d3 | 285 | 11/12/2025 |
| 0.7.0 | 4,362 | 9/19/2025 |
| 0.7.0-preview.80.7583c0f | 190 | 9/10/2025 |
| 0.7.0-preview.79.47f9402 | 215 | 8/24/2025 |
| 0.7.0-preview.78.d5d3fa8 | 146 | 8/16/2025 |
| 0.7.0-preview.77.43b8abc | 114 | 8/15/2025 |
| 0.7.0-preview.76.e0eb3c4 | 537 | 7/24/2025 |
| 0.7.0-preview.75.9626728 | 524 | 7/24/2025 |
| 0.7.0-preview.74.00871ba | 518 | 7/24/2025 |
| 0.7.0-preview.73.af00daa | 194 | 7/16/2025 |
| 0.7.0-preview.72.d91d48d | 169 | 7/14/2025 |
| 0.7.0-preview.71.3864955 | 184 | 7/6/2025 |
| 0.7.0-preview.70.cd91499 | 359 | 6/18/2025 |
| 0.6.0 | 4,671 | 6/7/2025 |
| 0.6.0-preview.67.4401bf1 | 122 | 6/7/2025 |
| 0.6.0-preview.66.3e5313f | 125 | 5/31/2025 |
removed INotificationHandler interface, Removed deprecated versions of .NET, All EventSub events were moved to `TwitchLib.EventSub.Core` Nuget Package, Like Events, all EventSub Models were moved to the `TwitchLib.EventSub.Core` package