logfile.ch

Hello, Matrix: Hello, Webhooks

Our Hello Matrix bot (see the announcement and the Gitlab repository) has received a fun new feature: It can now be used to create arbitrary web hooks that, when triggered, will send a message to your room.

How does it work? Just invite him into a room and call !webhook. If you are administrator in the room (power level 100), he will send you a private message with a one-off link to administer the web hooks for the room. You get an overview over the existing web hooks, can edit and delete them and create new ones.

When you create a new web hook, you can give it a name and specify a template. Whenever the web hook is triggered, the bot will send the template you specify as a notice to your room. You can use parameters to pass information passed to the web hook on to your room (see below).

As soon as you save the new web hook, the system will display a URL that you can provide to the sending service to be called. The sender (the service which will trigger the web hook) needs to be able to call this URL and (if necessary) to pass any additional information either as query parameters (via GET or POST) or as JSON data (via POST) to the web hook. You can use these parameters or JSON fields in your message template by giving their name in double curly brackets (i.e. ``).

What can you do with this? Here are only some ideas:

  • Zapier supports sending data to web hooks (including ours). For example, you can set-up zaps that notify your room (via the web hook) about the weather or about new tweets or incoming emails or any of the gazillion other integrations Zapier supports.
  • Uptime Robot supports notifying web hooks when services go offline. You can use it to notify a room if a website you operate goes down. Using their “keyword” feature, you could also use it to get notified if a specific keyword appears on a website.
  • If you run a server, it is very easy to hit the web hook from the command line using curl, so you can post to your Matrix room directly from the command line.

Note that some of these things might also be possible by directly hitting the Matrix API (it’s also just a web API, after all), but by using the webhook interface you do not have to deal with authentication tokens, managing transaction IDs or other intricacies of the Matrix API.