{
  "name": "ControlLaunchPad - Signed Offer Ready stage to Slack (starter)",
  "flow": [
    {
      "id": 1,
      "module": "gateway:CustomWebHook",
      "version": 1,
      "parameters": {
        "hook": 0,
        "maxResults": 1
      },
      "mapper": {},
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0,
          "name": "Enable JSON pass-through and request headers"
        },
        "restore": {
          "parameters": {
            "hook": {
              "label": "Create webhook; enable JSON pass-through and request headers; capture signed sample"
            }
          }
        }
      }
    },
    {
      "id": 2,
      "module": "util:SetVariable2",
      "version": 1,
      "parameters": {},
      "mapper": {
        "name": "signingSecret",
        "scope": "roundtrip",
        "value": "REPLACE_WITH_CLP_WEBHOOK_SECRET"
      },
      "metadata": {
        "designer": {
          "x": 300,
          "y": 0,
          "name": "Set your CLP signing secret"
        }
      }
    },
    {
      "id": 3,
      "module": "util:SetVariable2",
      "version": 1,
      "parameters": {},
      "mapper": {
        "name": "timestamp",
        "scope": "roundtrip",
        "value": "{{get(map(1.`__IMTHEADERS__`; \"value\"; \"name\"; \"x-clp-timestamp\"); 1)}}"
      },
      "metadata": {
        "designer": {
          "x": 600,
          "y": 0,
          "name": "Map original X-CLP-Timestamp header"
        }
      }
    },
    {
      "id": 4,
      "module": "util:SetVariable2",
      "version": 1,
      "parameters": {},
      "mapper": {
        "name": "expectedSignature",
        "scope": "roundtrip",
        "value": "{{sha256(join(add(emptyarray; 3.timestamp; 1.json); \".\"); \"hex\"; 2.signingSecret)}}"
      },
      "metadata": {
        "designer": {
          "x": 900,
          "y": 0,
          "name": "HMAC original timestamp and raw JSON"
        }
      }
    },
    {
      "id": 5,
      "module": "json:ParseJSON",
      "version": 1,
      "parameters": {
        "type": ""
      },
      "mapper": {
        "json": "{{1.json}}"
      },
      "metadata": {
        "designer": {
          "x": 1200,
          "y": 0,
          "name": "Verify signature before parsing"
        }
      },
      "filter": {
        "name": "Fail closed: configured secret, original body, signature and 5-minute window",
        "conditions": [
          [
            {
              "a": "{{2.signingSecret}}",
              "o": "text:notequal",
              "b": "REPLACE_WITH_CLP_WEBHOOK_SECRET"
            },
            {
              "a": "{{length(2.signingSecret)}}",
              "o": "number:greater",
              "b": "0"
            },
            {
              "a": "{{length(1.json)}}",
              "o": "number:greater",
              "b": "0"
            },
            {
              "a": "{{length(3.timestamp)}}",
              "o": "number:greater",
              "b": "0"
            },
            {
              "a": "{{get(map(1.`__IMTHEADERS__`; \"value\"; \"name\"; \"x-clp-signature\"); 1)}}",
              "o": "text:equal",
              "b": "sha256={{4.expectedSignature}}"
            },
            {
              "a": "{{abs(parseNumber(formatDate(now; \"X\")) - parseNumber(3.timestamp))}}",
              "o": "number:lessorequal",
              "b": "300"
            }
          ]
        ]
      }
    },
    {
      "id": 6,
      "module": "http:ActionSendData",
      "version": 3,
      "parameters": {
        "handleErrors": true,
        "useNewZLibDeCompress": true
      },
      "mapper": {
        "url": "https://hooks.slack.com/services/REPLACE_WITH_SLACK_WEBHOOK",
        "serializeUrl": false,
        "method": "post",
        "headers": [],
        "qs": [],
        "bodyType": "raw",
        "contentType": "application/json",
        "data": "{\n  \"text\": \"ControlLaunchPad: a lead reached your configured Offer Ready stage. Event {{escapeJSON(5.id)}} at {{escapeJSON(5.occurredAt)}}.\"\n}",
        "parseResponse": false,
        "timeout": "15",
        "shareCookies": false,
        "rejectUnauthorized": true,
        "followRedirect": false,
        "useQuerystring": false,
        "gzip": true,
        "useMtls": false
      },
      "metadata": {
        "designer": {
          "x": 1500,
          "y": 0,
          "name": "Set Slack incoming webhook and exact target stage ID"
        }
      },
      "filter": {
        "name": "Only real lead.stage_changed events",
        "conditions": [
          [
            {
              "a": "{{5.object}}",
              "o": "text:equal",
              "b": "event"
            },
            {
              "a": "{{5.type}}",
              "o": "text:equal",
              "b": "lead.stage_changed"
            },
            {
              "a": "{{5.test}}",
              "o": "boolean:equal",
              "b": false
            },
            {
              "a": "{{5.data.to.id}}",
              "o": "text:equal",
              "b": "REPLACE_WITH_OFFER_READY_STAGE_ID"
            }
          ]
        ]
      }
    }
  ],
  "metadata": {
    "instant": true,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": true,
      "confidential": true,
      "dataloss": false,
      "dlq": false,
      "freshVariables": false
    },
    "designer": {
      "orphans": []
    }
  }
}
