A Telegram bot that shares your currently playing Spotify track via inline queries.
Install dependencies with uv:
uv sync- Open Telegram and search for @BotFather
- Send
/newbotand follow the prompts to create your bot - You'll receive a bot token that looks like:
123456789:ABCdefGHIjklMNOpqrsTUVwxyz - Send
/setinlineto BotFather and select your bot to enable inline mode - Save the bot token for later
- Go to the Spotify Developer Dashboard
- Log in with your Spotify account
- Click "Create app"
- Fill in the details:
- App name: Choose any name (e.g., "Now Playing Bot")
- App description: Any description
- Redirect URI:
https://your-domain.com/spotify/callback(replace with your actual domain)
- Accept the terms and create the app
- Click "Settings" to view your Client ID and Client Secret
- Save both credentials for later
Generate APP_SECRET for encryption:
uv run python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"Generate BOT_WEBHOOK_SECRET:
uv run python -c "import secrets; print(secrets.token_urlsafe(32))"Create a .env file with all the credentials:
ENVIRONMENT=production
LOG_LEVEL=INFO
APP_URL=https://your-domain.com
APP_SECRET=<generated-from-step-4>
BOT_TOKEN=<from-step-2-botfather>
BOT_WEBHOOK_SECRET=<generated-from-step-4>
SPOTIFY_CLIENT_ID=<from-step-3-spotify-dashboard>
SPOTIFY_CLIENT_SECRET=<from-step-3-spotify-dashboard>
DATABASE_URL=postgresql://user:password@localhost/dbnameConfiguration notes:
ENVIRONMENT: Can bedevelopment,production, ortest(defaults todevelopment)LOG_LEVEL: Logging level -DEBUG,INFO,WARNING,ERROR, orCRITICAL(defaults toINFO)APP_URL: Must be publicly accessible for Telegram webhooks to workDATABASE_URL: Optional, defaults to SQLite (sqlite:///database.db). For production, use PostgreSQL
uv run alembic upgrade headFor local development, you'll need to expose your local server to the internet for Telegram webhooks to work. Use a tool like ngrok:
# Start ngrok in a separate terminal
ngrok http 8000
# Update APP_URL in .env to your ngrok URL (e.g., https://abc123.ngrok.io)
# Then start the development server
uv run fastapi dev --entrypoint app.main:app --host 0.0.0.0For production deployment, use a proper web server and ensure your domain is configured correctly:
uv run fastapi run --entrypoint app.main:app --host 0.0.0.0 --port 8000Make sure your server is accessible at the APP_URL you configured in the .env file.
To enable error tracking with Sentry, add your DSN to the .env file:
SENTRY_DSN=your-sentry-dsn-hereThe bot will work fine without Sentry configured - it's completely optional.
Run all checks before committing:
bash scripts/check.shThis runs:
ruff check- Lintingruff format- Code formattingty check- Type checkingpytest- Testsalembic check- Migration validation
- Start the bot with
/start - Login with your Spotify account
- Use the inline query (
@botnamein any chat) to share your current track