Remote-Work DJing with Slack and Spotify

Dan Cotton
5 min readJul 6, 2021

After a pretty serious year, we all need something fun.

The amazing team I work with in Capgemini’s Applied Innovation Exchange in London, (we’re also hiring btw!) are a fun bunch! In our office, we often build small, mini-projects to enhance our space and make our work better and more fun.

The most cherished of these projects was our Spotify music bot for Slack. When our team is in the office, any member of the team can drop onto Slack and queue up their own music via a chatbot, which will then be played for everyone.

I wanted to bring this fun, interactive way of sharing music to our remote work and have been considering how to make this happen in the most seamless way for quite a few months! Right up until last week….

The perfect UX

The Verge’s Article on Slack Huddles

Literally days before writing this article, Slack pushed a new feature to Slack Connect workspaces. Named “huddles” this was exactly what I was looking for.

With the press of a button, you’d seamlessly join an audio room, that would surreptitiously begin and end with participants coming and going. This gave me a Discord voice-channel type user experience which was exactly what I was waiting for, no barriers to entry.

So I allocated an evening as it was time to build a bot!

Bot huddling

This was probably the most tricky part of this project, primarily due to the fact that despite Slack’s amazing API for chat, they don’t support calling bots at the moment, so I’d need to find a workaround.

I went down an initial rabbit hole of reverse-engineering Slack’s calling feature, powered by Amazon Chime, with the aim of writing a small service to pull opus-encoded frames from an audio source, such as Spotify or YouTube and forward them into an Amazon Chime powered Slack Huddle.

But in the end I decided that this route would simply take too long, this project was about building something fun, I still didn’t really know if anyone would actually want to use it, so I opted for a faster approach to de-risk the problem….

I opted to write a Puppeteer script to launch Slack, open the music channel and watch for anyone to join the huddle, as soon as someone else joined, the bot would join, ready to play-back some music.

The bot automatically joins the Huddle when there’s at least one user in there

To route the audio into Slack, I simply created a virtual audio source in pulseaudio, which I created from the default VM output sink’s monitor, such that anything that was output would be sent straight back in as microphone input.

I opened up a random video on YouTube, connected to the huddle from my local slack annnnnd I could hear audio! It’s not the best quality audio in the world, but it works!

Music to my ears

Next up, building a bot to stream Spotify. Fortunately, Spotify have this amazing SDK for this and it’s really easy to use, basically just need to give it a valid oauth access token and you’re done!

In our case, our Slack bot would handle the oauth flow and we’d just retrieve it on the streamer, so I simply created a local-only REST endpoint on the bot to connect the two together, it’s that easy.

Time for a chatbot

Final step, we’re nearly there, connecting everything together with a chatbot.

The Slack API has always been pretty great to work with, but after they released their Bolt framework, it’s unbelievably easy to build a chatbot quickly.

I centred the design of the bot’s UX around the keyboard, avoiding forcing shifts from keyboard to mouse as much as possible, as such the bot is primarily driven with slack slash commands.

A demo of the /play slash command

So, I just went ahead and connected a bunch of ‘slash commands’ to Spotify behaviours, from Search, through to ‘Queueing’ and manging playback with /play or /pause.

The search results handler in from the bot’s codebase

This was really easy, simply register the command handler, call a method in Spotify’s API and then create a presentable response for Slack.

I used Slack’s Block Kit in order to present back rich, interactive content to the user. For example, when searching for a song, numbered search results are presented with an interactive ‘Play’ button, which enqueues that song.

The Search UI for the bot, right inside of Slack.

What does the future hold?

Honestly, I’m not sure! Our team has been playing around with the bot, affectionately named DJ Cleo, for a couple of days and so-far we’re loving it.

Having these small mechanisms of creating effortless interaction about things other than actual work is I think what most people are missing when remote working.

One of my colleagues sent me a message shortly after interacting with the bot, stating “(I) feel more connected to you all already!”, which is really the goal here. It’s not about the technology, or even really the music (you’ll get much better quality straight from Spotify!).

It’s about creating opportunities to connect in a digital-first time of living, something that we’ve all been trying to get better at over the past year.

I personally am looking forward to continuing to explore other ways we can re-imagine small aspects of the physical office experience to take the awkwardness and formality out of interacting digitally.

Now it’s your turn!

I’m sharing the codebase for the bot as an open-source project, available on my GitHub profile. It’s by no means the best code I’ve written, but it works and that’s what counts here!

https://github.com/daniel-cotton/spotify-huddle

Please contribute, fork it, do whatever you’d like with it, I’d love to see what people can do with it. I’m probably going to continue to push some features/fixes to it and I look forward to hearing about others who’ve deployed their own DJ bot.

--

--