{
  "name": "Silver Arrows: text your n8n agent",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "arrow",
        "responseMode": "responseNode",
        "options": {
          "rawBody": true
        }
      },
      "id": "9a1f6c2e-0b1d-4c3a-9e7f-1a2b3c4d5e01",
      "name": "Silver Arrows webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "webhookId": "5c8e1d7a-2f3b-4a6c-8d9e-0f1a2b3c4d5e"
    },
    {
      "parameters": {
        "jsCode": "// Checks X-Arrow-Signature so only Silver Arrows can start this workflow.\n// Enable this node after setting ARROW_WEBHOOK_SECRET (n8n Variables, or an env var on self-hosted;\n// self-hosted also needs NODE_FUNCTION_ALLOW_BUILTIN=crypto).\nconst crypto = require('crypto');\nconst secret = (typeof $vars !== 'undefined' && $vars.ARROW_WEBHOOK_SECRET) || $env.ARROW_WEBHOOK_SECRET;\nif (!secret) throw new Error('Set ARROW_WEBHOOK_SECRET first');\nconst item = $input.first();\nconst header = String(item.json.headers['x-arrow-signature'] || '').trim();\n// The webhook's Raw Body option keeps the exact bytes we signed in binary property \"data\".\nconst raw = await this.helpers.getBinaryDataBuffer(0, 'data');\nconst expected = 'sha256=' + crypto.createHmac('sha256', secret).update(raw).digest('hex');\nconst a = Buffer.from(expected);\nconst b = Buffer.from(header);\nif (a.length !== b.length || !crypto.timingSafeEqual(a, b)) {\n  throw new Error('Bad Silver Arrows signature');\n}\nreturn $input.all();"
      },
      "id": "9a1f6c2e-0b1d-4c3a-9e7f-1a2b3c4d5e05",
      "name": "Verify signature",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        0
      ],
      "disabled": true,
      "notes": "Optional but recommended. Disabled nodes pass data straight through; enable it once ARROW_WEBHOOK_SECRET is set.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "{\"reply\": \"__async__\"}",
        "options": {
          "responseCode": 200
        }
      },
      "id": "9a1f6c2e-0b1d-4c3a-9e7f-1a2b3c4d5e02",
      "name": "Respond __async__",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "b7c1e0f2-3a4d-4e5f-8a9b-0c1d2e3f4a01",
              "name": "reply",
              "type": "string",
              "value": "=You said: {{ $('Silver Arrows webhook').item.json.body.message.body }}"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "id": "9a1f6c2e-0b1d-4c3a-9e7f-1a2b3c4d5e03",
      "name": "Your agent logic",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        660,
        0
      ],
      "notes": "Replace this node with your agent (AI Agent, OpenAI, HTTP calls...). It must output a field named reply: plain text, under 320 characters.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://silverarrows.dev/v1/lines/{{ $('Silver Arrows webhook').item.json.body.line_id }}/reply",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_SA_LIVE_KEY"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ conversation_id: $('Silver Arrows webhook').item.json.body.conversation_id, body: $json.reply, in_reply_to: $('Silver Arrows webhook').item.json.body.message.id }) }}",
        "options": {
          "timeout": 10000
        }
      },
      "id": "9a1f6c2e-0b1d-4c3a-9e7f-1a2b3c4d5e04",
      "name": "Reply via Silver Arrows",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        0
      ]
    }
  ],
  "connections": {
    "Silver Arrows webhook": {
      "main": [
        [
          {
            "node": "Verify signature",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Respond __async__": {
      "main": [
        [
          {
            "node": "Your agent logic",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Your agent logic": {
      "main": [
        [
          {
            "node": "Reply via Silver Arrows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify signature": {
      "main": [
        [
          {
            "node": "Respond __async__",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "active": false
}
