musiclink/README.md

2.4 KiB

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 a Matrix-native bot that connects directly to a Matrix homeserver and replies in the originating room/thread. E2EE rooms are not supported.

  • Connectivity: Connects directly to Matrix and supports multiple allowlisted rooms.
  • 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.24 or higher
  • A Matrix homeserver and bot access token

Building

go build -o musiclink ./cmd/musiclink

Configuration

  1. Copy the example configuration:

    cp config.example.toml config.toml
    
  2. Configure Matrix-native mode (replies in the originating room/thread; E2EE rooms not supported):

    [matrix]
    shadow = false # set true to log-only during validation
    healthAddr = "127.0.0.1:8080" # optional health/metrics endpoint
    server = "https://matrix.example.com"
    accessToken = "your-matrix-access-token"
    userId = "@musiclink:example.com"
    rooms = ["!roomid:example.com"]
    stateStorePath = "data/matrix-state.db"
    

    Note: MusicLink reads configuration from the TOML file only. For production, prefer generating the config from a secrets manager or Nix module to avoid environment-variable leaks.

Running

./musiclink -config config.toml

Health and Metrics (Matrix-native)

If matrix.healthAddr is set, MusicLink exposes JSON health stats at /healthz (and /metrics). The address must bind to localhost (e.g., 127.0.0.1:8080). Example:

curl http://127.0.0.1:8080/healthz

Testing

The project includes both unit tests and integration tests.

Run All Tests

go test ./...

Integration Tests

No Matrix integration tests are included yet; add them as needed.

Smoke Test

A manual smoke test script is available in cmd/smoketest (requires network access to the idonthavespotify API):

go run cmd/smoketest/main.go

License

MIT