Category: Code

Private webhooks

Webhooks are cool!

I was looking into setting up my own incoming webhook server, because webhooks are super cool and useful for a variety of things. 
And also because I am a giant nerd and wanted to play around with some stuff. 

Now, there are very few ready made components for this out there, so I had to do a bit of digging and I've ended up with the configuration I'm documenting here for posterity. 

My setup is running on a VM on my local network, and I've routed an obscure port to it, so I can receive webhook requests from anywhere on the internet. 
The setup is as follows:

  • a VM running Ubuntu 16.04.3
  • Adnan Hajdarević's awesome Webhook server written in Go.

Setting up Go

Go is not in Ubuntus repos yet (should be in 17.04, but that does not have LTS support). So I followed these excellent instructions

Running the program as a service

First I install the webhook server. 

go get github.com/adnanh/webhook

This has no real value if I have to log in to the server and manually start it after each reboot, so with a little help from Caius I managed to set it up as a service, so the webhook runs on each boot. 

[Unit]
Description=Webhook service
ConditionPathExists=/home/[username]/work/bin/webhook
After=network.target

[Service]
Type=simple
User=[username]
Group=[username]
LimitNOFILE=1024

Restart=on-failure
RestartSec=10
startLimitIntervalSec=60

WorkingDirectory=/var/webhook
ExecStart=/home/[username]/work/bin/webhook -hooks /var/webhook/config/hooks.json -verbose

# make sure log directory exists and owned by syslog
PermissionsStartOnly=true
ExecStartPre=/bin/mkdir -p /var/log/echoservice
ExecStartPre=/bin/chown syslog:adm /var/log/echoservice
ExecStartPre=/bin/chmod 755 /var/log/echoservice
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=webhookd

[Install]
WantedBy=multi-user.target

The program loads a config file called hooks.json, that I've placed in /var/webhook/config, and it's a basic file that lists the names of the hooks available, what script that hook should activate and what the working directory for that command is.

[
  {
    "id": "redeploy-webhook",
    "execute-command": "/var/scripts/redeploy.sh",
    "command-working-directory": "/var/webhook"
  }
]

Now I can define what hooks I want, and whatever scripts I need to have executed. Examples of this could be having my Hue lights flash if one of my servers crash, or privately scrobbling my Plex views, to name but a few things I can do with this little box. 

Not Really Introducing Kin

For the last six months or so, I’ve been spending an not insignificant amount of my free time building a social network application. No, not an app that connects to Facebook or Twitter. More like something you can use as your own private Facebook.

I originally built it for the College of Wizardry LARP, as a way for characters to creations relations and interact, thus deepening their experience. It seems to have worked out well.

But then I figured, maybe this could be used for more. And so I tweaked the code and made it fairly usable across a broad spectrum of uses. So theoretically it can be used for other LARPs, a closed social network for you and your friends (or family). Basically anywhere you’d like a group of people to have Facebook/Myspace-like interactions without sharing it publicly.

It installs on your own server, so there’s no need to worry about your content being located somewhere else and what’s happening to said content.

Here are some of the features:

  • User Walls
  • Friend lists
  • User Groups
  • Private Messaging framework, w/ file attachments for messages
  • Flexible user profile field system
  • Notification framework
  • User Relationships (romantic and familial)
  • Likes, comments and more
  • Text and picture status updates
  • oEmbed support for Vimeo, Soundcloud and Youtube (more to be added)

Now, it’s not done yet. I’m currently working on Beta 0.9.8, but I plan on having a stable production ready version for no later than summer 2015. You can find out more about the project on Github.