{"name":"Log published posts in Airtable","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://api.airtable.com/v0/REPLACE_BASE_ID/REPLACE_TABLE_ID","method":"patch","headers":[{"name":"Authorization","value":"Bearer YOUR_AIRTABLE_TOKEN"}],"bodyType":"raw","contentType":"custom","customType":"application/json","data":"{\"performUpsert\":{\"fieldsToMergeOn\":[\"Event ID\"]},\"records\":[{\"fields\":{\"Event ID\":\"{{escapeJSON(2.result.eventId)}}\",\"Post ID\":\"{{escapeJSON(2.result.postId)}}\",\"Target ID\":\"{{escapeJSON(2.result.targetId)}}\",\"Post URL\":\"{{escapeJSON(2.result.url)}}\"}}]}","parseResponse":true,"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":[]}}}