As I’ve blogged before, IFTTT.com (short for “If This Then That”) is a popular service which lets you trigger actions based on certain events that occur around the internet.

One of the most requested features, by programmers at least, is to add WebHooks support. Webhooks are a very simple way of pinging API information about the internet between web services. It uses JSON to send an arbitrary payload over HTTP via a POST request to a specified endpoint. This is about as simple as you can get, which is of course the beauty of it.

Support for Webhooks is an obvious extension to IFTTT, and would allow people to build on the service, connecting together more than just the hand picked menu of channels on the IFTTT dashboard. Quite why this is so slow coming is a mystery; some have speculated that it was a business decision on their part, others that it is hard to build a slick interface for something of such a highly technical nature, others that they simply haven’t gotten around to it just yet.

Free Software to the Rescue!

Until IFTTT implement a WebHooks channel, you can use the following workaround.

Abhay Rana, in a project over on GitHub, has built a some code which provides a WebHooks bridge for IFTTT and other services. I have extend to add some extra functionality you might find useful.

Currently, the IFTTT wordpress channel uses that software’s RPC endpoint to make posts, so the software works by providing a little bit of middleware, that you install on an internet facing machine, which pretends to be an installation of WordPress. You then point the wordpress IFTTT channel at this installation, passing it some special parameters.

You specify the final endpoint URL as a tag, and by default the contents of the post, title, and categories get JSON encoded and relayed to this endpoint.

My extensions

Different Webhook endpoints need different fields, however, so my extension lets you provide service specific plugins. These plugins can manipulate the data sent to the upstream endpoint further, providing different fields and encoding options. This lets you support multiple webhook endpoints from a single installation, and without having to set up multiple IFTTT accounts.

To use, create the appropriate plugin in your installation’s plugins directory containing your extension of the Plugin class, then pass a special category “plugin:NameOfClass“.

I have included an example class and a JSON payload class. The latter assumes that the post body is valid JSON, validates it, and then sends it to the upstream endpoint. This lets you send specially crafted messages to upstream webhook endpoints.

My extension also includes much more debug logging, as well as some extra validation code and graceful failures.

Why?

IFTTT is a fantastically useful service, but unfortunately you are limited to using the services they choose to (or have time to) write connectors for. I find this limiting, and at times frustrating, since as well as excluding some great existing services, it places limits on my ability to hack my own stuff together!

Previously, I’d often used twitter to glue things together. However, since Twitter are currently making concerted efforts to turn their service into just another ad serving platform, rather than the communication platform and messaging service it was growing into, it was necessary to come up with an alternative method.

WebHooks seem a better solution anyway.

Thanks again to Abhay Rana for the original code, and I hope people find my additions useful!

» Visit the project on Github…

