A self-hosted slack bot which collects shared Spotify links into a playlist. Built using aiohttp.
To host this bot you will need
- Privileges to configure applications within your Slack workspace
- A Spotify developer account
- A hosting service (I deploy this on AWS)
Go to the Spotify Developer Dashboard and create a new client ID. I just called mine "tunes bot
- SSH into the instance you want to deploy on. I use a free-tier AWS EC2 t2.nano running Amazon Linux 2 since it's the easiest instance type to install Docker on.
- Make sure Docker is installed
- Clone this repository and enter the newly created directory:
$ git clone https://github.com/georgejdanforth/slack-spotify-bot.git && cd slack-spotify-bot
- Create a new config file:
$ cp example.env .env
-
Using your
$EDITOR
of choice, open up.env
and populate the config parameters. The parameters are:SERVER_DOMAIN
: Domain name or IP of the server hosting this service. Make sure to excludehttp://
from this. I just use my instance public IP for this parameter but if you'd like a proper domain name you're welcome to configure that yourself.SLACK_CHANNEL_ID
: ID of the Slack channel to listen to for spotify linksSPOTIFY_CLIENT_ID
: Your Spotify API client IDSPOTIFY_CLIENT_SECRET
: Your Spotify API client secretSPOTIFY_PLAYLIST_ID
: ID of the Spotify playlist to insert tracks into. This playlist should be owned by the same user holding the API credentials.
-
Create the Docker image:
sudo docker build -t slack-spotify-bot .
- Run the Docker image:
docker run -p 8080:8080 -p 80:80 -d --env-file /path/to/your/.env slack-spotify-bot prod
- After the server is set up, go back to the Spotify developer dashboard. Navigate to the Client ID you're using for this bot and click Edit Settings
- Add
http://<your-server-ip-or-domain>/authorize/
to the redirect URIs and save - In your browser, navigate to
http://<your-server-ip-or-domain>/authorize/
. It should return a blank page with the textAuthorized!
- Go to https://api.slack.com/apps and click Create New App. Give the app a name (I called mine tunes-bot) and select the workspace you want to enable it in.
- Enable Event Subscriptions. This should open up a new set of options.
- Under Request URL, enter
http://<your-server-ip-or-domain>/
. It should validate automatically. - Add the
links_shared
workspace event - Add open.spotify.com as an App Unfurl Domain
- Save changes
- Navigate back to Basic Information and install the app in your workspace.
You're all done! Posting Spotify links in the Slack channel specified by slack_channel_id
should now add the tracks to the playlist specified by spotify_playlist_id
.