https://github.com/alextibtab/twitch-streaming-tool
https://github.com/alextibtab/twitch-streaming-tool
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/alextibtab/twitch-streaming-tool
- Owner: Alextibtab
- Created: 2025-03-02T15:57:31.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-08T03:17:30.000Z (over 1 year ago)
- Last Synced: 2025-06-20T21:16:25.646Z (about 1 year ago)
- Language: TypeScript
- Size: 38.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Twitch Tool
A real-time Twitch integration tool that listens for channel point redemptions and broadcasts them via WebSockets to connected clients. Built with Deno, Oak, and Twurple.
## Features
- π Real-time channel point redemption notifications
- π WebSocket server for client connections
- π Secure EventSub integration with Twitch
- π Local development with ngrok tunneling
- π Comprehensive logging
## Project Structure
```
twitch-tool/
βββ src/
β βββγapi/
β β βββ middleware.ts
β β βββ routes.ts
β β βββ server.ts
β βββγauth/ # Twitch Authentication
β β βββ twitch.ts
β βββγchat/ # Chatbot setup
β β βββ commands/
β β β βββ chess.ts
β β β βββ mod.ts
β β βββ bot.ts
β β βββ events.ts
β βββ config/ # Configuration
β β βββ config.ts
β βββ eventsub/ # Twitch EventSub integration
β β βββ handler.ts
β β βββ setup.ts
β βββ websocket/ # WebSocket server
β β βββ server.ts
β βββ utils/ # Utility functions
β β βββ context.ts
β β βββ utils.ts
β βββ app.ts # Main application entry point
βββ .env # Environment variables (not in repo)
βββ deno.json # Deno configuration
βββ README.md # Project documentation
```
## How It Works
1. **EventSub Integration**: The application uses Twitch's EventSub system to receive real-time notifications about channel point redemptions.
2. **Ngrok Tunneling**: For local development, ngrok creates a public URL that Twitch can use to send webhook notifications.
3. **WebSocket Broadcasting**: When a channel point is redeemed, the event is broadcast to all connected WebSocket clients.
4. **Oak Web Server**: Handles HTTP requests and serves the WebSocket connections.
## Setup
### Prerequisites
- [Deno](https://deno.land/) installed
- [Twitch Developer Account](https://dev.twitch.tv/)
- [Ngrok Account](https://ngrok.com/)
### Environment Variables
Create a `.env` file with the following variables:
```
TWITCH_CLIENT_ID=your_client_id
TWITCH_CLIENT_SECRET=your_client_secret
TWITCH_ACCESS_TOKEN=your_access_token
TWITCH_CHANNEL_NAME=your_channel_name
TWITCH_EVENTSUB_SECRET=your_eventsub_secret
NGROK_AUTH_TOKEN=your_ngrok_auth_token
PORT=8000
```
### Running the Application
```bash
# Start the application
deno run --allow-net --allow-env --allow-read src/app.ts
# Test EventSub integration
deno run --allow-net --allow-env --allow-read src/test-eventsub.ts
```
## Technical Details
### EventSub Handler
The EventSub handler uses Twurple's `EventSubHttpListener` with an `NgrokAdapter` to receive webhook notifications from Twitch. When a channel point is redeemed, the handler processes the event and broadcasts it to all connected WebSocket clients.
### WebSocket Server
The WebSocket server uses Oak's WebSocket implementation to handle client connections. It provides a simple interface for broadcasting messages to all connected clients.
### Configuration
The application uses environment variables for configuration, which are loaded and validated at startup.
## Client Integration
To connect to the WebSocket server from a client:
```javascript
const ws = new WebSocket('ws://localhost:8000/ws');
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.type === 'reward_redeemed') {
console.log(`${data.data.userName} redeemed ${data.data.rewardTitle}`);
}
};
```
## Development
### Testing
To test if the EventSub integration is working:
1. Run the test script: `deno run --allow-net --allow-env --allow-read src/test-eventsub.ts`
2. Go to your Twitch channel and redeem a channel point reward
3. Check the console for logs indicating the event was received
## License
[MIT License](LICENSE)