- Fixed a panic in internal/bot/bot.go where a repeated read was attempted on a failed websocket connection. - Removed the 5-second read deadline and timeout handling in readLoop. - Added connection closure on ping failure to trigger quick reconnection. - Added NixOS module to flake.nix for service deployment. |
||
|---|---|---|
| cmd | ||
| docs | ||
| internal | ||
| pkg/config | ||
| .gitignore | ||
| config.example.toml | ||
| flake.lock | ||
| flake.nix | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| README.md | ||
MusicLink Bot
MusicLink is a Go-based chat bot that automatically detects music links (Spotify, Apple Music, YouTube, etc.) and responds with links to the same song on other streaming platforms. It solves the "I don't have Spotify" problem in group chats.
Architecture
MusicLink is designed to work as a sidecar to Matterbridge.
- Connectivity: Connects to Matterbridge via its WebSocket API. This allows MusicLink to support any chat platform Matterbridge supports (Discord, Slack, Telegram, Matrix, IRC, etc.).
- Resolution: Uses the idonthavespotify API to convert links between services without requiring individual API keys.
- Privacy: Does not store messages or user data. It only processes messages containing music links.
Getting Started
Prerequisites
- Go 1.22 or higher
- A running instance of Matterbridge (if running in production)
Building
go build -o musiclink ./cmd/musiclink
Configuration
-
Copy the example configuration:
cp config.example.toml config.toml -
Edit
config.tomlto match your Matterbridge WebSocket settings:[matterbridge] url = "ws://localhost:4242/api/websocket" token = "your-matterbridge-api-token" gateway = "main" # The gateway name defined in your matterbridge.toml username = "MusicLink"
Running
./musiclink -config config.toml
Testing
The project includes both unit tests and integration tests.
Run All Tests
go test ./...
Integration Tests
The integration tests (in internal/bot/bot_integration_test.go) mock both the Matterbridge WebSocket server and the music resolution API. This allows you to verify the bot's full logic flow without external dependencies.
go test -v internal/bot/bot_integration_test.go
Smoke Test
A manual smoke test script is available in cmd/smoketest:
go run cmd/smoketest/main.go