This code is a proxy between the clearbot and the node-sonos-http-api library.
sequenceDiagram
Slack-->>ClearBot: POST /slack/events { some message }
ClearBot-->>Sonos Proxy: websocket play_url { some message }
Sonos Proxy-->>node-sonos-http-api: GET http://localhost:5001/Office/clip/burn.mp3
- NPM
- Node
- Set up clearbot
- Put some mp3s in the
static/clips
directory (they correspond to the clearbot sounds defined in https://github.com/clearfunction/clearbot/blob/main/src/responses.ts.) - Set up your
.env
file (see.env.example
) - If you don't have a Sonos speaker, then you can still use the local player... just ensure you've got
USE_LOCAL_SOUNDS
set totrue
- If you do have a Sonos speaker, then you'll also need the
node-sonos-http-api
running locally - Ensure your
clearbot
is running. It has its own documentation. - Run
npm run dev
- Wait for the
Connected to http://...
message. It finds the speaker prior to starting socket connection to the bot. - Enjoy!
We set this up with
pm2
to daemonize it on the Mac Mini in our closet. Let's see how it works out for
us!
npm install # installs this app
npm install pm2 -g # installs the daemonizer
pm2 start ./server.js --name sonos_proxy # assumes you're in this app's folder, starts the daemon
pm2 save # saves the running process as a daemon that will be auto-restarted even after reboots