Skip to content
Slack integration for a local Sonos system
OCaml Dockerfile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
__tests__
docs
lib/js/__tests__/__snapshots__
src
.all-contributorsrc
.gitattributes
.gitignore
.releaserc
CHANGELOG.md
DateFns_test.re
Dockerfile
LICENSE
README.md
bsconfig.json
docker-compose.yml
package-lock.json
package.json

README.md

Sonos Wejay

Wejay is a music collaboration bot for Slack that can be used to add music to a local Sonos system. It needs to be started on the same network as your Sonos system in order to communicate with the speakers.

Demo of Wejay Slack bot

Get started

Prerequisites

Start by creating a .env file in the root directory of the project. This is for the Spotify search feature and to allow the bot to interact with Slack. It should contain

SPOTIFY_ID=spotify-token-here
SPOTIFY_SECRET=spotify-secret-here
SLACK_TOKEN=slack-token-here
WEJAY_IP=ip-of-the-speaker

Spotify token/secret can be generated by creating an app at https://developer.spotify.com/. Slack token can be found after adding the bot to your Slack below. The value for WEJAY_IP can be found in "About My Sonos System" of the Sonos Controller app, choose the IP of the speaker you'd like to send music to.

$ git clone https://github.com/Iteam1337/sonos-wejay.git
$ cd sonos-wejay
$ npm install
$ npm build && npm run dev

This will compile the Reason code and start up the Express app.

Testing it out

  1. The easiest way to start testing is using ngrok. After you've installed ngrok, open another terminal and run ngrok http 3000. This will create a tunnel to you local environment.
  2. Go to https://api.slack.com/apps and create a new app
  3. Inside OAuth & Permissions you'll find "Bot User OAuth Access Token" which is the token that should be added in your .env above.
  4. Go to Interactive Components and enable it. In the request url enter one of the urls provided by ngrok (http or https) and the route /action, i.e. https://127.0.0.1/action
  5. Also on Interactive Components add a action. Give it the name "Queue track" and description and callback id "queue"
  6. Go to Event Subscriptions and enable it. In the request url use the same url as above but use the route /event
  7. Also on Event Subscriptions add a "Bot User Event". The best one is message.im, which means you can send commands to the bot in private messages
  8. You should be able to send some commands to the bot in Slack now, try sending help to see all available commands

Available commands

Command Shorthand Description
blame Who added the track? (requires MySQL database)
clear Reset playlist
currentqueue getqueue, gq, cq Display upcoming tracks
fullqueue fq Display all tracks currently in the queue
help Display the help text
mute Mute
mostplayed List the most played tracks (requires MySQL database)
next skip Skip one track forward
nowplaying np Display what's playing right now
remove <numberOfTracks> <index> rm Remove tracks
pause Pause
play Play
playtrack <trackNumber> Play track number
playlatest pl Play latest track
previous Go back one track
queue <Spotify URI> q <Spotify URI> Queue a track using a Spotify URI
search <your search string> s <your search string> Search Spotify for a track
toplist List top Wejayers (requires MySQL database)
unmute Unmute
volume <0-100> Set volume, if no number is provided displays current volume

Copy and paste from Spotify

You can also select a couple of tracks in Spotify, press cmd+c (Mac) / ctrl+c (Windows), paste the copied information to the Wejay bot and send the message. Wejay will add all of your tracks at the end of the queue! 🎉

Database

Some of the commands, like blame and toplist requires that you have a MySQL database that the service can access. We've included a docker-compose.yml that you can use to spin up a database.

Contributors

Thanks goes to these wonderful people (emoji key):

Rickard Laurin
Rickard Laurin

💻 📖 🤔 👀
Tom Ekander
Tom Ekander

💻 🤔
Jimmy Jardland
Jimmy Jardland

💻 🤔
Nils Nilsson
Nils Nilsson

💻 🤔
faroutchris
faroutchris

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

You can’t perform that action at this time.