A small webhook reactor.
Hooktor is a little Node.js application that listens for webhooks, and depending on some factors, runs anything you want as a reaction to it. You may call it a small webhook reactor.
Hooktor is designed to support multiple kinds of webhooks, and multiple targets. The URLs for incoming hooks are rather simple, for example:
https://hooktor.example.com/[project]/[endpoint]
Hook endpoints are combined into what Hooktor calls projects. Projects are a simple way to group multiple webhooks together into a logical unit, and into one config file as well. This makes it easy to keep somewhat maintainable configurations, even when maintaining a log of hooks for lots of applications. A project can have an unlimited amount of endpoints, which are the key that identifies what kind of hook data is expected, and what should happen with the incoming events.
Some kinds of events expose parts of the information (like, for example, the pull request ID for GitHub pull request webhooks) as environmental variables to be used by the script. For maximum flexibility, the entire hook payload is provided to the hook script via STDIN
, so you are free to extract everything you need to!
For more details, information on how to get set up, and to explore some examples, have a look at docs/projects_and_endpoints.md
.
npm i
./etc/hooktor/config.json
node hooktor.js /etc/hooktor/config.json
If you want to deploy Hooktor on a server without the need for Node.js on the server, this app is set up to support pkg
. Do do so…
npm i
../node_modules/.bin/pkg .
Friends, as I am using Arch on all my servers, there is an AUR package available. This package distributes the binary version, so Node.js is only required to build the package, not to run it.
The package installs a minimal config to /etc/hooktor.json
, which expects the project configuration files in /var/lib/hooktor/projects
. It is also set up to listen on [::1]:4042
, so you need to change that if you want to have Hooktor listen on a public address. In addition, a Systemd service is available, so you should be good to go after systemctl {enable,start} hooktor
.
Feel free to jump in! Regardless if you file an issue on GitHub or end up contributing source, I will be very happy about it! If you have, for any reason, a question you do not want to ask in public, feel free to reach out to me directly and we’ll figure it out.
Adding a service (i.e. a new type of webhook payload) can be done by adding a new file to lib/services/
with a reasonably identifiable name. Each service must extend the Service
base class in lib/service.js
and implement the isValid()
and execute()
functions to be functional. If possible, I’d like to keep the number of dependencies as low as possible, but if there is a need for it, I will not complain. Also, for good measure, I require adding a documentation file to /docs/services/
as well. :)
So… although I am using this thing on my production servers, take care when deploying this in a production environment. At this point in time, bugs may attack you everywhere, and it is more than possible that the application will behave in unexpected ways if there is something wrong with anything, as I didn’t do much error handling. :)
MIT.