15 thoughts on “Using Webhooks with IFTTT.com

  1. WebHooks allow you to collect information about events, such as the publishing of a page or post, a comment on a page, etc. as they happen in real-time. They are very simple to set up – all you need to do is provide a URL, select when and where you want that URL to receive data about events on your list, and it will be sent to the URL you have specified as the events take place
    Wikipedia defines a WebHook as a “method of augmenting or altering the behaviour of a web page, or web application, with custom callbacks. These callbacks may be maintained, modified, and managed by third-party users and developers who may not necessarily be affiliated with the originating website or application”.

    WebHooks can also be used in Email Marketing. MailChimp for example, allows a wide variety of options for events you want to capture, based on their sources, including:
    Subscribes
    Unsubscribes
    Profile Updates
    Email Address Changes
    Here are some examples of how WebHooks function:
    Each time another blogger reblogs one of your posts, be informed about offshoot discussions on other blogs that emanated from your original post so that you can share on them yourself as well as receive more inbound links to your blog/website from the discussion
    set ‘trigger word(s)’. If a post or comment is made that contains one or more triggers such as name, website, genre, etc., the WebHook notifies the user
    WebHooks are simple to implement and can be integrated and implemented everywhere. You can point a WebHook at a site that will call other WebHooks – it might then process the data, record it, redistribute it to multiple other WebHooks.
    Related articles
    Using Webhooks with IFTTT.com (marcus-povey.co.uk)
    Why content shareability matters (thecontentlab.icrossing.com)
    Developers Want Realtime (leggetter.co.uk)

    50.735062
    -1.803208

    Related

  2. Thought I’d follow up on this by mentioning that Zapier (https://zapier.com) already has webhook support and has for quite some time.

    Disclaimer: I hack at Zapier. I actually came across this post while searching for something else webhook related and thought I’d comment. 😉

  3. IFTTT for automation – connecting the tubes together
    by Dav · July 4, 2014

    If you don’t already know about “If This Then That” (ifttt.com) – this is a legendary service, launched in 2010, that helps you connect your favourite web apps together. It also has links to your technology like your phone, home automation tech like thermostats, etc.
    For example, if you wanted to get a push notification on your phone every time somebody posts a comment on your blog, there’s a recipe for that.
    Yeah, they call these things “recipes”. It makes sense when you start using it.
    Another good example is if you want the system to mute your mobile phone when you have a meeting on your Google Calendar. You can write any recipe you want based on the supported “channels”
    At the time of writing this, the system has 116 possible channels you can activate, including:
    Facebook (including pages and groups)
    Gmail (or just ordinary email)
    Dropbox or Google Drive or Box.Net
    WordPress (self-hosted *and* wordpress.com supported)
    SMS text message
    Phone Call
    iOS Location, Contacts, Photos, Reminders, and Notifications.
    Android location, Notifications, SMS, Photos, and more….
    The full list is quite long, and it supports almost everything the casual consumer can think of.
    When you create a recipe, you first pick a “trigger” and then you select an “action” to do based on this trigger.
    So I have a recipe with an eBay search trigger for a 27″ monitor at a certain price and then it sends me a push notification on my phone via the Pushover app. In this case I’m using the eBay Channel and the Pushover channel.
    Some channels have both search triggers *and* actions, whereas others may only have one side. e.g. you can only store lines in a google doc spreadsheet, there’s no trigger for that (at least there wasn’t the last time I checked).
    The eBay search channel works without any activation needed, whereas the pushover channel will require your pushover API key – this is for your own security and in order to ensure the push notification goes to your phone only.
    It’s become a cliché now, but we really do live in an information age, where our time is precious and the tsunami of information and new apps can sometimes be overwhelming.
    In many ways these “time-saving” apps are actually taking up most of our time. So in my opinion, anything that helps me automate this sort of thing is a lifesaver. Admittedly this comes from a person that would rather be creating content than consuming it, but that’s another point for another day, and I think that this sort of app has relevancy for anybody that uses the likes of Facebook, Twitter, and Instagram.

    Dav’s wishlist for IFTTT
    1. More “triggers” and more “actions” on current channels
    This one I’m sure goes without saying but the more granularity we nerds (and non-nerds alike) receive, the more we can do.
    2. More business channels (or a premium business area)
    I’d love to see integrations with some applications like PayPal, Salesforce, etc., just like Zapier does. See more info on Zapier below.
    3. An API or some way to build your own triggers. [edit]webhooks is the way to do this really, there’s a good article (and a possible workaround) here[/edit]
    This is more for the programming geeks like myself, but it would be nice to be able to feed this into some of my own services or other unlisted web apps in order to “roll your own”. I suppose a combination of Yahoo pipes and IFTTT is possible but I haven’t really though about this until right now. I’m off to go try that after this post…..
    Similar and related services
    Zapier – this one is definitely more targeted at businesses, with 300 apps included at time of writing, integrations between Dropbox and MySQL, Salesforce and WuFoo forms, etc etc.
    Wappwolf Automator (for Dropbox, Google Drive and Box) – this service helps you convert files between different formats just by dropping the files in your cloud storage. It also has image manipulation options, even photo effects.
    Yahoo Pipes – this is another great service that allows you to hook RSS feeds together, work with XML data, even traverse normal HTML with xPath. Its primary function is to aggregate and mashup content from around the web.
    “Folder Actions” in Mac OS X – just some scripts that you can attach to folders that perform actions when you add/remove files from the folder. Here’s a decent explanation: http://www.simplehelp.net/2007/01/30/folder-actions-for-os-x-explained-with-real-world-examples/

    You can find more alternatives here:http://alternativeto.net/software/ifttt/
    Beardy Says: Feel free to post some of your favourite recipe ideas in the comments. such good automation best win!

  4. Marcus: thanks so much for sharing your work on this project. Can I ask how to enable the testplugin (I’m a simpleton). Do I edit the xmlrbc.php? I’m getting a mental hangup when I read: “pass a special category “plugin:NameOfClass“” and can’t figure out where/how to do that. Thanks!

  5. Hi there! No, you shouldn’t have to edit xmlrpc.php… you need to create a file for your plugin, and a class of the same name (see the examples given)…

    So, if you’re creating a class “MyAwesomePlugin”, you’d put it in the plugin directory in a file called myawesomeplugin.php. Then on the IFTTT side of things you’d tell your action to use that plugin by creating a category plugin:MyAwesomePlugin.

    Whenever your action gets triggered, the payload will get fired at your endpoint and routed to your handler.

  6. Hi Marcus. Please check out hookify.io We created it for just the kind of problems you are talking about. As someone who understands these problems and webhooks, I’d like to hear what you think of it. We are gearing up to let in our next batch of testers. If you are interested, sign up for the beta and I’ll make sure you get in the next batch.

  7. For many reasons, not least of which their decision to appoint a surveillance loving war criminal to their board of directors, I’ve been steadily migrating away from Dropbox.
    Thankfully, there is a drop-in replacement for much of it, providing you run your own server. So, I’ve got a syncing file store/backup running across my devices, which can be accessed while I’m on the go as well.
    However, one of the things I do use dropbox for (which is not terribly important in the grand scheme of things, but which I find quite useful) is, via the use of an IFTTT rule, to take a copy of any photos I’m tagged in on Facebook, so that I can see them (and to break them out of the silo) without actually having to go onto Facebook. This is possible using dropbox, owing to it being a centralised service, but obviously isn’t possible using your own server.
    Webhooks to the rescue!
    So a little while ago I put together a hack that used IFTTT’s wordpress channel to add a pluggable webhooks interface to IFTTT.
    Since this tool supports plugins, I was therefore able to write a simple Facebook adapter which, when triggered would extract the image URL from the push message and then simply download it.
    Since my owncloud install was on the same server, all I had to do was output this file to the appropriate owncloud data directory and any files retrieved are automatically synced to your client devices. You can of course opt to write to any directory, and not use owncloud at all, but since I wanted a like for like replacement for IFTTT+Dropbox I went for owncloud server storage!
    Here’s the facebookphoto.php plugin code:



    <?php
    class FacebookPhoto extends Plugin {

    private $owncloud_path = ‘/path/to/owncloud/server/data/user/files/Ifttt/tagged/Facebook/’;
    private $expected_password = ‘passwordforwordpresschannel’;

    public function execute($plugin, $object, $raw) {

    // Extract image urls
    if (preg_match(‘/< *img[^>]*src *= *[“‘]?([^”‘]*)/’, $object->description, $matches))
    {
    $url = $matches[1];

    $parsed = parse_url($url);

    if ($object->pass == $this->expected_password) {

    $filename = basename($parsed[‘path’]);

    file_put_contents($this->owncloud_path.$filename, file_get_contents($url));
    }
    }

    return $object;
    }
    }


    1234567891011121314151617181920212223242526

    <?php    class FacebookPhoto extends Plugin {                private $owncloud_path = ‘/path/to/owncloud/server/data/user/files/Ifttt/tagged/Facebook/’;        private $expected_password = ‘passwordforwordpresschannel’;         public function execute($plugin, $object, $raw) {                 // Extract image urls                if (preg_match(‘/< *img[^>]*src *= *[“‘]?([^”‘]*)/’, $object->description, $matches))                {                        $url = $matches[1];                         $parsed = parse_url($url);                         if ($object->pass == $this->expected_password) {                                                        $filename = basename($parsed[‘path’]);                                 file_put_contents($this->owncloud_path.$filename, file_get_contents($url));                        }                }                        return $object;        }    }


    Simple, and obviously you could extend this to do other things with it.
    Place the code in your plugins directory, and create a new recipe on ifttt triggering your plugin whenever you’re tagged on Facebook, remembering to pass plugin:FacebookPhoto as your category.
    » Visit the Ifttt webhook project on github…

    Thanks for visiting! If you’re new here you might like to read a bit about me. You may also like to follow me on Twitter!

    (Psst… I am also available to hire! Find out more…)
    Share this:EmailLinkedInTwitterGoogleFacebookReddit

  8. Hmm… this code is designed to take a trigger from IFTTT and convert it into an action which you can use externally.

    Taking an external action and triggering something in IFTTT is a little more tricky, and would require piggybacking off something with an input channel supported by them – e.g. have a post trigger an email/tweet or monitor an RSS feed.

    HTH 🙂

Leave a Reply