{
  "name": "ManageCallAI - Voicemail Received",
  "meta": {
    "templateId": "managecallai-voicemail-received",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "e0020000-0002-0002-0002-000000000001",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        300
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "managecall-voicemail",
        "responseMode": "onReceived",
        "options": {
          "rawBody": true
        }
      },
      "notes": "Subscribe to: voicemail.recording_available"
    },
    {
      "id": "e0020000-0002-0002-0002-000000000002",
      "name": "Verify Signature",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        300
      ],
      "parameters": {
        "jsCode": "const crypto = require('crypto');\nconst item = $input.first().json;\nconst h = item.headers ?? {};\nconst ts = parseInt(h['x-managecall-timestamp'] ?? '0', 10);\nif (Math.abs(Date.now() / 1000 - ts) > 300) throw new Error('timestamp_expired');\nconst body = typeof item.body === 'string' ? item.body : JSON.stringify(item.body ?? {});\nconst expected = 'sha256=' + crypto.createHmac('sha256', $env.MANAGECALL_WEBHOOK_SECRET).update(`${ts}.${body}`).digest('hex');\nif (!crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(h['x-managecall-signature-256'] ?? ''))) throw new Error('invalid_signature');\nreturn $input.all();"
      }
    },
    {
      "id": "e0020000-0002-0002-0002-000000000003",
      "name": "Create Ticket",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        680,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $env.VOICEMAIL_TICKET_URL }}",
        "sendBody": true,
        "contentType": "json",
        "body": {
          "tenant_id": "={{ $json.body.tenant_id }}",
          "event_id": "={{ $json.body.event_id }}",
          "mailbox_number": "={{ $json.body.data.mailbox_number }}",
          "recording_id": "={{ $json.body.data.recording_id }}",
          "received_at": "={{ $json.body.timestamp }}"
        }
      }
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Verify Signature",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify Signature": {
      "main": [
        [
          {
            "node": "Create Ticket",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e0020000-0002-0002-0002-000000000099"
}