This repository contains a Node.js application designed to integrate with Twitch's EventSub system for receiving real-time notifications about Twitch events, such as when a streamer goes live. It uses Twitch API to manage subscriptions and notifies a Discord channel using webhooks when a streamer starts broadcasting.
- Twitch OAuth2 authentication for secure API requests.
- Subscription management to Twitch EventSub for receiving streamer events.
- Real-time notifications to a Discord channel when a streamer goes live.
- Secure handling of Twitch webhook callbacks with signature verification.
- HTTPS server setup for receiving Twitch webhook callbacks.
Before you start, ensure you have the following:
- Node.js installed on your machine.
- A Twitch account with a registered application to obtain your
Client IDandClient Secret. - A Discord account with a server and channel where you want to receive notifications, and the ability to create a webhook in that channel.
-
Environment Variables: Set up your
.envfile with the necessary credentials and paths:DISCORD_WEBHOOK=<Your Discord Webhook URL> TWITCH_CLIENT_ID=<Your Twitch Client ID> TWITCH_CLIENT_SECRET=<Your Twitch Client Secret> PORT=<Server Port, default is 443> HOOK_SECRET=<Your Secret for Twitch Hook Verification> SSL_KEY_PATH=<Path to SSL Key> SSL_CERT_PATH=<Path to SSL Certificate> CALLBACK_URL=<Your Public Callback URL for Twitch Webhooks>
-
SSL Certificate: For local development, you can use tools like
mkcertto generate a local SSL certificate and key. -
Streamers List: Add the streamers you want to follow in the
streamers.jsonfile in the following format:[ { "streamer_name": "example_streamer", "going_live_message": "Example Streamer is now live!" } ]
-
Install dependencies:
npm install
-
Start the server:
npm start
The server will start, and it will automatically create subscriptions for the streamers listed in streamers.json. When one of these streamers goes live, a notification will be sent to the configured Discord channel.
The application listens for POST requests on the root path (/). It verifies the signature of incoming requests to ensure they are from Twitch, handles subscription verification challenges, and processes notifications about stream events.
- Always keep your Twitch
Client Secretand DiscordWebhook URLprivate. - Use a secure
HOOK_SECRETfor verifying the integrity of incoming webhook events. - Ensure your
CALLBACK_URLis served over HTTPS.
Contributions are welcome! Please feel free to submit a pull request or create an issue for any bugs or feature requests.
This project is open-source and available under the MIT License.