Your content here
- Javascript: Runs native javascript with a partial implementation of ECMA-262. See below for examples of common examples.
- Short lived: Triggers are intended to be short lived scripts, operations are non-blocking, and if an operation requires I/O such as communicating with a device or an external service, responses are asyncrhonous. Triggers that run too long may be aborted by the system.
- Isolated: Triggers run in isolated environments, meaning there is no way for triggers to directly communicate with eachother. There is a function exec.now() that can be used from a trigger to pass data and invoke another trigger.
Triggers have a finite lifecycle that typically spans milliseconds. The lifecycle is as follows:
- Event is received by the server.
- If the event includes location data, the event is encriched with the reverse geocoded address.
- The trigger filters are evaluated to determine if the event matches any triggers.
- If a trigger matches, then the trigger executes.
- The trigger can complete as a success for failure.
There are many use cases where you may want to store common functions or variables that can be re-used between multiple triggers, to address this we support library
triggers. To make a library trigger, you create a new trigger, and select the "Event type" as Library
.
- Store API keys, URLs, or other variables that you want to access in multiple triggers.
- Common functions that are needed in multiple triggers, such as custom decoding functions for payloads.
- Library triggers have the event type of
Library
.
- Library triggers cannot be started or stopped.
- Libraries can include other libraries.
- Libraries cannot include themselves or create a circular loop of libraries.
- No reference exists, so take care when importing/exporting to include your libraries.
trigger.include('mylibrary')
libraryfunc('hello world')
// named "mylibrary"
function libraryfunc(str) {
log.trace('received: '+str)
}
var obj = {a:1, b:2, c:3}
for(var key in obj) {
var val = obj[key]
log.trace('item: ' + key + '=' + val)
}
var arr = [ 1, 2, 3 ]
arr.forEach(function (val) {
log.trace('value: ' + val)
})
var obj = {a:1, b:2, c:3}
var arr = []
for(var key in obj) {
var val = obj[key]
arr.push(val)
}
try {
var rslt = http.get('http','https://www.google.com')
} catch(e) {
log.user('error: '+e)
}