{
  "name": "Run from Barncleuth",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "barncleuth-run",
        "responseMode": "onReceived",
        "options": {}
      },
      "name": "Task from Barncleuth",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [-720, 0],
      "webhookId": "barncleuth-run"
    },
    {
      "parameters": {
        "jsCode": "// The board signs each task: x-barncleuth-signature is t=<seconds>,v1=<hex HMAC-SHA256 of '<t>.<body>'>.\n// This lines the parts up for the Crypto node, which checks it with your signing secret.\nconst input = $input.first().json;\nconst header = String(input.headers['x-barncleuth-signature'] || '');\nconst parts = Object.fromEntries(header.split(',').map((part) => part.split('=')));\nreturn [{ json: { ...input.body, t: Number(parts.t || 0), given: String(parts.v1 || ''), signed: `${parts.t}.${JSON.stringify(input.body)}` } }];"
      },
      "name": "Line up the signature",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-480, 0]
    },
    {
      "parameters": {
        "action": "hmac",
        "type": "SHA256",
        "value": "={{ $json.signed }}",
        "dataPropertyName": "expected",
        "secret": "PASTE_THE_SIGNING_SECRET_FROM_THE_BOARD",
        "encoding": "hex"
      },
      "name": "Sign it with your secret",
      "type": "n8n-nodes-base.crypto",
      "typeVersion": 1,
      "position": [-240, 0]
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose" },
          "conditions": [
            {
              "leftValue": "={{ $json.expected }}",
              "rightValue": "={{ $json.given }}",
              "operator": { "type": "string", "operation": "equals" }
            },
            {
              "leftValue": "={{ Math.abs(Date.now() / 1000 - $json.t) }}",
              "rightValue": 300,
              "operator": { "type": "number", "operation": "lt" }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "name": "From the board, and fresh?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [0, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('From the board, and fresh?').item.json.reply_url }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={ \"status\": \"working\", \"note\": \"Started in n8n\" }",
        "options": {}
      },
      "name": "Say: working",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [240, -100]
    },
    {
      "parameters": {},
      "name": "Do the work (put your steps here)",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [480, -100]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('From the board, and fresh?').item.json.reply_url }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={ \"status\": \"done\", \"note\": \"Done in n8n: {{ $('From the board, and fresh?').item.json.title }}\" }",
        "options": {}
      },
      "name": "Say: done",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [720, -100]
    },
    {
      "parameters": {},
      "name": "Not from the board: stop",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [240, 120]
    }
  ],
  "connections": {
    "Task from Barncleuth": { "main": [[{ "node": "Line up the signature", "type": "main", "index": 0 }]] },
    "Line up the signature": { "main": [[{ "node": "Sign it with your secret", "type": "main", "index": 0 }]] },
    "Sign it with your secret": { "main": [[{ "node": "From the board, and fresh?", "type": "main", "index": 0 }]] },
    "From the board, and fresh?": {
      "main": [
        [{ "node": "Say: working", "type": "main", "index": 0 }],
        [{ "node": "Not from the board: stop", "type": "main", "index": 0 }]
      ]
    },
    "Say: working": { "main": [[{ "node": "Do the work (put your steps here)", "type": "main", "index": 0 }]] },
    "Do the work (put your steps here)": { "main": [[{ "node": "Say: done", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" },
  "pinData": {}
}
