Playing with Huginn: "Your agents are standing by!"
According to their docs, "Huginn is a system for building agents and performing automated tasks online." That means you can make it watch websites for changes, twitter for trends or speaks, take care of some repetitive tasks, et cetera. I wanted to give it a try, for the excellently chosen name and logo, if for nothing else. π Read on for a brief overview of what it is and what you can do with it. (Next time: how to run it with Docker.)
Some of examples they give in the ReadMe:
- Track the weather and get an email when it's going to rain (or snow) tomorrow ("Don't forget your umbrella!")
- List terms that you care about and receive emails when their occurrence on Twitter changes. (For example, want to know when something interesting has happened in the world of Machine Learning? Huginn will watch the term "machine learning" on Twitter and tell you when there is a spike in discussion.)
- Send and receive WebHooks
- Run custom JavaScript or CoffeeScript functions
- Track your location over time
- Create Amazon Mechanical Turk workflows as the inputs, or outputs, of agents (the Amazon Turk Agent is called the "HumanTaskAgent"). For example: "Once a day, ask 5 people for a funny cat photo; send the results to 5 more people to be rated; send the top-rated photo to 5 people for a funny caption; send to 5 final people to rate for funniest caption; finally, post the best captioned photo on my blog."
Making a personalized newsletter
My main use-case is pretty simple. There are a few things I want to keep up to date on, but want to expend as little energy as possible. Things like when there are updates to the software I self-host, which now includes Huginn. π I do want to know what changes and when, but I don't want to check manually, receive a flood of notifications, or have it take up space in my RSS reader (which basically is just a different way of flooding me with notifications).
So I'd decided to make this the first use-case for Huginn. I took the RSS sources of the software (and some other things) I'm interested in, formatted them, and plugged them into a "E-mail Digest" - an agent that collects events that flow into it, and emits an e-mail when instructed.
This way I'm not spammed by each notification separately, but get an e-mail once in two days that just summarizes everything.
I've begun to like it a lot and started adding more and more features; now it also includes some news I only want to see once per week, Instagram accounts of a few people who only post occasionally, I've even kept in the XKCD comic that's present in the demo.
Another great feature: You can view dependencies between your agents, or group them into exportable scenarios.
How does it work?
The core concept is simple: you can define agents and dependencies between them. There are lots of agents to choose from, including ones that can send (or receive) web requests, check twitter, send e-mail, refresh RSS feeds, generate HTML output or format Huginn events.
For each agent, you can define event sources or receivers. Events are basically just JSON payloads - a simple, structured way to pass data around.
Imagine this simple scenario" when you create an RSS agent and set an e-mail agent as its receiver. (The RSS now also appears in the e-mail agent's "sources" field.) Every few hours, the RSS agent checks whether there is a new item in the feed - if there is, it generates an event in Huginn, containing things like the new item's contents, or (optionally) the feed's metadata.
Then next time the Event propagation runs (which by default is once a minute), Huginn checks whether there are new events and pushes them onto their receivers. At this point, the Event gets into the E-mail agent which then sends you an e-mail.
This system of message passing is simple and expressive, therefore allowing you to work around many issues or special cases.
For instance: I now also wanted to have Huginn's release notes in my newsletter, but the Huginn devs don't do any such thing as a 'release'. Every time a commit is made on the Master branch, you can consider it a release, the Docker images get rebuilt, and everything. But there can be a lot of commits, and they can be spread all over the place. I don't want every second or third item in my newsletter to be a single line with a Huginn commit message, what now?
The solution turned out to be quite simple: I've added a "Digest" agent that takes events from input and bundles them into a single output event. In my case, that means every two days it takes all the RSS feed items, and emits a single message that says "These are the the new Huginn updates:" and proceeds to list the feed item headlines.
Then I've found out there is a lot of garbage in the resulting e-mail, because the Digest event/message also contains a field with all the raw events, which ended up dumped in the mail as well. So I've added an "Event formatting agent" that removes it.
It took a while to figure out how I'm supposed to build this, but once I've learned how it's meant to work, all the subsequent agents went a lot quicker.
What next?
I've done some more things, like adding Pushbullet notifications for important events or news. But there's a lot more I'd like to do.
I have some personal workflows that push or pull data that run on a server somewhere, but there is no central overview/control of them. I'd like to use Huginn for that.
And the first test case will be: When the Ghost blog platform announces a new release, in addition to it entering my mail newsletter, it should also trigger an automatic update to Ghost CLI and my staging blog (where I test all the releases before I update the prod ones); then notify me.
So that's about it for now. If it looks like your kind of thing, or if you're using IFTTT but would like to do more complex or sophisticated things, definitely give Huginn a try.