{"name":"Send a Slack message when a post goes live","flow":[{"id":1,"module":"gateway:CustomWebHook","version":1,"mapper":{},"parameters":{"maxResults":1},"metadata":{"designer":{"x":0,"y":0}}},{"id":2,"module":"code:ExecuteCode","version":0,"mapper":{"language":"python","inputFormat":"editor","dependencies":[],"codeEditorPython":"values = input\nimport hashlib\nimport hmac\nimport json\nimport re\nimport time\n\nsecret = values.get(\"secret\")\nraw = values.get(\"raw\")\nsignature = values.get(\"signature\", \"\")\nmatch = re.fullmatch(r\"t=([1-9][0-9]{0,15}),v1=([0-9a-f]{64})\", signature or \"\")\nif not secret or secret == \"REPLACE_WITH_SIGNING_SECRET\" or not isinstance(raw, str) or not match:\n    raise ValueError(\"Invalid Posthoop signature\")\ntimestamp, supplied = match.groups()\nif abs(int(time.time()) - int(timestamp)) > 300:\n    raise ValueError(\"Invalid Posthoop signature\")\nsigned = (timestamp + \".\" + raw).encode(\"utf-8\")\nexpected = hmac.new(secret.encode(\"utf-8\"), signed, hashlib.sha256).hexdigest()\nif not hmac.compare_digest(expected, supplied):\n    raise ValueError(\"Invalid Posthoop signature\")\nevent = json.loads(raw)\ndata = event.get(\"data\", {})\nreturn {\n    \"type\": event[\"type\"],\n    \"eventId\": event[\"id\"],\n    \"postId\": data.get(\"postId\") or \"\",\n    \"targetId\": data.get(\"targetId\") or \"\",\n    \"url\": data.get(\"externalUrl\") or \"\",\n}","input":[{"name":"raw","value":"{{1.json}}"},{"name":"signature","value":"{{first(map(1.`__IMTHEADERS__`; value; name; posthoop-signature))}}"},{"name":"secret","value":"REPLACE_WITH_SIGNING_SECRET"}]},"parameters":{},"metadata":{"designer":{"x":300,"y":0}}},{"id":3,"module":"gateway:WebhookRespond","version":1,"mapper":{"status":"204","body":"","headers":[]},"parameters":{},"metadata":{"designer":{"x":600,"y":0}}},{"id":4,"module":"http:ActionSendData","version":3,"mapper":{"url":"https://hooks.slack.com/services/REPLACE/REPLACE/REPLACE","method":"post","headers":[],"bodyType":"raw","contentType":"custom","customType":"application/json","data":"{\"text\":\"Published: {{escapeJSON(ifempty(2.result.url; 2.result.postId))}}\"}","parseResponse":false,"followRedirect":false,"followAllRedirects":false,"shareCookies":false,"gzip":true},"parameters":{"handleErrors":true},"filter":{"name":"Published events only","conditions":[[{"a":"{{2.result.type}}","b":"post.target.published","o":"text:equal"}]]},"metadata":{"designer":{"x":900,"y":0}}}],"metadata":{"version":1,"instant":true,"scenario":{"roundtrips":1,"maxErrors":3,"autoCommit":true,"autoCommitTriggerLast":true,"sequential":false,"confidential":true,"dataloss":false,"dlq":false,"freshVariables":false},"designer":{"orphans":[]}}}