Email trigger flow with preprocessor template

json · 51 lines
1
{
2
  "summary": "Email trigger flow with preprocessor template",
3
  "value": {
4
    "modules": [],
5
    "preprocessor_module": {
6
      "id": "preprocessor",
7
      "value": {
8
        "type": "rawscript",
9
        "content": "/**\n * Trigger Preprocessor\n *\n * It processes raw trigger data (e.g., MQTT, HTTP, SQS, WebSocket, Kafka, NATS) before passing it to the flow.\n * Common tasks:\n * - Convert binary payloads to string/JSON\n * - Extract metadata\n * - Filter messages\n * - Add timestamps/context\n *\n * The returned object determines the parameter values passed to the flow.\n * e.g., `{ b: 1, a: 2 }` → Calls the flow with `a = 2` and `b = 1`, assuming the flow has two inputs called `a` and `b`.\n * Ensure that the input names of the flow match the keys in the returned object.\n *\n * @param event - Trigger data (e.g., MQTT, HTTP, SQS, WebSocket, Kafka, NATS)\n * @returns Processed data for the flow\n */\nexport async function preprocessor(\n  event: {\n    kind: 'email';\n    parsed_email: any;\n    raw_email: string;\n    email_extra_args?: Record<string, string>\n  }\n) {\n  if (event.kind === 'email') {\n    return {\n      parsed_email: event.parsed_email,\n      raw_email: event.raw_email,\n      email_extra_args: event.email_extra_args,\n    };\n  }\n\n  throw new Error(`Expected email trigger kind, got: ${event.kind}`);\n}\n\n",
10
        "language": "bun",
11
        "input_transforms": {
12
          "event": {
13
            "type": "static"
14
          }
15
        }
16
      }
17
    }
18
  },
19
  "schema": {
20
    "type": "object",
21
    "order": [
22
      "parsed_email",
23
      "raw_email",
24
      "email_extra_args"
25
    ],
26
    "$schema": "https://json-schema.org/draft/2020-12/schema",
27
    "required": [
28
      "parsed_email",
29
      "raw_email"
30
    ],
31
    "properties": {
32
      "raw_email": {
33
        "type": "string",
34
        "default": null,
35
        "description": "",
36
        "originalType": "string"
37
      },
38
      "parsed_email": {
39
        "type": "object",
40
        "default": null,
41
        "description": ""
42
      },
43
      "email_extra_args": {
44
        "type": "object",
45
        "format": "resource-record",
46
        "default": null,
47
        "description": ""
48
      }
49
    }
50
  }
51
}
Orvanta Hub — community scripts, flows, apps & resource types.