Recently I discovered a tool called Huginn. It’s a neat tool that allows you to automate many tasks – like a self hosted Zapier. I also realized a desire to automate the discovery + publication of codes from Hideout.tv’s Facebook page – so I figured, why not use Huginn to solve that problem?
Setup for your own Discord server is pretty simple. All you need is a server to host Huginn and the JSON file for my Huginn scenario (basically a bundle that runs itself).
If you don’t want to set up your own server, and just want to get notifications, I have a demo Discord server where an instance of the bot lives.
You’ll need a server with at least 2GB RAM, a decent CPU, and Ubuntu or Debian. Make sure you have Docker and Docker-compose installed:
curl https://get.docker.com | bash
apt install docker-compose
Huginn can easily be run with a simple
version: '2' services: mysqldata: image: mysql:5.7 command: /bin/true volumes: - /opt/huginn/mysql-data:/var/lib/mysql mysql: image: mysql:5.7 restart: always env_file: - ./mysql.env volumes_from: - mysqldata web: image: huginn/huginn-single-process restart: always ports: - "127.0.0.1:3000:3000" env_file: - ./mysql.env - ./secrets.env depends_on: - mysql threaded: image: huginn/huginn-single-process command: /scripts/init bin/threaded.rb restart: always env_file: - ./mysql.env - ./secrets.env depends_on: - mysql - web watchtower: volumes: - '/var/run/docker.sock:/var/run/docker.sock' image: containrrr/watchtower
Put this in a file called
docker-compose.yaml in a folder of your choice, download secrets.env and mysql.env to the same folder, and run
docker-compose up -d. Huginn will be running on
126.96.36.199:3000 (where 188.8.131.52 is your server’s IP).
(You should know that Huginn is incredibly configurable. Config options are available in the GitHub repo, but are outside the scope of this guide.)
You should use a reverse proxy like Caddy in front of Huginn, but that is outside the scope of this guide.
Once you access the web UI by opening
184.108.40.206:3000 in your web browser, login using the default username and password,
admin / password (you should change these).
Discord Webhook Setup
Make sure you are the admin of a server (or at least have Manage Webhooks permission). Create a webhook by opening Server Settings > Webhooks > Create Webhook, specify a channel of your choice for the bot to post to, and copy the URL at the bottom. You’ll need this to configure the scenario at the next step.
Download the scenario from my Huginn server: https://huginn.unixfy.me/scenarios/2/export.json
Upload it through the “Import Scenario” button in the “Scenarios” section of Huginn.
Go to “Credentials” and create a new credential called
discord_hideout_webhook_url. Set the value to the webhook URL you copied earlier.
Now, wait for Hideout.tv to post a new code to their Facebook page and watch the notification automagically appear in your Discord server!
Editing the notification sent to Discord by the bot
To change how the notification appears or add/remove mentions, you can edit the Agent titled “Publish codes to Discord“. In the
payload section of the JSON configuration, you can modify the POST request sent to Discord (hint: use this tool to generate an embed!).
If you run into any problems with the setup, feel free to comment down below 🙂
The logic behind the bot is pretty simple, and thanks to Huginn, requires exactly 0 lines of code.
A web scraper agent parses the posts list of Hideout’s Facebook page and converts the contents of each post into a text string (postContent). All posts are dropped except the most recent one. A trigger agent reads the output of the most recent post and checks if it contains “free points” (a string present in every post with a promo code). If it does, it’s sent to a post agent that POSTs the Discord webhook, if not, the data is discarded. It’s that simple (and shows how powerful Huginn is!).