Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

twitch-webhook

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twitch-webhook

A Node JS library for new Twitch Helix API Webhooks

  • 1.2.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-50%
Maintainers
2
Weekly downloads
 
Created
Source

Node.js Twitch Helix Webhooks

Build Status Coverage Status JavaScript Style Guide dependencies Status devDependencies Status Node version Read the Docs (version) https://nodei.co/npm/twitch-webhook.png?downloads=true&downloadRank=true&stars=true

Little Node.js module to interact with new Twitch Helix API Webhooks.

Install

npm install --save twitch-webhook

Usage

Note: Twitch will return old payload for "users/follows" topic if {first: 1} is not specified

const TwitchWebhook = require('twitch-webhook')

const twitchWebhook = new TwitchWebhook({
    client_id: 'Your Twitch Client ID',
    callback: 'Your Callback URL',
    secret: 'It\'s a secret', // default: false
    lease_seconds: 259200,    // default: 864000 (maximum value)
    listen: {
        port: 8080,           // default: 8443
        host: '127.0.0.1',    // default: 0.0.0.0
        autoStart: false      // default: true
    }
})

// set listener for all topics
twitchWebhook.on('*', ({ topic, options, endpoint, event }) => {
    // topic name, for example "streams"
    console.log(topic)
    // topic options, for example "{user_id: 12826}"
    console.log(options)
    // full topic URL, for example
    // "https://api.twitch.tv/helix/streams?user_id=12826"
    console.log(endpoint)
    // topic data, timestamps are automatically converted to Date
    console.log(event)
})

// set listener for topic
twitchWebhook.on('users/follows', ({ event }) => {
    console.log(event)
})

// subscribe to topic
twitchWebhook.subscribe('users/follows', {
    first: 1,
    from_id: 12826 // ID of Twitch Channel ¯\_(ツ)_/¯
})

// renew the subscription when it expires
twitchWebhook.on('unsubscibe', (obj) => {
  twitchWebhook.subscribe(obj['hub.topic'])
})

// tell Twitch that we no longer listen
// otherwise it will try to send events to a down app
process.on('SIGINT', () => {
  // unsubscribe from all topics
  twitchWebhook.unsubscribe('*')

  // or unsubscribe from each one individually
  twitchWebhook.unsubscribe('users/follows', {
    first: 1,
    to_id: 12826
  })

  process.exit(0)
})

Documentation

API Reference

Keywords

FAQs

Package last updated on 13 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc