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

twitch-toolkit

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twitch-toolkit

A set of tools to integrate with Twitch API, Twitch Chat and Twitch WebHooks.

  • 0.0.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
38
increased by137.5%
Maintainers
1
Weekly downloads
 
Created
Source

twitch-toolkit

License Build Status

A set of tools to integrate with Twitch API, Twitch Chat and Twitch WebHooks.

NPM

To start to use this module, check the project documentation.

Installation

Using npm:

$ npm i --save twitch-toolkit

Usage

The library is composed by three independent modules:

  • API: Provides access to the Helix API.
  • Chat: Provides access to the chat events through tmi.js .
  • WebHook: Provides access to the WebHook topics and events.

The toolkit exports each module and you can access it like this:

const {API, Chat, WebHook} = require('twitch-toolkit');

Every module must be instanced with the required configs as described in the next sessions.

API

The API module must be instanced with the following config object:

NameTypeDescription
client_idstringThe client_id to be used to access the API. This is required.
client_secretstringThe secret to be used to access the API that requires login. If this is not provided, the restricted methods will thrown an error.

Example:

const { API } = require('twitch-toolkit');
const twitchAPI = new API({client_id: 'id-string', client_secret: 'secret-string'})

The API methods are described in the TwitchApi documentation page

Chat

The API module must be instanced with the config objects described in the constructor documentation

Example:

const { Chat } = require('twitch-toolkit');
const twitchChat = new Chat(options)

To connected to the channels with the specified user, you'll need to call the connect function:

twitch.connect()

After that, you'll be able to listen to channel and chat events. You can also disconnect from the chat, if you wish:

twitch.disconnect()

The methods and events are described in the TwitchChatEmitter documentation page

Webhooks

The Twitch Webhooks implementation, as described in https://dev.twitch.tv/docs/api/webhooks-guide/ .

The API module must be instanced with the following config object:

NameTypeDescription
client_idstringThe client ID of the user to be passed to the Hub (un)subscribe requests. This is required.
callbackUrlstringThe 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.
loggerobjectThe logger object.

Example:

const { WebHook } = require('twitch-toolkit');
const twitchWebHook = new WebHook({
            client_id: 'id-string',
            callbackUrl: 'http://domain/path/to/cbUrl'
        });

The Webhook/WebSub requires a public endpoint on the running server/application to receive the data from the hub. Without this, its impossible to make this work.

The methods and events are described in the WebHook documentation page

Tests

The module uses Mocha with Chai for unit tests and Istanbul for test coverage reports.

To run the mocha tests:

$ npm run test

To run tests in debug mode (--inspect-brk)

$ npm run test:debug

To run the tests with the coverage report:

$ npm run test:coverage

To properly run the tests, the following Environment Variables must be set:

Var NameValue
TWITCH_CLIENT_IDThe Client-ID to be used to make the API calls.
TWITCH_CLIENT_SECRETThe Client Secret to be used to make the API calls.
TWITCH_CLIENT_USERNAMEThe Username related to the Client-ID
TWITCH_CLIENT_PASSWORDThe OAUTH password. It can be generated here.

License

Licensed under the MIT License.

Keywords

FAQs

Package last updated on 18 Aug 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