npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ifttt-these

v0.1.5

Published

This package is middleware for IFTTT, allowing custom triggers and actions.

Downloads

5

Readme

#ifttt-these

This package is middleware for IFTTT, allowing custom triggers and actions. Ever wanted to use boolean logic for an action? This is the right place to look.

This package is under development, but should work as-is. If you have any suggestions on better terminologies/function names, please let me know!

Installing ifttt-these

Run npm install ifttt-these

Initialize ifttt-these

Username and password are required for receiving triggers from the ifttt server; a key from the Maker channel is required for sending an action to the server.

    var IFTTT_These = require("ifttt-these");
    var ifttt = new IFTTT_These({
      username: "username",
      password: "password", 
      key:      "makerkey"
    });

Create custom trigger middleware

Messages are received through the wordpress post action. There are two types of messages that we can receive. ##Receiving

  1. State changes - A state change will have the contents of the post as JSON, and the title "state". The internal state variable will be updated with the values from the JSON. Each top-level variable in the object will be triggered (see below).
  2. receiving triggers - Set the title as "action", and the content as the name of your trigger

##Example

For this example, I want to to get a phone call if I am late for work. Most of the work is going to be on the IFTTT side of things:

  1. I set a date/time event for every weekday at 6:45, to do a wordpress post. The content for the post will be "TimeToLeave".
  2. I set up a few events which keep track of where I am; for this example, I have two location events. When I leave home, I send {location:"unknown"}, and when I get home, send {location: "home"}.
  3. I have a final event, when I send the trigger "Call", I trigger a phone call which will speak the first argument.

This is all of the code I need for the middleware.

    ifttt.ifThisThen(
      function() { return ifttt.wasTriggered("TimeToLeave") && ifttt.state.location !== "home"; },
      function() { 
        ifttt.trigger("Call", function(){return ["Wake up you're late for work."]}) 
    });

##Functions

###softTrigger(string)

    /**
     * Software trigger
     * @param  {String} action name of the trigger
     */

###ifThis(bool())

    /**
     * One-time if-this
     * @param  {function} bool Function which will evaluate true for a trigger.
     * @returns {Promise} Promise
     */

###ifThisThen(bool(), callback())

    /**
     * Set up a condition for trigger
     * @param  {function} bool Function which will evaluate true for a trigger.
     */

###wasTriggered(string)

    /**
     * Was Triggered
     * @param  {String} name Name of item to check if triggered
     * @return {bool}      true if the item was triggered.
     */

###setState(Object)

    /**
     * Set internal state
     * @param {Object} state State variables to modify.
     */

###trigger(eventName, argsFunction)

  /**
   * Send a trigger to the ifttt server 
   * @param  string eventName       the name of the trigger which will be 
   *                                specified by the Maker channel
   * @param  function argsFunction  function which will return an array of up to 
   *                                3 booleans, which will be maker values.
   */

###triggerPromise(eventName, argsFunction)

  /**
   * Promise to send a trigger to the ifttt server 
   * @param  string eventName       the name of the trigger which will be 
   *                                specified by the Maker channel
   * @param  function argsFunction  function which will return an array of up to 
   *                                3 booleans, which will be maker values.
   * @return Promise              
   */