Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@binaryfissiongames/twitch-webhooks
Advanced tools
Library to abstract subscribing to the documented Twitch webhook API endpoints, with persistence in mind.
Library for subscribing to Twitch webhooks.
Run the command
npm i @binaryfissiongames/twitch-webhooks
while in your project directory.
import {TwitchWebhookManager} from "@binaryfissiongames/twitch-webhooks";
import express = require("express");
const app = express();
//Setup
let webhookManager: TwitchWebhookManager = new TwitchWebhookManager({
hostname: process.env.HOST_NAME, //Hostname for the server this is hosted on
app: app, // Express application
client_id: process.env.CLIENT_ID, // Twitch Client ID
base_path: 'webhooks', // base path to use on the express application for webhook endpoints
getOAuthToken: getOAuthToken, // Async function to get OAuthToken from user ID
refreshOAuthToken: refreshToken, // Function to refresh OAuth token from said OAuth token
secret: 'supersecret' //If omitted, a cryptographically random secret will be generated
});
//setup message handler
webhook.on('message', (webhookId: WebhookId, msg: WebhookPayload<any>) => {
console.log(`Got message: ${msg.type} for webhook ${webhookId}, ${JSON.stringify(msg)}`);
});
//Set up error handler
webhook.on('error', (e) => console.error(e))
app.listen(8080).then(() => {
//Subscribe to some endpoints
let webhookId = await webhookManager.addUserFollowsSubscription({
leaseSeconds: 6000, // Can be up to 864000 (default, 10 days),
secret: 'thisiswebhookspecificsecret' //If omitted, the webhook manager secret is used.
}, {to_id: "1002"});
/* Code goes here */
await webhookManager.unsubscribe(webhookId);
//OR
await webhookManager.unsubFromAll();
//Destroy all owned resources (timers, persistence manager, renewal scheduler)
//Note: As of writing this, this manager may still receive messages after destruction,
//depending on the persistence manager implementation, AND if the underlying http(s) server is not closed.
await webhookManager.destroy();
});
A specific persistence implementation is defined through the TwitchWebhookPersistenceManager
(see persistence.ts
) interface.
An instance of an implementation may be provided to the TwitchWebhookManager
's constructor as the persistenceManager
property.
In the case that NO such persistence manager is provided - a default, IN-MEMORY persistence manager is used. This means data about your
webhooks will not persist between restarts, and could lead to twitch attempting to contact a down server
if the server shuts down without properly unsubscribing from endpoints.
Rescheduling is defined through the WebhookRenewalScheduler
interface (see scheduling.ts
).
If no scheduler is provided during construction of the TwitchWebhookManager
as the renewalScheduler
property,
then webhooks WILL NOT be renewed. A simple, default implementation is provided with the library,
(see BasicWebhookRenewalScheduler
in scheduling.ts
). This implementation will attempt to renew a webhook
after 85% of it's time from start to expiry has occurred. Smarter logic can be substituted by implementing
the WebhookRenewalScheduler
interface.
TODO:
FAQs
Library to abstract subscribing to the documented Twitch webhook API endpoints, with persistence in mind.
The npm package @binaryfissiongames/twitch-webhooks receives a total of 0 weekly downloads. As such, @binaryfissiongames/twitch-webhooks popularity was classified as not popular.
We found that @binaryfissiongames/twitch-webhooks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.