Skip to content

bkonetzny/node-ifttt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ifttt

IFTTT

Enables you to build IFTTT compatible node endpoints with express.

Features

Planned

Install

Install the module via npm:

$ npm install --save ifttt

Usage

// Require the module in your code.
var Ifttt = require('ifttt');

// Create new IFTTT channel.
var iftttChannel = new Ifttt();

// Add triggers & actions to your IFTTT channel.
iftttChannel.registerTrigger(YOUR_TRIGGER);
iftttChannel.registerAction(YOUR_ACTION);

// Add IFTTT channel routes to your express app.
iftttChannel.addExpressRoutes(app);

Examples

Create trigger

// Require the module in your code.
var Ifttt = require('ifttt');
var util = require('util');

// Create example trigger.
function ExampleTrigger() {
  ExampleTrigger.super_.call(this, 'example');
}
util.inherits(ExampleTrigger, Ifttt.Trigger);

// Overwrite `_getResponseData` with your response handler.
ExampleTrigger.prototype._getResponseData = function(req, requestPayload, cb){
  var results = [];

  results.push({
    field1: 'value1',
    created_at: new Date().toISOString(),
    meta: {
      id: 'id1',
      timestamp: new Date.now()
    }
  });

  return cb(null, results);
};

module.exports = ExampleTrigger;

Create action

// Require the module in your code.
var Ifttt = require('ifttt');
var util = require('util');

// Create example action.
function ExampleAction() {
  ExampleAction.super_.call(this, 'example');
}
util.inherits(ExampleAction, Ifttt.Action);

// Overwrite `_getResponseData` with your response handler.
ExampleAction.prototype._getResponseData = function(req, requestPayload, cb){
  var results = [];

  results.push({
    id: 'id1'
  });

  return cb(null, results);
};

module.exports = ExampleAction;

Create trigger field

// Require the module in your code.
var Ifttt = require('ifttt');
var util = require('util');

// Create example field.
function ExampleField() {
  ExampleField.super_.call(this, 'example');

  // Set sample data so IFTTT can properly test this field.
  this.setOptionsSampleData('valid_option_value', 'invalid_option_value');
}
util.inherits(ExampleField, Ifttt.Trigger.TriggerField);

// Overwrite `_getOptionsData` to return field options.
ExampleField.prototype._getOptionsData = function(req, response, cb){
  var option = new response.OptionEntity();
  option.setLabel('Valid option 1');
  option.setValue('valid_option_value');
  response.addOption(option);

  var option = new response.OptionEntity();
  option.setLabel('Valid option 2');
  option.setValue('valid_option_value2');
  response.addOption(option);

  return cb(null);
};

// Overwrite `_getValidateData` to check if value is valid.
ExampleField.prototype._getValidateData = function(req, response, payload, cb){
  var value = payload.getValue();

  if (value === 'valid_option_value') {
    response.setValid(true);
    return cb(null);
  }
  else if (value === 'invalid_option_value') {
    response.setValid(false);
    return cb(null);
  }
};

module.exports = ExampleField;

Releases

No releases published

Packages

No packages published