Node.js Twitch Helix Webhooks
Installation
Install with NPM:
npm install --save twitch-webhook
Usage
const TwitchWebhook = require('twitch-webhook');
const twitchWebhook = new TwitchWebhook({
client_id: 'Your Twitch Client ID',
callback: 'Your Callback URL'
secret: 'It\'s a secret'
})
twitchWebhook.on('streams', (obj) => {
console.log(obj);
});
twitchWebhook.on('users/follows', (obj) => {
console.log(obj);
})
twitchWebhook.on('*', (obj) => {
console.log(obj);
})
twitchWebhook.subscribe('users/follows',{
from_id: 'User id'
});
twitchWebhook.subscribe('streams',{
user_id: 'User id'
});
Documentation
TwitchWebhook
TwitchWebHookAPI
Kind: global class
new TwitchWebhook(options)
Constructs an instance of TwitchWebHookAPI
Param | Type | Default | Description |
---|
options | Object | | Options |
options.client_id | string | | Client ID required for Twitch API calls |
options.callback | string | | URL where notifications will be delivered. |
[options.secret] | string | | Secret used to sign notification payloads. |
[options.lease_seconds] | number | | Number of seconds until the subscription expires. |
[options.listen] | boolean | Object | | Listen options |
[options.listen.autoStart] | string | false | Should automaticaly starts listening |
[options.listen.host] | string | ""0.0.0.0"" | Host to bind to |
[options.listen.port] | number | 8443 | Port to bind to |
[options.https] | boolean | Object | false | Should use https connection. If yes, these options to be passed to https.createServer() . |
[options.baseApiUrl] | string | ""https://api.twitch.tv/helix/\"" | Base Twitch API URL. It needs for proxying and testing |
TwitchWebhook.errors
Returns errors
Kind: instance property of TwitchWebhook
TwitchWebhook.listen([...args]) ⇒ Promise
Start listening for connections
Kind: instance method of TwitchWebhook
Param | Type | Description |
---|
[...args] | any | Arguments |
TwitchWebhook.close() ⇒ Promise
Stop listening for connections
Kind: instance method of TwitchWebhook
TwitchWebhook.isListening() ⇒ boolean
Checks if server is listening for connections.
Kind: instance method of TwitchWebhook
TwitchWebhook.subscribe(topic, options)
Subscribes to specific topic
Kind: instance method of TwitchWebhook
Param | Type | Description |
---|
topic | string | Topic name |
options | Object | Topic options |
TwitchWebhook.unsubscribe(topic)
Unsubscribes from specific topic
Kind: instance method of TwitchWebhook
Param | Type | Description |
---|
topic | string | Topic name |