twitch-webhook
Advanced tools
Comparing version 1.2.2 to 1.2.4
@@ -28,2 +28,3 @@ const TwitchWebhook = require('twitch-webhook') | ||
twitchWebhook.subscribe('users/follows', { | ||
first: 1, | ||
to_id: '12826' // ID of Twitch Chanell ¯\_(ツ)_/¯ | ||
@@ -30,0 +31,0 @@ }) |
{ | ||
"name": "twitch-webhook", | ||
"version": "1.2.2", | ||
"version": "1.2.4", | ||
"description": "A Node JS library for new Twitch Helix API Webhooks", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -22,2 +22,5 @@ # Node.js Twitch Helix Webhooks | ||
_**Note**: Twitch will return old payload for "users/follows" topic | ||
if `{first: 1}` is not specified_ | ||
```js | ||
@@ -31,3 +34,3 @@ const TwitchWebhook = require('twitch-webhook') | ||
lease_seconds: 259200, // default: 864000 (maximum value) | ||
listen: { | ||
listen: { | ||
port: 8080, // default: 8443 | ||
@@ -41,10 +44,10 @@ host: '127.0.0.1', // default: 0.0.0.0 | ||
twitchWebhook.on('*', ({ topic, options, endpoint, event }) => { | ||
// topic name, for example "stream" | ||
// topic name, for example "streams" | ||
console.log(topic) | ||
// topic options, for example "{user_id: 12826}" | ||
console.log(options) | ||
// full topic URL, for example | ||
// full topic URL, for example | ||
// "https://api.twitch.tv/helix/streams?user_id=12826" | ||
console.log(endpoint) | ||
// topic data | ||
// topic data, timestamps are automatically converted to Date | ||
console.log(event) | ||
@@ -60,2 +63,3 @@ }) | ||
twitchWebhook.subscribe('users/follows', { | ||
first: 1, | ||
from_id: 12826 // ID of Twitch Channel ¯\_(ツ)_/¯ | ||
@@ -65,3 +69,3 @@ }) | ||
// renew the subscription when it expires | ||
twitchWebhook.on('unsubscibe', (obj) => { | ||
twitchWebhook.on('unsubscibe', (obj) => { | ||
twitchWebhook.subscribe(obj['hub.topic']) | ||
@@ -78,2 +82,3 @@ }) | ||
twitchWebhook.unsubscribe('users/follows', { | ||
first: 1, | ||
to_id: 12826 | ||
@@ -88,2 +93,2 @@ }) | ||
<a href="https://true-dubach.github.io/node-twitch-webhook">API Reference</a> | ||
[API Reference](https://true-dubach.github.io/node-twitch-webhook) |
@@ -278,3 +278,9 @@ const errors = require('./errors') | ||
case 'users/follows': | ||
data.timestamp = new Date(data.timestamp) | ||
if (data.timestamp) { // for compatibility with old payloads | ||
data.timestamp = new Date(data.timestamp) | ||
} else { | ||
for (let follow of data.data) { | ||
follow.followed_at = new Date(follow.followed_at) | ||
} | ||
} | ||
break | ||
@@ -281,0 +287,0 @@ case 'streams': |
@@ -609,3 +609,3 @@ const TwitchWebhook = require('../src/index') | ||
describe('date fix', () => { | ||
it('should fix "timestamp" field in "users/follows" topic', (done) => { | ||
it('should fix "timestamp" field in old "users/follows" topic', (done) => { | ||
twitchWebhook.once('users/follows', ({event}) => { | ||
@@ -628,2 +628,26 @@ assert(event.timestamp instanceof Date) | ||
it('should fix "followed_at" field in "users/follows" topic', (done) => { | ||
twitchWebhook.once('users/follows', ({event}) => { | ||
for (let follow of event.data) { | ||
assert(follow['followed_at'] instanceof Date) | ||
} | ||
done() | ||
}) | ||
helpers.sendRequest({ | ||
url: `http://127.0.0.1:${webhookPort}`, | ||
method: 'POST', | ||
headers: { | ||
link: '<https://api.twitch.tv/helix/users/follows?to_id=1337>; rel="self"' | ||
}, | ||
json: { | ||
data: [{ | ||
'followed_at': '2017-12-01T10:09:45Z' | ||
}, { | ||
'followed_at': '2017-12-02T11:49:47Z' | ||
}] | ||
} | ||
}) | ||
}) | ||
it('should fix "started_at" fields in "streams" topic', (done) => { | ||
@@ -630,0 +654,0 @@ twitchWebhook.once('streams', ({event}) => { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47130
1250
88