twitcheasy-twitch-bottwitch-authtwitch-auth-tmitwitch-chat-clienttwitch-eventsubtwitch-pubsub-clienttwitch-webhooks

EventSubListener

A listener for the Twitch EventSub event distribution mechanism.

Overview

Constructor

new EventSubListener(apiClient, adapter, secret, config)

Creates a new EventSub listener.

Parameter Type Required Default Description
apiClient ApiClient none

The ApiClient instance to use for user info and API requests.

adapter ConnectionAdapter none

The connection adapter.

secret string none

The secret for Twitch to sign payloads with.

config EventSubConfig none

Methods

applyMiddleware(app)

async

Applies middleware that handles EventSub notifications to a connect-compatible app (like express).

The express app should be started before this.

Parameter Type Required Default Description
app ConnectCompatibleApp none

The app the middleware should be applied to.

Return type: void

listen(port)

async

Starts the backing server and listens to incoming EventSub notifications.

Parameter Type Required Default Description
port number none none
Return type: void

resumeExistingSubscriptions()

async

Resumes subscriptions that are already registered with Twitch.

Return type: void

subscribeToChannelBanEvents(user, handler)

async

Subscribes to events that represent a user getting banned from a channel.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications for when users get banned in their channel.

handler (event: EventSubChannelBanEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelCheerEvents(user, handler)

async

Subscribes to events that represent a user cheering some bits.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications for about cheers they get.

handler (event: EventSubChannelCheerEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelFollowEvents(user, handler)

async

Subscribes to events that represent a user following a channel.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications about their followers.

handler (event: EventSubChannelFollowEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelHypeTrainBeginEvents(user, handler)

async

Subscribes to events that represent a Hype Train beginning.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications about Hype Trains in their channel.

handler (data: EventSubChannelHypeTrainBeginEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelHypeTrainEndEvents(user, handler)

async

Subscribes to events that represent the end of a Hype Train in a channel.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications about Hype Trains in their channel.

handler (data: EventSubChannelHypeTrainEndEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelHypeTrainProgressEvents(user, handler)

async

Subscribes to events that represent progress in a Hype Train in a channel.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications about Hype Trains in their channel.

handler (data: EventSubChannelHypeTrainProgressEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelRaidEventsFrom(user, handler)

async

Subscribes to events that represent a broadcaster raiding another broadcaster.

Parameter Type Required Default Description
user UserIdResolvable none

The broadcaster for which to get outgoing raid notifications.

handler (event: EventSubChannelRaidEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelRaidEventsTo(user, handler)

async

Subscribes to events that represent a broadcaster being raided by another broadcaster.

Parameter Type Required Default Description
user UserIdResolvable none

The broadcaster for which to get incoming raid notifications.

handler (event: EventSubChannelRaidEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelRedemptionAddEvents(user, handler)

async

Subscribes to events that represents a Channel Points reward being redeemed.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications for when their rewards are redeemed.

handler (data: EventSubChannelRedemptionAddEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelRedemptionAddEventsForReward(user, rewardId, handler)

async

Subscribes to events that represent a specific Channel Points reward being redeemed.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications when their reward is redeemed.

rewardId string none

The ID of the reward for which to get notifications when it is redeemed.

handler (data: EventSubChannelRedemptionAddEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelRedemptionUpdateEvents(user, handler)

async

Subscribes to events that represent a Channel Points reward being updated by a broadcaster.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications for when they update a reward.

handler (data: EventSubChannelRedemptionUpdateEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelRedemptionUpdateEventsForReward(user, rewardId, handler)

async

Subscribes to events that represent a specific Channel Points reward being updated by a broadcaster.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications for when they update the reward.

rewardId string none

The ID of the reward for which to get notifications when it gets updated.

handler (data: EventSubChannelRedemptionUpdateEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelRewardAddEvents(user, handler)

async

Subscribes to events that represent a Channel Points reward being added to a channel.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications for when they add a reward to their channel.

handler (data: EventSubChannelRewardEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelRewardRemoveEvents(user, handler)

async

Subscribes to events that represent a Channel Points reward being removed.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications for when they remove a reward.

handler (data: EventSubChannelRewardEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelRewardRemoveEventsForReward(user, rewardId, handler)

async

Subscribes to events that represent a specific Channel Points reward being removed.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications for when they remove the reward.

rewardId string none

The ID of the reward to get notifications for when it is removed.

handler (data: EventSubChannelRewardEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelRewardUpdateEvents(user, handler)

async

Subscribes to events that represent a Channel Points reward being updated.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications for when they update a reward.

handler (data: EventSubChannelRewardEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelRewardUpdateEventsForReward(user, rewardId, handler)

async

Subscribes to events that represent a specific Channel Points reward being updated.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications for when they update the reward.

rewardId string none

The ID of the reward for which to get notifications when it is updated.

handler (data: EventSubChannelRewardEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelSubscriptionEvents(user, handler)

async

Subscribes to events that represent a user subscribing to a channel.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications for about their subscribers.

handler (event: EventSubChannelSubscriptionEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelUnbanEvents(user, handler)

async

Subscribes to events that represent a user getting unbanned from a channel.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications for when users get unbanned in their channel.

handler (event: EventSubChannelUnbanEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToChannelUpdateEvents(user, handler)

async

Subscribes to events representing a change in channel metadata, e.g. stream title or category.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications about updates.

handler (event: EventSubChannelUpdateEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToStreamOfflineEvents(user, handler)

async

Subscribes to events representing a stream going offline.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications about their streams going offline.

handler (event: EventSubStreamOfflineEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToStreamOnlineEvents(user, handler)

async

Subscribes to events representing a stream going live.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications about their streams going live.

handler (event: EventSubStreamOnlineEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToUserAuthorizationRevokeEvents(clientId, handler)

async

Subscribes to events that represent a user revoking authorization from an application.

Parameter Type Required Default Description
clientId string none

The Client ID for which to get notifications about authorization revocations.

handler (data: EventSubUserAuthorizationRevokeEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

subscribeToUserUpdateEvents(user, handler)

async

Subscribes to events that represent a user updating their account details.

Parameter Type Required Default Description
user UserIdResolvable none

The user for which to get notifications about account updates.

handler (data: EventSubUserUpdateEvent) => void none

The function that will be called for any new notifications.

Return type: EventSubSubscription

unlisten()

async

Stops the backing server, suspending all active subscriptions.

Return type: void