Transforming Events

You can write logic in your Cloud Action to perform a transformation on the Event received, and then create one or more new Events with different payloads. For example, you could read the value reported in an incoming Event such as a numeric temperature reading in degrees Celsius, convert that value to Fahrenheit, and return an event with the converted value.

This is accomplished by dynamically constructing and returning an event handler within the Cloud Action's script.

For example, the following code modifies the x field of event and then forwards a new event:

function(event) {

   // Your code here

   var new_event = event;
   new_event.elems.x += 1;

   return {
    "/my_company/transformed": [new_event],
    "/my_company/original": [event]
   }
}

In this example, /my_company/transformed is the path that the new event is output to. The original event is also output into a /my_company/original Stream.