One time rule with arbitrary input arguments

You might often need a rule that just gets executed once, based on the input arguments that are provided within a request. For instance, connected appliances might send towards a waylay the ERROR code together with an asset identity that might need different processing in the backend (sending emails, creating work orders or alarms). In order to illustrate this use case, we created a simple template that sends different email messages that are defined in the first payload.

image

Here is the template:

{
  "name": "my-template",
  "sensors": [
    {
      "label": "transformer_1",
      "name": "transformer",
      "version": "1.0.1",
      "position": [
        133,
        224
      ],
      "properties": {
        "converter": "{\n  \"mail1\": \"veselin@waylay.io\",\n  \"mail2\": \"veselin@waylay.io\",\n  \"message1\": \"hello world\",\n  \"message2\": \"hello world 2\"\n}"
      },
      "sequence": 0,
      "tickTrigger": true,
      "dataTrigger": false
    }
  ],
  "actuators": [
    {
      "label": "templateMail_2",
      "name": "templateMail",
      "version": "0.0.9",
      "position": [
        423,
        296
      ],
      "properties": {
        "to": "${nodes.transformer_1.rawData.mail1}",
        "from": "info@waylay.io",
        "message": "${nodes.transformer_1.rawData.message2}",
        "subject": "test"
      }
    },
    {
      "label": "templateMail_1",
      "name": "templateMail",
      "version": "0.0.9",
      "position": [
        420,
        165
      ],
      "properties": {
        "from": "info@waylay.io",
        "to": "${nodes.transformer_1.rawData.mail1}",
        "message": "${nodes.transformer_1.rawData.message1}",
        "subject": "test"
      }
    }
  ],
  "relations": [],
  "notes": [],
  "triggers": [
    {
      "sourceLabel": "transformer_1",
      "destinationLabel": "templateMail_1",
      "invocationPolicy": 0,
      "statesTrigger": [
        "done"
      ]
    },
    {
      "sourceLabel": "transformer_1",
      "destinationLabel": "templateMail_2",
      "invocationPolicy": 0,
      "statesTrigger": [
        "done"
      ]
    }
  ]
}

If we start a one time task from this template and want to change the subject of these emails this would be the REST call:

 curl --user apiKey:apiSecret -H "Content-Type:application/json" -X POST \
 -d '{
    "name": "test email",
    "template": "my-template",
    "start": true,
    "type": "onetime",
    "nodes": [{
      "name": "transformer_1",
      "properties": {
        "sensor": {
          "name": "transformer",
          "version": "1.0.1",
          "label": "transformer_1",
          "requiredProperties": [ { "converter": "{ \"mail1\": \"veselin@waylay.io\", \"mail2\": \"veselin@waylay.io\", \"message1\": \"hello world 11\", \"message2\": \"hello world 22\" }" }]
        }
      }
    }]}' https://sandbox.waylay.io/api/tasks