This API server bridges YouTube Music playback status with Slack user status. It provides endpoints for monitoring music playback, updating Slack status, and managing server configuration.
All endpoints (except /) require authentication via a private key that must match the PRIVATE_KEY environment variable.
- GET requests: Include token as URL parameter:
?token=your-private-key - POST requests: Include token in request body:
{"token": "your-private-key"}
SLACK_USER_TOKEN- Slack user token (required, format: xoxp-...)PRIVATE_KEY- Authentication token for API access (required)PORT- Server port (default: 8788)TEMPLATE- Status text template (default: "${title} :: ${artist}")MIN_UPDATE_SECONDS- Minimum seconds between updates (default: 4)
Description: Basic health check endpoint (no auth required)
Response: 404 "ok"
Description: Server health and configuration status Authentication: Required via URL parameter Response:
{
"ok": true,
"port": 8788,
"template": "${title} :: ${artist}",
"minUpdateMs": 4000,
"lastKey": "playing|Song Title :: Artist Name",
"lastSentAt": 1640995200000,
"currentlySetByUs": true,
"authInfo": {
"user": "U1234567890",
"team": "T1234567890"
}
}Description: Send a test status to Slack (expires in 60 seconds) Authentication: Required in request body Request Body:
{
"token": "your-private-key",
"text": "Test Track — Debugger"
}Response:
{
"ok": true,
"text": "Test Track — Debugger"
}Description: Manually set Slack status text Authentication: Required in request body Request Body:
{
"token": "your-private-key",
"text": "Custom status message"
}Clear Status:
{
"token": "your-private-key",
"text": ""
}Response:
{
"ok": true,
"text": "Custom status message"
}Description: Server metrics and usage statistics Authentication: Required via URL parameter Response:
{
"updates": 42,
"clears": 5,
"errors": 1,
"lastUpdate": "2023-12-01T10:30:00.000Z",
"apiActiveTime": 1640995200000,
"startTime": 1640995000000,
"uptime": 200000,
"uptimeFormatted": "200s"
}Metrics Explanation:
updates: Number of successful status updatesclears: Number of times status was clearederrors: Number of failed operationslastUpdate: ISO timestamp of last successful updateapiActiveTime: Timestamp when server became activestartTime: Server start timestampuptime: Server uptime in millisecondsuptimeFormatted: Human-readable uptime
Description: Update server configuration at runtime Authentication: Required in request body Request Body:
{
"token": "your-private-key",
"privateKey": "new-private-key",
"template": "${title} by ${artist}",
"minUpdateSeconds": 5
}Partial Updates (any field is optional):
{
"token": "your-private-key",
"template": "🎵 ${title}"
}Response:
{
"ok": true,
"config": {
"privateKey": "***set***",
"template": "🎵 ${title}",
"minUpdateMs": 5000
}
}Configuration Fields:
privateKey: New authentication tokentemplate: Status text template with${title}and${artist}placeholdersminUpdateSeconds: Minimum delay between status updates
Description: Update status based on current music playback (primary endpoint for userscript) Authentication: Required in request body Request Body:
{
"token": "your-private-key",
"title": "Song Title",
"artist": "Artist Name",
"state": "playing"
}Response (Playing):
{
"ok": true,
"status": "Song Title :: Artist Name"
}Response (Not Playing):
{
"ok": true,
"cleared": true
}Response (Throttled):
{
"ok": true,
"skipped": "dedupe/throttle",
"text": "Song Title :: Artist Name"
}State Values:
playing: Currently playing musicpaused: Music is pausedunknown: Playback state unknown
Behavior:
- Only updates Slack when
stateis "playing" andtitleis provided - Automatically clears status when music stops playing
- Implements throttling to prevent excessive API calls
- Deduplicates identical status updates
Description: Get current playing status Authentication: Required via URL parameter Response (Currently Set):
{
"ok": true,
"status": "Song Title :: Artist Name",
"lastSentAt": 1640995200000,
"currentlySetByUs": true
}Response (Not Set):
{
"ok": true,
"status": null,
"lastSentAt": 1640995200000,
"currentlySetByUs": false
}{
"ok": false,
"error": "Invalid or missing key"
}{
"ok": false,
"error": "Make sure to set a private key"
}{
"ok": false,
"error": "Slack set failed"
}Health Check:
curl "http://localhost:8788/health?token=your-private-key"Set Custom Status:
curl -X POST http://localhost:8788/set \
-H "Content-Type: application/json" \
-d '{"token": "your-private-key", "text": "🎧 Listening to music"}'Update Configuration:
curl -X POST http://localhost:8788/config \
-H "Content-Type: application/json" \
-d '{"token": "your-private-key", "template": "🎵 ${title} by ${artist}"}'View Analytics:
curl "http://localhost:8788/analytics?token=your-private-key"// Update status
const response = await fetch('http://localhost:8788/now-playing', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
token: 'your-private-key',
title: 'Song Title',
artist: 'Artist Name',
state: 'playing'
})
});
const result = await response.json();
console.log(result);- Minimum update interval is configurable via
MIN_UPDATE_SECONDS(default: 4 seconds) - Duplicate status updates are automatically deduplicated
- Status clears are throttled to prevent excessive API calls
- All operations track metrics for monitoring
- Keep your
PRIVATE_KEYsecure and never expose it in client-side code - The API is designed for localhost usage - ensure proper network security if exposed
- Slack user tokens have broad permissions - use dedicated tokens when possible