ImSmart Programmer's Guide

The programming language used in ImSmart is Javascript or more specifically the V8 open-source Javascript engine. You program modules, connectors and advanced triggers using Javascript. The variables you define on your Variables page are variables you can access and set in Javascript. When you set one of your variables value in Javascript, its value is immediately reflected on your Variables page. Triggers associated to the variable are not called when you set a value in Javascript.

All ImSmart scripts run in a self-contained environment where you cannot access any UI or DOM elements. Nevertheless it makes a very powerful and flexible tool. All scripts are time-restricted to 3 seconds. If the script runs longer than 3 seconds, it is aborted and a script timeout is recorded in the trigger activity logs.

All your variables are accessible from your trigger or module script. Technically, variables are also accessible from your connector script but you should avoid accessible specific variables since a connector should be made independant of user variables.

All variables defined in ImSmart, either in your Variables repository or in the definition of a connector must follow the ECMAScript 6 valid grammar. Avoid operator keywords as well as ImSmart and _ImSmart in your variable names. A connector can use variable _moduleKey which contains the connector key.

The object ImSmart is accessible and contains the following functions:

For example, ImSmart.access('IFTTT', 'Key', 1) will return the access Key #1 which is needed in a WebHooks call.

The object ImSmart also contains the following read-only values:

We have a good example in the following IFTTT script:

Maker = function Maker(keyN){ 
   this.keyN = keyN;
   this.call = MakerCall;
};

function MakerCall(MakerEvent, value1, value2, value3)
{
   var key = ImSmart.access('IFTTT', 'Key', this.keyN);
   var url = 'https://maker.ifttt.com/trigger/' + MakerEvent + '/with/key/' + key + '?';
   var logUrl = 'https://maker.ifttt.com/trigger/' + MakerEvent + '/with/key/{{AccessKey:' + _moduleKey + '#' + this.keyN + '}}?';
 
   if (value1 !== '' && value1 !== undefined)
   {
      url += 'value1=' + escape(value1) + '&';
      logUrl += 'value1=' + escape(value1) + '&';
   }
 
   if (value2 !== '' && value2 !== undefined)
   {
      url += 'value2=' + escape(value2) + '&';
      logUrl += 'value2=' + escape(value2) + '&';
   }
 
   if (value3 !== '' && value3 != undefined)
   {
      url += 'value3=' + escape(value3);
      logUrl += 'value3=' + escape(value3);
   }
 
    ImSmart.http(url, true);
 
   if (ImSmart.fromEvent)
      ImSmart.log('Scheduled event executed. Called ' + logUrl);
   else
      ImSmart.log('Called ' + logUrl);
}

An object _ImSmart also exists for core functions but only acts as an interface to the ImSmart object. You should generally avoid using this object directly.