{
  "name": "bubbl3: leads from Notion",
  "flow": [
    {
      "id": 1,
      "module": "gateway:CustomWebHook",
      "version": 1,
      "parameters": { "hook": null, "maxResults": 1 },
      "mapper": {},
      "metadata": { "designer": { "x": 0, "y": 0, "name": "Notion sends here" } }
    },
    {
      "id": 2,
      "module": "util:SetVariables",
      "version": 1,
      "parameters": {},
      "mapper": {
        "variables": [
          { "name": "event_id", "value": "notion-{{1.data.id}}" },
          { "name": "phone", "value": "{{1.data.properties.Phone.phone_number}}" },
          { "name": "email", "value": "{{1.data.properties.Email.email}}" },
          { "name": "timestamp", "value": "{{formatDate(now; X)}}" },
          { "name": "source_secret", "value": "PASTE_THE_SOURCE_SECRET" }
        ],
        "scope": "roundtrip"
      },
      "metadata": { "designer": { "x": 300, "y": 0, "name": "Lead fields" } },
      "filter": {
        "name": "Has the Notion record id",
        "conditions": [[{ "a": "{{1.data.id}}", "b": "", "o": "exist" }]]
      }
    },
    {
      "id": 3,
      "module": "util:SetVariables",
      "version": 1,
      "parameters": {},
      "mapper": {
        "variables": [
          {
            "name": "body",
            "value": "event_id={{encodeURL(2.event_id)}}&phone={{encodeURL(2.phone)}}&email={{encodeURL(2.email)}}"
          }
        ],
        "scope": "roundtrip"
      },
      "metadata": { "designer": { "x": 600, "y": 0, "name": "Lead body" } }
    },
    {
      "id": 4,
      "module": "util:SetVariables",
      "version": 1,
      "parameters": {},
      "mapper": {
        "variables": [{ "name": "signed", "value": "{{2.timestamp}}.{{3.body}}" }],
        "scope": "roundtrip"
      },
      "metadata": { "designer": { "x": 900, "y": 0, "name": "Text to sign" } }
    },
    {
      "id": 5,
      "module": "util:SetVariables",
      "version": 1,
      "parameters": {},
      "mapper": {
        "variables": [{ "name": "signature", "value": "{{sha256(4.signed; ; 2.source_secret)}}" }],
        "scope": "roundtrip"
      },
      "metadata": { "designer": { "x": 1200, "y": 0, "name": "Signature" } }
    },
    {
      "id": 6,
      "module": "http:ActionSendData",
      "version": 3,
      "parameters": { "handleErrors": true },
      "mapper": {
        "url": "https://api.bubbl3.com/v1/inbound/leads/PASTE_THE_SOURCE_ID",
        "method": "post",
        "headers": [
          { "name": "bubbl3-signature", "value": "t={{2.timestamp}},v1={{5.signature}}" },
          { "name": "Idempotency-Key", "value": "{{2.event_id}}" },
          { "name": "Content-Type", "value": "application/x-www-form-urlencoded" }
        ],
        "qs": [],
        "bodyType": "raw",
        "contentType": "custom",
        "data": "{{3.body}}",
        "parseResponse": true
      },
      "metadata": { "designer": { "x": 1500, "y": 0, "name": "Send the lead to bubbl3" } }
    }
  ],
  "metadata": {
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": true,
      "confidential": true,
      "dataloss": false,
      "dlq": false
    },
    "designer": { "orphans": [] }
  }
}
