- Use Case
- Log in →
- Node-RED OwnTracks location tracking without public IP/MQTT
- Secure webhooks to Jenkins on Kubernetes
- Remote YouTube downloader Slack bot
- Introducing WebSocket Server
- Rancher - push to deploy workflow with Keel
- Documenting your API with OpenAPI (Swagger) and Redoc
- Home Assistant remote access add-on
- Hassle-free remote access to Home Assistant on a Raspberry Pi
- How to receive Paypal webhooks on localhost
- DevOps Use Case: Performing Redis maintenance in Kubernetes
- Auto deploy your Node.js app on push to GitHub in 3 simple steps
- What is a webhook and how to create one?
- Mailgun webhook fan-out
- Web Relay Ingress with Docker for Mac
- How to receive Stripe webhooks on localhost
- Receive Github webhooks on Jenkins without public IP
- Keel - automated Kubernetes updates
- Introduction to Webhook Relay
Remote YouTube downloader Slack bot
Dec 12, 2018, by Karolis Rusenas
For the webhook producer, we will use Slack and their slash commands. Advantages of Slack slash commands:
- No need for Slack client SDK
- Works through webhooks that can easily be processed in any language
- No authentication token required (just needs a webhook endpoint where to send requests)
Webhooks are awesome but your application needs to be exposed to the internet to receive them. It must also have a web server that can process those webhooks. For a simple application or that doesn’t have to be always online, configuring NAT/firewall might be an overkill.
Webhook Relay + WebSocket client can let your applications receive webhooks from 3rd party services without having a public IP/domain, configuring NAT, and even the web server becomes unnecessary. You can process webhooks right inside your application.
We will be to create a bucket (buckets are used to group inputs/outputs in Webhook Relay) to capture and relay Slack webhooks. Go to buckets page and create a new bucket called
slash. It will get a default public endpoint which we will be using in the next step. Create an internal output too, the destination doesn’t matter but it will help us with debugging:
First things first, we will need an easy way to send a webhook. I initially thought about trying out Airtable and Google Sheets but was quite disappointed with the lack of webhooks in their services. Zapier seems to be trying to help a bit there, but their webhooks can only work every 15 minutes and even then I didn’t receive any webhooks.. :) So, another obvious and easy choice would be Slack slash commands.
Slash Commands let users trigger an interaction with your app directly from the message box in Slack.
Creating a Slash command actually is a lot more straightforward than you would expect, have a look in the official docs. Come up with a name and select a workspace:
Now, from ‘Add features and functionality’ select Slash Commands and fill in some details:
You can get creative with the command prefix
/dl as our application doesn’t consume it, only the text after the command will be used inside the code. In the Request URL add your Webhook Relay input endpoint that is
https://my.webhookrelay.com/v1/webhooks/..... Once you are happy with the details, save and install it:
Now, whenever we type
/dl https://www.youtube.com/watch?v=tPEE9ZwTmy0 it will send a webhook to Webhook Relay input and from there we can relay it to our app. Try it out, it will be captured.
Once we have got the test payload, we need to check what’s inside it. Unfortunatelly I couldn’t find a way to make it send JSON and so we will have to work with
Content-Type: [ "application/x-www-form-urlencoded" ]. Webhook Relay helpfully parses the message:
So we now know what fields are we going to take:
- text - this is our URL to download
- response_url - this is where we can reply to the user
Application code can be found on Github repo, feel free to clone it. To make our life easier, some main libraries:
- https://github.com/przemyslawpluta/node-youtube-dl - download the videos.
- https://github.com/ljharb/qs - query string parses (helps us parse Slack payload).
- https://github.com/request/request - simple HTTP client. Even though I would always prefer using a stdlib, in this case it just worked better for me.
For readers, here’s the whole application:
Install dependencies from https://github.com/webhookrelay/slack-slash-downloader/blob/master/package.json by:
To launch it, retrieve the tokens from tokens page and set them as an environment variables:
Once it’s running, you can start downloading videos via Slack, just type:
App logs should be similar to this:
Your file should appear in the same directory as the application:
You can modify the code to put it into your downloads directory or wherever you want to keep the files.
In this technical demo we showed a practical use case of how a lightweight Node.js daemon can receive and process webhooks without having public IP or running a web server. This can greatly simplify the whole application, reduce attack surface and provide audit capabilities on top of it.