IFTTT - Switching a smart device when generating a ticket
In this tutorial regarding the example of the IoT provider IFTTT we will describe the role which todo4teams can play on the Internet. Other IoT providers can be integrated analogously into the business processes of todo4teams. A prerequisite is a registration within the respective provider and the acquisition of a suitable device. In this example a switchable socket (smart plug) is used. The prerequisite is that the corresponding device is previously registered with IFTTT. In our example todo4teams sends an event from a script that triggers an associated event. Specifically, in this example a smart socket is connected to an incoming email that generates a ticket within todo4teams.
1. step: the todo4teams-script to trigger the event
The script and the key to access the Internet of Things are stored in two server properties.
We call these server properties in our example IFTTT for the script and IFTTT_KEY for the associated key.
In the server property IFTT the function is stored, with the help of which the event can be triggered. As a parameter the function is given the name of the "webhook" to be triggered:
var iftttkey = helper.getServerPropertyByName("IFTTT_KEY");
var StringArray = Java.type("java.lang.String[]");
var JsonType = Java.type("net.sf.json.JSONObject");
var ClientConfig = Java.type("org.glassfish.jersey.client.ClientConfig");
var ClientBuilder = Java.type("javax.ws.rs.client.ClientBuilder");
var Entity = Java.type("javax.ws.rs.client.Entity");
var UriBuilder = Java.type("javax.ws.rs.core.UriBuilder");
var config = new ClientConfig();
var client = ClientBuilder.newClient(config);
var target = client.target(UriBuilder.fromUri("https://maker.ifttt.com/trigger/"+hookname+"/with/key/"+iftttkey).build());
var json = new JsonType();
json.put("Start", "Start");
var payload = json.toString();
var accept = new StringArray(1);
accept[0]= new java.lang.String("application/json");
var response = target.request(accept).put(Entity.json(payload));
}
2. step: triggering the respective event in the Internet of Things
With the above preparations the respective event can now be triggered in the server-side scripts as follows:
ifttt("NeuesTicket");