TwitchWebhook

TwitchWebhook

TwitchWebhook The Twitch Webhooks implementation, as described in https://dev.twitch.tv/docs/api/webhooks-guide/ . The Webhook requires a public endpoint on the running express server/application to receive the data from the hub. Without this, its impossible to make this work.

Constructor

new TwitchWebhook(config)

Source:
Parameters:
Name Type Description
config object

The config object.

Name Type Description
clientId string

The client ID of the user to be passed to the Hub (un)subscribe requests. This is required.

callbackUrl string

The callback URL that will receive the Hub requests. These requests should be forwarded to the handleRequest method to properly handle these data. This is required.

logger object

The logger object.

Methods

destroy()

Destroy the Webhook, unsubscribing every active subscription.

Source:

handleRequest(method, headers, qs, body) → {object}

This method will handle the request data and validate the subscriptions or properly emit the events with the received data.

Source:
Parameters:
Name Type Description
method string

The http method

headers Array.<string>

The headers array

qs Array.<string>

The request query string array. Used for GET and POST

body Array.<string>

The POST body. Used just for post.

Returns:
Type:
object

The response result object with the status and data to be sent in the response.

subscribe(topic, eventName) → {string}

Subscribe to a specific topic that will fires an event when new data is received from the hub. The event handler will receive the data object and the subscription ID.

Source:
Parameters:
Name Type Description
topic string

The topic name/URL.

eventName string

The event name that will be fired when new data is received.

Returns:
Type:
string

The subscription ID, used to identify the active topic.

topicStreamUpDownSubscribe(streamUserId) → {string}

Notifies when a stream goes online or offline. The response mimics the Get Streams endpoint. (https://dev.twitch.tv/docs/api/reference/#get-streams)

Source:
Parameters:
Name Type Description
streamUserId number

The ID of the user whose stream is monitored.

Fires:
Returns:
Type:
string

The subscription ID, used to identify the active topic.

topicUserFollowsSubscribe(fromId, toId) → {string}

Notifies when a follows event occurs. The response mimics the Get Users Follows endpoint. (https://dev.twitch.tv/docs/api/reference/#get-users-follows)

Source:
Parameters:
Name Type Description
fromId number

The ID of the user who starts following someone.

toId number

The ID of the user who has a new follower.

Fires:
Returns:
Type:
string

The subscription ID, used to identify the active topic.

unsubscribe(id)

Unsubscribe from a topic by its ID.

Source:
Parameters:
Name Type Description
id string

The subscription ID.

Events

Webhook:stream_up_down

Stream Up/Down Event

Source:
Parameters:
Name Type Description
data object

The data object received from the Hub.

id string

The subscription ID.

Webhook:user_follows

Stream User Follows Event

Source:
Parameters:
Name Type Description
data object

The data object received from the Hub.

id string

The subscription ID.