Spotify Control via AI Chatbot
Control Spotify playback through your AI bot. Play music, manage queues, and control speakers via Telegram or Discord.
Overview
Control your Spotify playback through chat commands. Ask your AI bot to play music, skip tracks, adjust volume, or queue songs - all through Telegram or Discord messages.
What You Can Do
- Play music: "Play some jazz"
- Artist requests: "Put on The Beatles"
- Mood-based: "Play something relaxing"
- Control playback: "Skip this track" / "Pause"
- Volume: "Turn it down a bit"
- Queue management: "Add this to my queue"
- Device control: "Play on the living room speaker"
Prerequisites
- Spotify Premium account (required for API control)
- VPS running OpenClaw
- Spotify Developer account
Setup Guide
Step 1: Create Spotify App
- Go to developer.spotify.com/dashboard
- Click "Create App"
- Fill in details:
- Name: "AI Music Bot"
- Redirect URI:
http://localhost:8888/callback
- Save Client ID and Client Secret
Step 2: Authorize Your Account
Run authorization flow once:
# Install Spotify auth helper
npm install spotify-web-api-node
# Run auth script
node spotify-auth.js
// spotify-auth.js
const SpotifyWebApi = require('spotify-web-api-node');
const spotifyApi = new SpotifyWebApi({
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
redirectUri: 'http://localhost:8888/callback'
});
// Generate auth URL
const scopes = [
'user-read-playback-state',
'user-modify-playback-state',
'user-read-currently-playing'
];
const authUrl = spotifyApi.createAuthorizeURL(scopes, 'state');
console.log('Open this URL:', authUrl);
// After authorization, get tokens from callback URL
Step 3: Configure Bot
# Spotify Integration
SPOTIFY_ENABLED=true
SPOTIFY_CLIENT_ID=your-client-id
SPOTIFY_CLIENT_SECRET=your-client-secret
SPOTIFY_REFRESH_TOKEN=your-refresh-token
Step 4: Test Connection
You: "What's playing right now?"
Bot: "Currently playing: 'Bohemian Rhapsody' by Queen on Living Room Speaker"
Usage Examples
Basic Playback
You: "Play some music" Bot: "Starting playback. Now playing: Your Daily Mix 1"
You: "Pause" Bot: "Paused βΈοΈ"
You: "Resume" Bot: "Playing βΆοΈ"
Artist and Song Requests
You: "Play Daft Punk" Bot: "Playing 'Daft Punk' - Starting with 'Get Lucky'"
You: "Play 'Stairway to Heaven'" Bot: "Now playing: 'Stairway to Heaven' by Led Zeppelin πΈ"
Mood-Based Selection
You: "I need some focus music" Bot: "Starting 'Deep Focus' playlist - instrumental tracks for concentration π―"
You: "Play something upbeat for my workout" Bot: "Starting 'Beast Mode' playlist - high energy workout tracks πͺ"
Device Control
You: "What speakers are available?" Bot: "Available devices:
- Living Room (Sonos) - Active
- Bedroom (Echo Dot)
- Office (MacBook)"
You: "Play on the bedroom speaker" Bot: "Switched playback to Bedroom speaker π"
Queue Management
You: "Add 'Hotel California' to the queue" Bot: "Added 'Hotel California' by Eagles to your queue β"
You: "What's coming up next?" Bot: "Queue:
- Hotel California - Eagles
- Dream On - Aerosmith
- Sweet Child O' Mine - Guns N' Roses"
Volume Control
You: "Turn it up" Bot: "Volume increased to 70% π"
You: "Set volume to 40%" Bot: "Volume set to 40%"
Advanced Features
Smart Playlists
Context-aware music selection:
SPOTIFY_SMART_PLAYLISTS="
morning=37i9dQZF1DWWQRwui0ExPn # Morning motivation
focus=37i9dQZF1DWZeKCadgRdKQ # Deep focus
dinner=37i9dQZF1DX4xuWVBs4FgJ # Dinner jazz
workout=37i9dQZF1DX76Wlfdnj7AP # Beast mode
sleep=37i9dQZF1DWZd79rJ6a7lp # Sleep sounds
"
You: "Time for dinner music" Bot: "Starting your Dinner Jazz playlist π·"
Sonos Integration
Control multi-room audio:
SONOS_ENABLED=true
SONOS_COORDINATOR_IP=192.168.1.100
You: "Play jazz in all rooms" Bot: "Grouping all speakers and playing Jazz Classics"
You: "Stop music in the bedroom" Bot: "Bedroom removed from group and paused"
Voice Commands
Combine with voice features:
π€ "Play my discover weekly" π€ "Now playing: Discover Weekly - 30 new tracks curated for you"
Music Alarms
Wake up to music:
SPOTIFY_ALARM_ENABLED=true
ALARM_PLAYLIST=37i9dQZF1DX0...
ALARM_TIME=07:00
ALARM_DEVICE=bedroom
ALARM_VOLUME=30 # Start quiet
ALARM_RAMP_MINUTES=10 # Gradually increase
Bot at 7 AM: Gradually increases volume playing your morning playlist.
Now Playing in Chat Status
Set Discord status to current track:
DISCORD_SPOTIFY_STATUS=true
Your Discord status shows: "π΅ Listening to 'Song Name' by Artist"
Automation Ideas
Time-Based Playlists
// Cron job for automatic music
async function scheduleMusic() {
const hour = new Date().getHours();
if (hour >= 6 && hour < 9) {
await playPlaylist('morning');
} else if (hour >= 9 && hour < 17) {
await playPlaylist('focus');
} else if (hour >= 18 && hour < 21) {
await playPlaylist('dinner');
} else if (hour >= 21) {
await playPlaylist('evening');
}
}
Home Automation Integration
Combine with Home Assistant:
You: "Movie time" Bot: "Setting up movie mode:
- Dimming lights to 20%
- Stopping Spotify
- Switching TV to Netflix"
You: "Party mode" Bot: "Party mode activated:
- Lights to color cycle
- Playing Party Mix at 70%
- All speakers grouped"
Workout Companion
You: "Start my workout" Bot: "Workout mode started:
- Playing High Energy playlist
- Timer started for 45 minutes
- I'll remind you of rest intervals"
30 min later: Bot: "Great progress! 15 minutes left. Keep pushing! πͺ"
Troubleshooting
"No active device"
Error: No active device found
Solution: Open Spotify on any device first, then try again.
"Premium required"
Spotify API playback control requires Premium subscription.
Token expired
Refresh tokens automatically:
async function refreshSpotifyToken() {
const data = await spotifyApi.refreshAccessToken();
spotifyApi.setAccessToken(data.body['access_token']);
}
// Run every 50 minutes
setInterval(refreshSpotifyToken, 50 * 60 * 1000);
Wrong device
Specify device explicitly:
You: "Play on Living Room" Bot: "Switched to Living Room and playing"
Privacy Notes
- Spotify tracks your listening history
- Bot commands don't add to Spotify's tracking
- Your VPS doesn't store playback data
Related Guides
Need Help?
Spotify integration with multi-device control requires OAuth setup. Our setup service includes full Spotify configuration with speaker integration.
Need a VPS for Your Bot?
We recommend Hostinger KVM 2 VPS - reliable, fast, and perfect for AI chatbots. Get started with our recommended setup.
Get Hostinger VPSNeed Help With Setup?
Got your VPS? Let us handle the technical work. Professional setup and maintenance for OpenClaw (formerly Clawd.bot).