twitch-helper
v1.1.7
Published
A simple twitch api library that makes it easy to interact with kraken, helix, and other endpoints
Downloads
7
Readme
twitch-helper
This library provides function that make it easy to do things related to the twitch api including but not limited to the helix api, the kraken api, the bttv api, and the ffz api. at its most basic this library wraps twitch api credentials with the fetch function so you don't have to pass them in everytime, but it also has functions that get data from different api endpoints for you with basic inputs.
Support
This project is a part of DisStreamChat. Whether you use this project, another DisStreamChat project, have learned something from it, or just like it, please consider supporting it by becoming a patreon, so we can dedicate more time on more projects like this 😀.
Documentation
basic usage
import TwitchHelper from "twich-helper";
const ApiHelper = new TwitchHelper({
clientId: process.env.client_id,
authorizationKey: process.env.authorization_key
})
const cheerMotes = await ApiHelper.getCheerMotes()
const userInfo = await ApiHelper.getUserInfo("codinggarden")
// do something with the cheermotes and user info
Functions that require authentication
import TwitchHelper from "twich-helper";
const AuthenticatedApiHelper = new TwitchHelper({
clientId: process.env.client_id,
authorizationKey: process.env.authorization_key
})
get moderators for a channel
const moderators = await AuthenticatedApiHelper.getUserModerators("alca")
get user info from helix
// get user info by username
const userInfo = await AuthenticatedApiHelper.getUserInfo("codinggarden");
// get user info by id
const userInfo = await AuthenticatedApiHelper.getUserInfo("413856795");
get user info from kraken
coming soon
get custom channel badges by username
const channelBadges = await AuthenticatedApiHelper.getBadgesByUsername("instafluff");
refresh a refresh token
set the client secret on the helper
const copiedAuthenticatedApiHelper = AuthenticatedApiHelper.copy;
copiedAuthenticatedApiHelper.clientSecret = process.env.client_secret;
const refreshData = await copiedAuthenticatedApiHelper.refreshToken("refresh token");
input the client secret in the function call
const refreshData = await AuthenticatedApiHelper.refreshToken("refresh token", process.env.client_secret);
get cheermotes
// get global cheermotes
const cheermotes = await copiedAuthenticatedApiHelper.getCheerMotes();
// get global cheermotes along with custom channel cheermotes
const customCheermotes = await copiedAuthenticatedApiHelper.getCheerMotes("413856795");
Functions that do not require authentication
import TwitchHelper from "twich-helper";
const UnAuthenticatedApiHelper = new TwitchHelper({});
get channel badges by id
const channelBadges = await UnAuthenticatedApiHelper.getBadgesById("413856795");
get global message badges
const globalBadges = await UnAuthenticatedApiHelper.getGlobalBadges()
get bttv emotes for a channel (includes global bttv emotes)
const {bttvEmotes, bttvRegex} = await UnAuthenticatedApiHelper.getBttvEmotes("codinggarden")
get ffz emotes for a channel (includes global ffz emotes)
const { ffzEmotes, ffzRegex } = await UnAuthenticatedApiHelper.getFfzEmotes("codinggarden")
get the channels a user moderates for
const channelsIModerate = await UnAuthenticatedApiHelper.getUserModerationChannels("dav1dsnyder404")
Contributing
Found a bug? Want a new feature? Don't like the docs? Please create a pull request or raise an issue.
Raising issues
When raising an issue, please add as much details as possible. Screenshots, video recordings, or anything else that can make it easier to reproduce the bug you are reporting.
- A new option is to create a code pen with the code that causes the bug. Fork this example and add your code there, then fork and add the new link to the issue.
Installation
- clone the repo with
git clone https://github.com/DisStreamChat/twitch-helper.git
- cd into the repo with cd twitch-helper
- install dependencies with
npm i
- create a
.env
file and add in the variables from the.env.sample
file - run
npm run build-tests
in order to transpile the typescript and run tests
- run
npm build
to transpile the typescript - run
npm start
to execute the transpiled typescript - run
npm test
to run tests on the transpiled typescript