When working from home it's helpful to tell people by use of our Slack Status, but it's always a pain to update it back and forth as I move about.
Here I'll show how to use the act of plugging my laptop into a USB Dock as a trigger to call the Slack API to set my status.
Step 1: choose an event engine
Step 2: Install Node-RED
npm install -g node-red node-red
This should install
node-red and then start it. It'll show some console output then should be accessible on
127.0.0.1:1880. Play around with it, then exit the engine by typing
Ctrl-C in the console.
Step 2: Install Node-RED as a service
pm2 is an service that'll run any node program in the background of your computer, required otherwise you'd have to keep a Console window open the whole time.
Step 3: Detect USB's being plugged in.
You can install the module by going into
node-red's Manage Palate mode found here:
Then searching for
usb-watch and installing it:
It might take a hot-second to install depending on whether it finds a binary for your OS or has to build it itself (due to USB being quite low-level relatively).
Step 4: Putting together the flow
With the package now in place, we can put together our flow. We start with a simple check that our
usb watch node works correctly:
Then we add a filter for only the USB device we're interested in:
Confirm that it works:
Now we need to setup the JSON payload that we'll send to Slack using a
Then add the
http request node for calling Slack's API. We'll need a
bearer authentication token to authenticate ourselves with Slack, which can be generated here.
Finally we Deploy and plug in our USB Dock and watch the magic:
Voila! We have a set our Status! All we have to do it again with different filter ID's and payloads at work and we'll have a working system.