A modern Twitch chat bot built with Node.js that integrates with Spotify to provide music-related commands and interactive features for stream viewers.
- Spotify Integration
- View current playing song (
!song) - Check queue of upcoming songs (
!queue) - Skip current track (
!skip) - Request songs via chat (
!songrequest)
- View current playing song (
- Interactive Commands
- Built-in mini-game access (
!game) - Help command to list available features (
!commands)
- Built-in mini-game access (
- Robust Architecture
- Automatic token refresh and validation
- PostgreSQL for secure environment variable storage
- WebSocket-based real-time chat interaction
- Dockerized deployment support
- Backend: Node.js
- Database: PostgreSQL
- APIs:
- Twitch EventSub WebSocket API
- Spotify Web API
- Authentication: OAuth2 flow for both Twitch and Spotify
- Deployment: Docker support with Node 18
The bot consists of three main components:
- TwitchBot: Handles WebSocket connections, chat commands, and message routing
- TokenGenerator: Manages OAuth2 authentication flow and token refresh
- Postgres: Secures environment variables and authentication tokens
- Secure token management with database storage
- Automatic token refresh handling
- Environment variable isolation
- No hardcoded credentials
!song- Display currently playing track!queue- Show next 5 songs in queue!skip- Skip the current song!songrequest- Request a song (e.g., 'the days by notion')!game- Get a link to a custom web game!commands- List all available commands
The application includes a Dockerfile for easy deployment and containerization, using the node:18-slim base image for optimal performance and size.
- Automatic WebSocket reconnection on timeout
- Token revalidation and refresh system
- Graceful error handling and recovery