{
  "name": "Meteor IA: receive messages with a verified signature",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "meteor-ia",
        "options": {
          "rawBody": true
        }
      },
      "id": "00000000-0000-4000-8000-000000000011",
      "name": "Meteor IA messages",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "webhookId": "00000000-0000-4000-8000-000000000019"
    },
    {
      "parameters": {
        "jsCode": "const crypto = require('crypto');\n\nconst secreto = 'PASTE_YOUR_WHSEC_HERE'; // the secret returned by POST /webhook-endpoints\nconst cabecera = $input.first().json.headers['x-met-signature'] ?? '';\nconst crudo = (await this.helpers.getBinaryDataBuffer(0, 'data')).toString('utf8');\n\nconst partes = cabecera.split(',').map((p) => p.trim().split('='));\nconst t = Number(partes.find(([k]) => k === 't')?.[1]);\nif (!t || Math.abs(Date.now() / 1000 - t) > 300) throw new Error('Meteor IA signature missing or expired');\n\nconst esperada = Buffer.from(\n  crypto.createHmac('sha256', secreto).update(`${t}.${crudo}`).digest('hex'),\n);\nconst valida = partes\n  .filter(([k]) => k === 'v1')\n  .map(([, v]) => Buffer.from(v ?? ''))\n  .some((v) => v.length === esperada.length && crypto.timingSafeEqual(v, esperada));\nif (!valida) throw new Error('Invalid Meteor IA signature');\n\nreturn [{ json: JSON.parse(crudo) }];"
      },
      "id": "00000000-0000-4000-8000-000000000012",
      "name": "Verify X-Met-Signature",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        0
      ]
    },
    {
      "parameters": {},
      "id": "00000000-0000-4000-8000-000000000013",
      "name": "Your logic here",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        480,
        0
      ]
    },
    {
      "parameters": {},
      "id": "00000000-0000-4000-8000-000000000014",
      "name": "Run once to subscribe",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        260
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.met.meteor.com.co/api/v1/webhook-endpoints",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{\n  \"url\": \"PASTE_THE_WEBHOOK_PRODUCTION_URL_HERE\",\n  \"enabled_events\": [\n    \"contact.message.received\"\n  ]\n}",
        "options": {}
      },
      "id": "00000000-0000-4000-8000-000000000015",
      "name": "Subscribe this URL in Meteor IA",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        240,
        260
      ]
    },
    {
      "parameters": {
        "content": "## Receive Meteor IA messages\n\n1. Publish the workflow and copy the Webhook node production URL.\n2. Paste it into the «Subscribe this URL in Meteor IA» node and run it once with your Bearer Auth credential (scope `webhooks:manage`; to receive the event, `conversations:read`).\n3. The response carries `data.secret` (`whsec_…`) only once: paste it into the Code node.\n4. On n8n Cloud the `crypto` module is available; if you self-host n8n, enable Code node modules.\n5. The secret stays written in the Code node: do not share or export this workflow with the secret pasted in.",
        "height": 300,
        "width": 460
      },
      "id": "00000000-0000-4000-8000-000000000016",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        440
      ]
    }
  ],
  "connections": {
    "Meteor IA messages": {
      "main": [
        [
          {
            "node": "Verify X-Met-Signature",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify X-Met-Signature": {
      "main": [
        [
          {
            "node": "Your logic here",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run once to subscribe": {
      "main": [
        [
          {
            "node": "Subscribe this URL in Meteor IA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
