{
  "name": "Tuco AI — iMessage Automation (Send, Replies, Fallback)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "tuco-reply-received",
        "options": {}
      },
      "id": "f1ed7a25-417a-4c9f-8fe5-906565a85744",
      "name": "Webhook — Receive iMessage",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1.1,
      "position": [
        0,
        192
      ],
      "webhookId": "7d2e9b4a-1c5f-4a7b-8e30-1b2c3d4e5f6a"
    },
    {
      "parameters": {
        "url": "=https://app.tuco.ai/api/lines/by-user",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "options": {}
      },
      "id": "0b3affda-bd96-440e-a049-397b12394ef7",
      "name": "Get Lines",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        736,
        656
      ],
      "disabled": true,
      "credentials": {
        "httpBearerAuth": {
          "name": "Tuco AI API Key (Bearer tuco_...)"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://app.tuco.ai/api/messages",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"message\": \"{{ $('Map Message and Contact Info').item.json.message }}\",\n  \"leadId\": \"{{ $json.body.leadIds[0] }}\",\n  \"fromLineId\": \"{{ $('Map Message and Contact Info').item.json.lineId }}\"\n}",
        "options": {}
      },
      "id": "80d15d4d-fe60-48f0-8179-51073c13dbdd",
      "name": "Send Step 1 — Opening Text",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1320,
        0
      ],
      "credentials": {
        "httpBearerAuth": {
          "name": "Tuco AI API Key (Bearer tuco_...)"
        }
      },
      "notesInFlow": true,
      "notes": "PLAIN TEXT ONLY — no attachments AND no links in the first message to a contact. Tuco defers attachments on a first-ever outbound (new-conversation guard) and bare links in an opener hurt deliverability. Files and links belong in step 2 onward."
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://app.tuco.ai/api/leads",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {}
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"leads\": [\n    { \"firstName\": \"{{ $('Map Message and Contact Info').item.json.firstName }}\", \"lastName\": \"{{ $('Map Message and Contact Info').item.json.lastName }}\", \"email\": \"{{ $('Map Message and Contact Info').item.json.email }}\", \"phone\": \"{{ $('Map Message and Contact Info').item.json.phone }}\", \"companyName\": \"{{ $('Map Message and Contact Info').item.json.companyName }}\", \"customFields\": { \"bookingLink\": \"{{ $('Map Message and Contact Info').item.json.bookingLink }}\" }}\n  ], \n  \"source\": \"n8n\"\n}",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "responseFormat": "json"
            }
          }
        }
      },
      "id": "c4bb3c9f-2b55-4d71-b448-2db57f18c9a3",
      "name": "Create Lead",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1100,
        0
      ],
      "alwaysOutputData": true,
      "credentials": {
        "httpBearerAuth": {
          "name": "Tuco AI API Key (Bearer tuco_...)"
        }
      }
    },
    {
      "parameters": {
        "url": "=https://app.tuco.ai/api/leads?search=bg",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "options": {}
      },
      "id": "bc69378a-9530-48fb-90b1-7954b7448144",
      "name": "Search for Lead",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        656
      ],
      "disabled": true,
      "credentials": {
        "httpBearerAuth": {
          "name": "Tuco AI API Key (Bearer tuco_...)"
        }
      }
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "tuco-imessage-fallback",
        "options": {}
      },
      "id": "ff6b2446-2aa3-460b-84ea-ef83aca963c4",
      "name": "Webhook — Message Fallback",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1.1,
      "position": [
        0,
        384
      ],
      "webhookId": "5c3d8a2b-0e4a-4b6c-7d19-2c3d4e5f6a7b"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "tuco-send-imessage",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        0,
        0
      ],
      "id": "fb408474-1022-4da5-95b0-2b4dc6d6c696",
      "name": "Webhook — Send iMessage",
      "webhookId": "9e1f0a3c-4b6d-4c8e-9f21-0a1b2c3d4e5f"
    },
    {
      "parameters": {
        "url": "https://app.tuco.ai/api/replies",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "leadId",
              "value": "={{ $json.message.leadId }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        976,
        656
      ],
      "id": "ddaaab31-1366-4863-a82b-8927cf0af1ae",
      "name": "Check Replies",
      "disabled": true,
      "credentials": {
        "httpBearerAuth": {
          "name": "Tuco AI API Key (Bearer tuco_...)"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "reply-a0",
              "name": "leadId",
              "value": "={{ $json.body.leadId }}",
              "type": "string"
            },
            {
              "id": "reply-a1",
              "name": "phone",
              "value": "={{ $json.body.phone }}",
              "type": "string"
            },
            {
              "id": "reply-a2",
              "name": "replyText",
              "value": "={{ $json.body.message }}",
              "type": "string"
            },
            {
              "id": "reply-a3",
              "name": "attachmentDownloadUrls",
              "value": "={{ $json.body.attachmentDownloadUrls ?? [] }}",
              "type": "array"
            }
          ]
        },
        "options": {}
      },
      "id": "fcced9e4-afd4-4ebc-95ce-465a9fc705bd",
      "name": "Map Tuco Reply (EDIT ME)",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        192
      ],
      "notesInFlow": true,
      "notes": "A lead replied — text AND photos/files. attachmentDownloadUrls are public signed links (30-day) that stream the real bytes; raw attachmentUrls are private blobs that 403 to API keys, so always fetch the download URLs. Wire into your CRM, Slack, or storage."
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "fb-a0",
              "name": "leadId",
              "value": "={{ $json.body.leadId }}",
              "type": "string"
            },
            {
              "id": "fb-a1",
              "name": "phone",
              "value": "={{ $json.body.lead.phone }}",
              "type": "string"
            },
            {
              "id": "fb-a2",
              "name": "failedMessage",
              "value": "={{ $json.body.message.message }}",
              "type": "string"
            },
            {
              "id": "fb-a3",
              "name": "reason",
              "value": "={{ $json.body.data.reason }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "1179bb5f-d9af-4b89-a6c9-b651c7be60d0",
      "name": "Map Fallback (EDIT ME)",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        384
      ],
      "notesInFlow": true,
      "notes": "iMessage wasn't available for this contact. Send the text via your SMS provider or log it for manual follow-up."
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "11111111-1111-4111-8111-111111111111-a0",
              "name": "message",
              "value": "={{ $json.body.customData.message }}",
              "type": "string"
            },
            {
              "id": "11111111-1111-4111-8111-111111111111-a1",
              "name": "firstName",
              "value": "={{ $json.body.first_name }}",
              "type": "string"
            },
            {
              "id": "11111111-1111-4111-8111-111111111111-a2",
              "name": "lastName",
              "value": "={{ $json.body?.last_name ?? \"\" }}",
              "type": "string"
            },
            {
              "id": "11111111-1111-4111-8111-111111111111-a3",
              "name": "email",
              "value": "={{ $json.body.email }}",
              "type": "string"
            },
            {
              "id": "11111111-1111-4111-8111-111111111111-a4",
              "name": "phone",
              "value": "={{ $json.body.phone }}",
              "type": "string"
            },
            {
              "id": "map-vn",
              "name": "voiceNoteUrl",
              "value": "https://example.com/voice-note.mp3",
              "type": "string"
            },
            {
              "id": "map-fu",
              "name": "followupText",
              "value": "Just circling back — any thoughts?",
              "type": "string"
            },
            {
              "id": "map-line",
              "name": "lineId",
              "value": "",
              "type": "string"
            },
            {
              "id": "map-co",
              "name": "companyName",
              "value": "={{ $json.body.company ?? \"\" }}",
              "type": "string"
            },
            {
              "id": "map-book",
              "name": "bookingLink",
              "value": "={{ $json.body.booking_link ?? \"\" }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "f96fc9fc-0ef6-4dfb-aae3-969db8e2d7fd",
      "name": "Map Message and Contact Info",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        224,
        0
      ],
      "notesInFlow": true,
      "notes": "Map YOUR fields here. phone MUST be E.164 (+14155551234) — the gate below rejects anything else. First message rule: text only, no attachments, no links. companyName/bookingLink show standard + custom fields flowing into the lead. lineId optional ('' = auto); steps 2-3 reuse step 1's actual line."
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "tuco-ai-draft-created",
        "options": {}
      },
      "id": "b8d4e6f0-5a7c-4d9e-8b21-3c4d5e6f7a8b",
      "name": "Webhook — AI Draft Created",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1.1,
      "position": [
        0,
        576
      ],
      "webhookId": "4a5b6c7d-8e9f-4a0b-9c1d-2e3f4a5b6c7d"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "draft-a0",
              "name": "replyId",
              "value": "={{ $json.body.data.replyId }}",
              "type": "string"
            },
            {
              "id": "draft-a1",
              "name": "draftText",
              "value": "={{ $json.body.message }}",
              "type": "string"
            },
            {
              "id": "draft-a2",
              "name": "inboundText",
              "value": "={{ $json.body.data.inboundText }}",
              "type": "string"
            },
            {
              "id": "draft-a3",
              "name": "recipient",
              "value": "={{ $json.body.data.conversationRecipient }}",
              "type": "string"
            },
            {
              "id": "draft-a4",
              "name": "confidence",
              "value": "={{ $json.body.data.confidence }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "d0e2f4a6-7b9c-4e1d-8f30-4d5e6f7a8b9c",
      "name": "Map AI Draft (EDIT ME)",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        576
      ],
      "notesInFlow": true,
      "notes": "Tuco's AI drafted a reply for review. Route it into your approval flow (Slack, email, dashboard), then POST replyId back to approve."
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://app.tuco.ai/api/knowledge-base/auto-replies",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"replyId\": \"{{ $json.replyId }}\",\n  \"action\": \"approve\"\n}",
        "options": {}
      },
      "id": "e2f4a6b8-9c0d-4f2e-8a41-5e6f7a8b9c0d",
      "name": "Approve & Send Draft",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        480,
        576
      ],
      "disabled": true,
      "notesInFlow": true,
      "notes": "DISABLED on purpose: as wired it would approve EVERY draft instantly. Add your human-approval step first, then enable. action can also be 'reject'.",
      "credentials": {
        "httpBearerAuth": {
          "name": "Tuco AI API Key (Bearer tuco_...)"
        }
      }
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "tuco-message-failed",
        "options": {}
      },
      "id": "a1c3e5f7-2b4d-4c6e-8d90-6f7a8b9c0d1e",
      "name": "Webhook — Message Failed",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1.1,
      "position": [
        0,
        768
      ],
      "webhookId": "3b4c5d6e-7f8a-4b9c-8d01-3e4f5a6b7c8d"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "failed-a0",
              "name": "leadId",
              "value": "={{ $json.body.leadId }}",
              "type": "string"
            },
            {
              "id": "failed-a1",
              "name": "phone",
              "value": "={{ $json.body.lead.phone }}",
              "type": "string"
            },
            {
              "id": "failed-a2",
              "name": "failedMessage",
              "value": "={{ $json.body.message.message }}",
              "type": "string"
            },
            {
              "id": "failed-a3",
              "name": "reason",
              "value": "={{ $json.body.data.reason }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "c2d4e6f8-3a5b-4d7c-9e01-7a8b9c0d1e2f",
      "name": "Map Failed (EDIT ME)",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        768
      ],
      "notesInFlow": true,
      "notes": "Technical send failure (server/network) — different from fallback (no iMessage on the number). Alert your team or retry via another channel."
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "tuco-ai-draft-resolved",
        "options": {}
      },
      "id": "f3a5b7c9-4d6e-4f8a-9b02-8c9d0e1f2a3b",
      "name": "Webhook — Draft Approved / Rejected",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1.1,
      "position": [
        0,
        960
      ],
      "webhookId": "2a3b4c5d-6e7f-4a8b-9c00-4d5e6f7a8b9c"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "resolved-a0",
              "name": "event",
              "value": "={{ $json.body.event }}",
              "type": "string"
            },
            {
              "id": "resolved-a1",
              "name": "replyId",
              "value": "={{ $json.body.data.replyId }}",
              "type": "string"
            },
            {
              "id": "resolved-a2",
              "name": "draftText",
              "value": "={{ $json.body.message }}",
              "type": "string"
            },
            {
              "id": "resolved-a3",
              "name": "recipient",
              "value": "={{ $json.body.data.conversationRecipient }}",
              "type": "string"
            },
            {
              "id": "resolved-a4",
              "name": "approvalChannel",
              "value": "={{ $json.body.data.approvalChannel }}",
              "type": "string"
            },
            {
              "id": "resolved-a5",
              "name": "approvedBy",
              "value": "={{ $json.body.data.approvedBy }}",
              "type": "string"
            },
            {
              "id": "resolved-a6",
              "name": "rejectedReason",
              "value": "={{ $json.body.data.rejectedReason }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "a4b6c8d0-5e7f-4a9b-8c13-9d0e1f2a3b4c",
      "name": "Map Draft Resolution (EDIT ME)",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        960
      ],
      "notesInFlow": true,
      "notes": "Fires for BOTH message.ai_draft_approved and message.ai_draft_rejected (subscribe one URL to both). Branch on `event`; approvalChannel says who actioned it (dashboard, telegram, api, unibox_direct_send)."
    },
    {
      "parameters": {
        "url": "https://app.tuco.ai/api/check-availability",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "address",
              "value": "={{ $json.phone }}"
            }
          ]
        },
        "options": {}
      },
      "id": "11aa22bb-33cc-44dd-8ee0-aabbccddee01",
      "name": "Check iMessage Availability",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        0
      ],
      "notesInFlow": true,
      "notes": "Verifies the number can receive iMessage BEFORE creating the lead or sending.",
      "credentials": {
        "httpBearerAuth": {
          "name": "Tuco AI API Key (Bearer tuco_...)"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "cond-available",
              "leftValue": "={{ $json.available }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "11aa22bb-33cc-44dd-8ee0-aabbccddee02",
      "name": "Has iMessage?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        880,
        0
      ],
      "notesInFlow": true,
      "notes": "FALSE branch is open — wire it to your SMS provider or CRM note."
    },
    {
      "parameters": {
        "amount": 1,
        "unit": "days"
      },
      "id": "11aa22bb-33cc-44dd-8ee0-aabbccddee03",
      "name": "Wait 1 Day",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1540,
        0
      ],
      "webhookId": "8f0a1b2c-3d4e-4f5a-9b6c-7d8e9f0a1b2c"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://app.tuco.ai/api/messages",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"message\": \"\",\n  \"leadId\": \"{{ $json.leadId }}\",\n  \"attachmentUrls\": [\"{{ $('Map Message and Contact Info').item.json.voiceNoteUrl }}\"],\n  \"voiceNote\": true,\n  \"skipIfReplied\": true,\n  \"fromLineId\": \"{{ $('Send Step 1 — Opening Text').item.json.message.fromLineId }}\"\n}",
        "options": {}
      },
      "id": "11aa22bb-33cc-44dd-8ee0-aabbccddee04",
      "name": "Send Step 2 — Voice Note (skips if replied)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1760,
        0
      ],
      "notesInFlow": true,
      "notes": "First step where attachments are allowed (a conversation now exists). Audio URL is delivered as a native iMessage voice note. skipIfReplied:true suppresses this step when the lead already replied. Sends from the SAME line step 1 used.",
      "credentials": {
        "httpBearerAuth": {
          "name": "Tuco AI API Key (Bearer tuco_...)"
        }
      }
    },
    {
      "parameters": {
        "amount": 1,
        "unit": "days"
      },
      "id": "11aa22bb-33cc-44dd-8ee0-aabbccddee05",
      "name": "Wait 1 More Day",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1980,
        0
      ],
      "webhookId": "9a1b2c3d-4e5f-4a6b-8c7d-8e9f0a1b2c3d"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://app.tuco.ai/api/messages",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"message\": \"{{ $('Map Message and Contact Info').item.json.followupText }}\",\n  \"leadId\": \"{{ $('Send Step 1 — Opening Text').item.json.leadId }}\",\n  \"skipIfReplied\": true,\n  \"fromLineId\": \"{{ $('Send Step 1 — Opening Text').item.json.message.fromLineId }}\"\n}",
        "options": {}
      },
      "id": "11aa22bb-33cc-44dd-8ee0-aabbccddee06",
      "name": "Send Step 3 — Follow-up Text (skips if replied)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2200,
        0
      ],
      "notesInFlow": true,
      "notes": "Final nudge — same line as steps 1-2, skipped automatically once the lead replies.",
      "credentials": {
        "httpBearerAuth": {
          "name": "Tuco AI API Key (Bearer tuco_...)"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "cond-e164",
              "leftValue": "={{ $json.phone }}",
              "rightValue": "^\\+[1-9]\\d{7,14}$",
              "operator": {
                "type": "string",
                "operation": "regex"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "11aa22bb-33cc-44dd-8ee0-aabbccddee07",
      "name": "Valid E.164 Phone?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        440,
        0
      ],
      "notesInFlow": true,
      "notes": "Only E.164 passes (+14155551234 — plus sign, country code, digits only, no spaces). The Tuco API rejects other formats; fix formatting in the Map node."
    }
  ],
  "pinData": {
    "Get Lines": [
      {
        "json": {
          "lines": [
            {
              "_id": "699f704bc405fae6ca299a08",
              "workspaceId": "org_SampleWorkspaceA00000000",
              "createdByUserId": "user_SampleUserA000000000000",
              "phone": "+15550100200",
              "email": "line-owner@example.com",
              "firstName": "Alex",
              "lastName": "Morgan",
              "profileImageUrl": null,
              "isActive": true,
              "provisioningStatus": "active",
              "provisioningSubmittedAt": "2026-02-25T21:57:31.276Z",
              "estimatedReadyAt": "27-FEB-2026",
              "lineType": "byon",
              "dailyNewConversationsLimit": 20,
              "dailyTotalMessagesLimit": 50,
              "healthCheck": {
                "status": "healthy",
                "lastCheckedAt": "2026-03-01T20:52:00.097Z",
                "failures": [],
                "sendEmailOnNextDown": true,
                "lastHealthyAt": "2026-03-01T20:52:00.097Z",
                "consecutiveFailures": 0,
                "emailSentForLineDown": false,
                "firstFailureAt": null,
                "waitUntil": null
              },
              "hasPrivateApi": false,
              "createdAt": "2026-02-25T21:57:31.276Z",
              "updatedAt": "2026-03-01T20:52:04.622Z",
              "usage": {
                "date": "2026-03-01",
                "newContactsCount": 4,
                "messagesSentCount": 8,
                "totalMessagesCount": 11
              }
            }
          ]
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "Search for Lead": [
      {
        "json": {
          "leads": [
            {
              "_id": "69a2e8e6c580cf046a551fde",
              "firstName": "Tuco test",
              "lastName": null,
              "email": "bg@tuco.ai",
              "phone": null,
              "altPhone1": null,
              "altPhone2": null,
              "altPhone3": null,
              "altEmail1": null,
              "altEmail2": null,
              "altEmail3": null,
              "listId": "69a1fc43a00b806f643082df",
              "workspaceId": "org_SampleWorkspaceA00000000",
              "createdByUserId": "user_SampleUserA000000000000",
              "source": "api",
              "createdAt": "2026-02-28T13:08:54.421Z",
              "updatedAt": "2026-02-28T13:08:54.421Z"
            }
          ],
          "lists": [
            {
              "_id": "69a1fc43a00b806f643082df",
              "name": "Quick Sends",
              "description": "Quick send messages",
              "workspaceId": "org_SampleWorkspaceA00000000",
              "createdByUserId": "user_SampleUserA000000000000",
              "leadCount": 2,
              "createdAt": "2026-02-27T20:19:15.930Z",
              "updatedAt": "2026-03-01T22:13:29.337Z"
            }
          ],
          "pagination": {
            "page": 1,
            "limit": 50,
            "totalCount": 1,
            "totalPages": 1
          }
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "Webhook — Receive iMessage": [
      {
        "json": {
          "headers": {
            "host": "your-n8n.example.com",
            "user-agent": "node",
            "content-length": "2423",
            "accept": "*/*",
            "accept-encoding": "br, gzip, deflate",
            "accept-language": "*",
            "content-type": "application/json",
            "sec-fetch-mode": "cors",
            "x-forwarded-for": "203.0.113.10",
            "x-forwarded-host": "your-n8n.example.com",
            "x-forwarded-proto": "https",
            "x-railway-edge": "iad1",
            "x-railway-request-id": "SAMPLE-REQUEST-ID",
            "x-real-ip": "203.0.113.10",
            "x-request-start": "1773350326876",
            "x-tuco-event": "message.reply",
            "x-tuco-signature": "hmac-sha256-of-raw-body-using-your-webhook-secret",
            "x-tuco-timestamp": "2026-03-12T21:18:46.866Z"
          },
          "params": {},
          "query": {},
          "body": {
            "event": "message.reply",
            "timestamp": "2026-03-12T21:18:46.866Z",
            "workspaceId": "org_SampleWorkspaceB00000000",
            "leadId": "69b2c41d352a78479d2c623b",
            "lead": {
              "_id": "69b2c41d352a78479d2c623b",
              "firstName": "BG",
              "lastName": "Tuco",
              "email": "bg@tuco.ai",
              "phone": "+919042956129",
              "altPhone1": null,
              "altPhone2": null,
              "altPhone3": null,
              "altEmail1": null,
              "altEmail2": null,
              "altEmail3": null,
              "companyName": null,
              "jobTitle": null,
              "linkedinUrl": null,
              "notes": null,
              "customFields": null,
              "availabilityStatus": "available",
              "availabilityCheckedAt": "2026-03-12T13:48:13.154Z",
              "listId": "69ab444ac1feb77d7f46462f",
              "workspaceId": "org_SampleWorkspaceB00000000",
              "contactOwnerId": "user_SampleUserB000000000000",
              "createdByUserId": "user_SampleUserB000000000000",
              "source": "gohighlevel",
              "createdAt": "2026-03-12T13:48:13.154Z",
              "updatedAt": "2026-03-12T21:00:23.116Z",
              "integrationIds": {
                "ghlRecordId": "SAMPLE_CRM_CONTACT_ID",
                "ghlLocationId": "SAMPLE_CRM_LOCATION_ID"
              },
              "contactIdentifiers": [
                "bg@tuco.ai",
                "+919042956129"
              ]
            },
            "messageId": "69b32db6cad37b94a846eeb8",
            "message": "Interested — here's a screenshot of what we use today",
            "firstName": "BG",
            "lastName": "Tuco",
            "phone": "+919042956129",
            "listId": "69ab444ac1feb77d7f46462f",
            "fromLineId": "69ab427ac1feb77d7f46462e",
            "recipientName": "BG Tuco",
            "repliedAtUtc": "2026-03-12T21:18:46.843Z",
            "parentMessages": [
              {
                "messageId": "69b32964cad37b94a846eeac",
                "message": "Quick follow-up on your request",
                "sentAtUtc": "2026-03-12T21:00:23.050Z",
                "batchId": null
              },
              {
                "messageId": "69b2dd535b8e8fac401e72d7",
                "message": "Hey — following up from our chat",
                "sentAtUtc": "2026-03-12T15:36:00.035Z",
                "batchId": null
              }
            ],
            "ghlContactId": "SAMPLE_CRM_CONTACT_ID",
            "ghlLocationId": "SAMPLE_CRM_LOCATION_ID",
            "hsPortalId": null,
            "hsContactId": null,
            "data": {
              "reply": {
                "leadId": "69b2c41d352a78479d2c623b",
                "messageId": "69b32db6cad37b94a846eeb8",
                "respondedAtUtc": "2026-03-12T21:18:46.843Z",
                "recipientPhone": "+919042956129",
                "name": "BG Tuco",
                "parentMessages": [
                  {
                    "messageId": "69b32964cad37b94a846eeac",
                    "message": "Quick follow-up on your request",
                    "sentAtUtc": "2026-03-12T21:00:23.050Z",
                    "batchId": null
                  },
                  {
                    "messageId": "69b2dd535b8e8fac401e72d7",
                    "message": "Hey — following up from our chat",
                    "sentAtUtc": "2026-03-12T15:36:00.035Z",
                    "batchId": null
                  }
                ],
                "recipientEmail": "bg@tuco.ai",
                "recentReplies": [
                  {
                    "messageId": "69b32db6cad37b94a846eeb8",
                    "message": "Interested — here's a screenshot of what we use today",
                    "receivedAtUtc": "2026-03-12T21:18:46.843Z"
                  }
                ],
                "attachmentUrls": [
                  "https://abc123private.private.blob.vercel-storage.com/inbound/screenshot-x7k2.jpeg"
                ],
                "attachmentDownloadUrls": [
                  "https://app.tuco.ai/api/attachments/crm-media/eyJrIjoiaW5ib3VuZC9zY3JlZW5zaG90LXg3azIuanBlZyJ9?exp=1775000000&sig=samplesignature"
                ],
                "attachmentNames": [
                  "screenshot.jpeg"
                ]
              },
              "repliedAtUtc": "2026-03-12T21:18:46.843Z",
              "parentMessages": [
                {
                  "messageId": "69b32964cad37b94a846eeac",
                  "message": "Quick follow-up on your request",
                  "sentAtUtc": "2026-03-12T21:00:23.050Z",
                  "batchId": null
                },
                {
                  "messageId": "69b2dd535b8e8fac401e72d7",
                  "message": "Hey — following up from our chat",
                  "sentAtUtc": "2026-03-12T15:36:00.035Z",
                  "batchId": null
                }
              ]
            },
            "attachmentUrls": [
              "https://abc123private.private.blob.vercel-storage.com/inbound/screenshot-x7k2.jpeg"
            ],
            "attachmentDownloadUrls": [
              "https://app.tuco.ai/api/attachments/crm-media/eyJrIjoiaW5ib3VuZC9zY3JlZW5zaG90LXg3azIuanBlZyJ9?exp=1775000000&sig=samplesignature"
            ],
            "attachmentNames": [
              "screenshot.jpeg"
            ],
            "contactOwnerEmail": null,
            "optedOut": false
          },
          "webhookUrl": "https://your-n8n.example.com/webhook/tuco-reply-received",
          "executionMode": "production"
        }
      }
    ],
    "Check Replies": [
      {
        "json": {
          "replies": [
            {
              "leadId": "69b2c41d352a78479d2c623b",
              "messageId": "69b340dd6dae1d942ece4d09",
              "message": "Sounds good, send it over",
              "respondedAtUtc": "2026-03-12T22:40:29.174Z",
              "recipientPhone": "+919042956129",
              "name": "BG Tuco",
              "hasReplied": true,
              "hasEverReplied": true,
              "recentReplies": [
                {
                  "messageId": "69b340dd6dae1d942ece4d09",
                  "message": "Sounds good, send it over",
                  "receivedAtUtc": "2026-03-12T22:40:29.174Z"
                }
              ],
              "parentMessages": [
                {
                  "messageId": "69b344bc6dae1d942ece4d0e",
                  "message": "Here’s your document.",
                  "sentAtUtc": "2026-03-12T22:57:02.892Z",
                  "batchId": null
                },
                {
                  "messageId": "69b340c86dae1d942ece4d07",
                  "message": "Quick follow-up on your request",
                  "sentAtUtc": "2026-03-12T22:40:10.909Z",
                  "batchId": null
                }
              ]
            }
          ],
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "Create Lead": [
      {
        "json": {
          "body": {
            "message": "Lead was a duplicate; existing lead ID returned.",
            "duplicateOnly": true,
            "duplicateCount": 1,
            "totalProcessed": 1,
            "leadId": "69b2c41d352a78479d2c623b",
            "existingLeadIds": [
              "69b2c41d352a78479d2c623b"
            ],
            "leadIds": [
              "69b2c41d352a78479d2c623b"
            ],
            "duplicates": [
              {
                "input": {
                  "firstName": "BG",
                  "lastName": "Tuco",
                  "email": "bg@tuco.ai",
                  "phone": "+919042956129"
                },
                "existingLead": {
                  "_id": "69b2c41d352a78479d2c623b",
                  "firstName": "BG",
                  "lastName": "Tuco",
                  "email": "bg@tuco.ai",
                  "phone": "+919042956129"
                }
              }
            ],
            "ghlContactId": "SAMPLE_CRM_CONTACT_ID",
            "ghlLocationId": "SAMPLE_CRM_LOCATION_ID",
            "hsPortalId": null,
            "hsContactId": null
          },
          "headers": {
            "content-type": "application/json",
            "date": "Fri, 13 Mar 2026 17:48:07 GMT",
            "server": "railway-edge",
            "vary": "rsc, next-router-state-tree, next-router-prefetch, next-router-segment-prefetch",
            "x-clerk-auth-message": "Invalid JWT form. A JWT consists of three parts separated by dots. (reason=token-invalid, token-carrier=header)",
            "x-clerk-auth-reason": "token-invalid",
            "x-clerk-auth-status": "signed-out",
            "x-middleware-rewrite": "/api/leads",
            "x-railway-edge": "railway/edge",
            "x-railway-request-id": "SAMPLE-REQUEST-ID",
            "connection": "close",
            "transfer-encoding": "chunked"
          },
          "statusCode": 200,
          "statusMessage": "OK"
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "Webhook — Send iMessage": [
      {
        "json": {
          "headers": {
            "host": "your-n8n.example.com",
            "user-agent": "axios/1.13.2",
            "content-length": "1399",
            "accept": "application/json, text/plain, */*",
            "accept-encoding": "gzip, compress, deflate, br",
            "content-type": "application/json",
            "traceparent": "00-00000000000000000000000000000000-0000000000000000-00",
            "x-forwarded-for": "203.0.113.12",
            "x-forwarded-host": "your-n8n.example.com",
            "x-forwarded-proto": "https",
            "x-railway-edge": "railway/edge",
            "x-railway-request-id": "SAMPLE-REQUEST-ID",
            "x-real-ip": "203.0.113.12",
            "x-request-start": "1773424379331"
          },
          "params": {},
          "query": {},
          "body": {
            "contact_id": "SAMPLE_CRM_CONTACT_ID",
            "first_name": "BG",
            "last_name": "Tuco",
            "full_name": "BG Tuco",
            "email": "bg@tuco.ai",
            "phone": "+919042956129",
            "country": "US",
            "contact_type": "lead",
            "customData": {
              "message": "Hey BG — thanks for reaching out! Want me to send over the details?"
            },
            "company": "Tuco AI",
            "booking_link": "https://tuco.ai/demo"
          },
          "webhookUrl": "https://your-n8n.example.com/webhook/tuco-send-imessage",
          "executionMode": "production"
        }
      }
    ],
    "Webhook — AI Draft Created": [
      {
        "json": {
          "headers": {
            "host": "your-n8n.example.com",
            "user-agent": "node",
            "content-type": "application/json",
            "x-tuco-event": "message.ai_draft",
            "x-tuco-signature": "hmac-sha256-of-raw-body-using-your-webhook-secret",
            "x-tuco-timestamp": "2026-03-12T21:20:02.114Z"
          },
          "params": {},
          "query": {},
          "body": {
            "event": "message.ai_draft",
            "timestamp": "2026-03-12T21:20:02.114Z",
            "workspaceId": "org_SampleWorkspaceB00000000",
            "leadId": "69b2c41d352a78479d2c623b",
            "lead": {
              "_id": "69b2c41d352a78479d2c623b",
              "firstName": "BG",
              "lastName": "Tuco",
              "email": "bg@tuco.ai",
              "phone": "+919042956129",
              "workspaceId": "org_SampleWorkspaceB00000000",
              "source": "n8n"
            },
            "message": "Sure — the onboarding call runs about 30 minutes and we can do Thursday 2pm. Want me to lock it in?",
            "ghlContactId": null,
            "ghlLocationId": null,
            "hsPortalId": null,
            "hsContactId": null,
            "data": {
              "replyId": "69b330a1cad37b94a846ef01",
              "draftMessage": "Sure — the onboarding call runs about 30 minutes and we can do Thursday 2pm. Want me to lock it in?",
              "conversationRecipient": "+919042956129",
              "inboundText": "How long is the onboarding call and when can we do it?",
              "inboundMessageId": "69b32db6cad37b94a846eeb8",
              "confidence": 0.92,
              "mode": "copilot",
              "approveEndpoint": "/api/knowledge-base/auto-replies",
              "ghlContactId": null,
              "ghlLocationId": null,
              "hsPortalId": null,
              "hsContactId": null
            },
            "contactOwnerEmail": null
          },
          "webhookUrl": "https://your-n8n.example.com/webhook/tuco-ai-draft-created",
          "executionMode": "production"
        }
      }
    ],
    "Approve & Send Draft": [
      {
        "json": {
          "success": true,
          "status": "approved"
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "Webhook — Message Fallback": [
      {
        "json": {
          "headers": {
            "host": "your-n8n.example.com",
            "user-agent": "node",
            "content-length": "2232",
            "accept": "*/*",
            "accept-encoding": "br, gzip, deflate",
            "accept-language": "*",
            "content-type": "application/json",
            "sec-fetch-mode": "cors",
            "x-forwarded-for": "203.0.113.11",
            "x-forwarded-host": "your-n8n.example.com",
            "x-forwarded-proto": "https",
            "x-railway-edge": "railway/edge",
            "x-railway-request-id": "SAMPLE-REQUEST-ID",
            "x-real-ip": "203.0.113.11",
            "x-request-start": "1773355343072",
            "x-tuco-event": "message.fallback",
            "x-tuco-signature": "hmac-sha256-of-raw-body-using-your-webhook-secret",
            "x-tuco-timestamp": "2026-03-12T22:42:23.038Z"
          },
          "params": {},
          "query": {},
          "body": {
            "event": "message.fallback",
            "timestamp": "2026-03-12T22:42:23.038Z",
            "workspaceId": "org_SampleWorkspaceB00000000",
            "leadId": "69b3414e6dae1d942ece4d0c",
            "lead": {
              "_id": "69b3414e6dae1d942ece4d0c",
              "firstName": "John",
              "lastName": "Smith",
              "email": null,
              "phone": "+15551230002",
              "altPhone1": null,
              "altPhone2": null,
              "altPhone3": null,
              "altEmail1": null,
              "altEmail2": null,
              "altEmail3": null,
              "companyName": null,
              "jobTitle": null,
              "linkedinUrl": null,
              "notes": null,
              "customFields": null,
              "availabilityStatus": "available",
              "availabilityCheckedAt": "2026-03-12T22:42:22.280Z",
              "listId": "69ab444ac1feb77d7f46462f",
              "workspaceId": "org_SampleWorkspaceB00000000",
              "contactOwnerId": "user_SampleUserB000000000000",
              "createdByUserId": "user_SampleUserB000000000000",
              "source": "gohighlevel",
              "createdAt": "2026-03-12T22:42:22.280Z",
              "updatedAt": "2026-03-12T22:42:22.280Z",
              "integrationIds": {
                "ghlRecordId": "SAMPLE_CRM_CONTACT_ID",
                "ghlLocationId": "SAMPLE_CRM_LOCATION_ID"
              },
              "contactIdentifiers": [
                "+15551230002"
              ]
            },
            "messageId": "69b3414e6dae1d942ece4d0d",
            "message": {
              "_id": "69b3414e6dae1d942ece4d0d",
              "message": "Quick follow-up on your request",
              "messageType": "imessage",
              "direction": "sent",
              "recipientEmail": null,
              "recipientPhone": "+15551230002",
              "recipientName": "John Smith",
              "fromLineId": "69ab427ac1feb77d7f46462e",
              "fromLinePhone": "+15550100200",
              "fromLineEmail": "line-owner@example.com",
              "leadId": "69b3414e6dae1d942ece4d0c",
              "hsContactId": null,
              "hsPortalId": null,
              "ghlContactId": null,
              "ghlLocationId": null,
              "ghlConversationMessageId": null,
              "sendFallbackSmsOnFailed": false,
              "attachmentUrls": null,
              "attachmentNames": null,
              "workspaceId": "org_SampleWorkspaceB00000000",
              "createdByUserId": "user_SampleUserB000000000000",
              "status": "fallback",
              "scheduledDate": null,
              "batchId": null,
              "settings": null,
              "createdAt": "2026-03-12T22:42:22.379Z",
              "updatedAt": "2026-03-12T22:42:22.962Z",
              "error": "Prospect's iMessage not available on +15551230002",
              "errorMessage": "Prospect's iMessage not available on +15551230002"
            },
            "ghlContactId": "SAMPLE_CRM_CONTACT_ID",
            "ghlLocationId": "SAMPLE_CRM_LOCATION_ID",
            "hsPortalId": null,
            "hsContactId": null,
            "data": {
              "reason": "Prospect's iMessage not available on +15551230002",
              "checkedAddresses": [
                "+15551230002"
              ],
              "ghlContactId": "SAMPLE_CRM_CONTACT_ID",
              "ghlLocationId": "SAMPLE_CRM_LOCATION_ID"
            },
            "contactOwnerEmail": null
          },
          "webhookUrl": "https://your-n8n.example.com/webhook/tuco-imessage-fallback",
          "executionMode": "production"
        }
      }
    ],
    "Webhook — Message Failed": [
      {
        "json": {
          "headers": {
            "host": "your-n8n.example.com",
            "user-agent": "node",
            "content-length": "2232",
            "accept": "*/*",
            "accept-encoding": "br, gzip, deflate",
            "accept-language": "*",
            "content-type": "application/json",
            "sec-fetch-mode": "cors",
            "x-forwarded-for": "203.0.113.11",
            "x-forwarded-host": "your-n8n.example.com",
            "x-forwarded-proto": "https",
            "x-railway-edge": "railway/edge",
            "x-railway-request-id": "SAMPLE-REQUEST-ID",
            "x-real-ip": "203.0.113.11",
            "x-request-start": "1773355343072",
            "x-tuco-event": "message.failed",
            "x-tuco-signature": "hmac-sha256-of-raw-body-using-your-webhook-secret",
            "x-tuco-timestamp": "2026-03-12T22:42:23.038Z"
          },
          "params": {},
          "query": {},
          "body": {
            "event": "message.failed",
            "timestamp": "2026-03-12T22:42:23.038Z",
            "workspaceId": "org_SampleWorkspaceB00000000",
            "leadId": "69b3414e6dae1d942ece4d0c",
            "lead": {
              "_id": "69b3414e6dae1d942ece4d0c",
              "firstName": "John",
              "lastName": "Smith",
              "email": null,
              "phone": "+15551230002",
              "altPhone1": null,
              "altPhone2": null,
              "altPhone3": null,
              "altEmail1": null,
              "altEmail2": null,
              "altEmail3": null,
              "companyName": null,
              "jobTitle": null,
              "linkedinUrl": null,
              "notes": null,
              "customFields": null,
              "availabilityStatus": "available",
              "availabilityCheckedAt": "2026-03-12T22:42:22.280Z",
              "listId": "69ab444ac1feb77d7f46462f",
              "workspaceId": "org_SampleWorkspaceB00000000",
              "contactOwnerId": "user_SampleUserB000000000000",
              "createdByUserId": "user_SampleUserB000000000000",
              "source": "gohighlevel",
              "createdAt": "2026-03-12T22:42:22.280Z",
              "updatedAt": "2026-03-12T22:42:22.280Z",
              "integrationIds": {
                "ghlRecordId": "SAMPLE_CRM_CONTACT_ID",
                "ghlLocationId": "SAMPLE_CRM_LOCATION_ID"
              },
              "contactIdentifiers": [
                "+15551230002"
              ]
            },
            "messageId": "69b3414e6dae1d942ece4d0d",
            "message": {
              "_id": "69b3414e6dae1d942ece4d0d",
              "message": "Quick follow-up on your request",
              "messageType": "imessage",
              "direction": "sent",
              "recipientEmail": null,
              "recipientPhone": "+15551230002",
              "recipientName": "John Smith",
              "fromLineId": "69ab427ac1feb77d7f46462e",
              "fromLinePhone": "+15550100200",
              "fromLineEmail": "line-owner@example.com",
              "leadId": "69b3414e6dae1d942ece4d0c",
              "hsContactId": null,
              "hsPortalId": null,
              "ghlContactId": null,
              "ghlLocationId": null,
              "ghlConversationMessageId": null,
              "sendFallbackSmsOnFailed": false,
              "attachmentUrls": null,
              "attachmentNames": null,
              "workspaceId": "org_SampleWorkspaceB00000000",
              "createdByUserId": "user_SampleUserB000000000000",
              "status": "failed",
              "scheduledDate": null,
              "batchId": null,
              "settings": null,
              "createdAt": "2026-03-12T22:42:22.379Z",
              "updatedAt": "2026-03-12T22:42:22.962Z",
              "error": "Message server unreachable after 3 retries",
              "errorMessage": "Message server unreachable after 3 retries"
            },
            "ghlContactId": "SAMPLE_CRM_CONTACT_ID",
            "ghlLocationId": "SAMPLE_CRM_LOCATION_ID",
            "hsPortalId": null,
            "hsContactId": null,
            "data": {
              "error": "Message server unreachable after 3 retries",
              "ghlContactId": "SAMPLE_CRM_CONTACT_ID",
              "ghlLocationId": "SAMPLE_CRM_LOCATION_ID"
            },
            "contactOwnerEmail": null
          },
          "webhookUrl": "https://your-n8n.example.com/webhook/tuco-message-failed",
          "executionMode": "production"
        }
      }
    ],
    "Webhook — Draft Approved / Rejected": [
      {
        "json": {
          "headers": {
            "host": "your-n8n.example.com",
            "user-agent": "node",
            "content-type": "application/json",
            "x-tuco-event": "message.ai_draft_approved",
            "x-tuco-signature": "hmac-sha256-of-raw-body-using-your-webhook-secret",
            "x-tuco-timestamp": "2026-03-12T21:25:14.882Z"
          },
          "params": {},
          "query": {},
          "body": {
            "event": "message.ai_draft_approved",
            "timestamp": "2026-03-12T21:25:14.882Z",
            "workspaceId": "org_SampleWorkspaceB00000000",
            "leadId": "69b2c41d352a78479d2c623b",
            "lead": {
              "_id": "69b2c41d352a78479d2c623b",
              "firstName": "BG",
              "lastName": "Tuco",
              "email": "bg@tuco.ai",
              "phone": "+919042956129",
              "workspaceId": "org_SampleWorkspaceB00000000",
              "source": "n8n"
            },
            "message": "Sure — the onboarding call runs about 30 minutes and we can do Thursday 2pm. Want me to lock it in?",
            "ghlContactId": null,
            "ghlLocationId": null,
            "hsPortalId": null,
            "hsContactId": null,
            "data": {
              "replyId": "69b330a1cad37b94a846ef01",
              "draftMessage": "Sure — the onboarding call runs about 30 minutes and we can do Thursday 2pm. Want me to lock it in?",
              "conversationRecipient": "+919042956129",
              "confidence": 0.92,
              "mode": "copilot",
              "approveEndpoint": "/api/knowledge-base/auto-replies",
              "approvalChannel": "telegram",
              "approvedBy": "user_SampleUserB000000000000",
              "ghlContactId": null,
              "ghlLocationId": null,
              "hsPortalId": null,
              "hsContactId": null,
              "inboundText": null,
              "inboundMessageId": null
            },
            "contactOwnerEmail": null
          },
          "webhookUrl": "https://your-n8n.example.com/webhook/tuco-ai-draft-resolved",
          "executionMode": "production"
        }
      }
    ],
    "Check iMessage Availability": [
      {
        "json": {
          "success": true,
          "available": true,
          "address": "+919042956129"
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "Send Step 2 — Voice Note (skips if replied)": [
      {
        "json": {
          "message": null,
          "success": true,
          "leadId": "69b2c41d352a78479d2c623b",
          "ghlContactId": null,
          "ghlLocationId": null,
          "hsPortalId": null,
          "hsContactId": null,
          "skippedOnly": true,
          "skipReason": "recipient_replied",
          "skipMessage": "Skipped: this contact already replied in your workspace. The skipIfReplied gate prevented this send.",
          "repliedAt": "2026-03-13T09:12:44.120Z",
          "pdCompanyId": null,
          "pdPersonId": null,
          "pdLeadId": null
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "Send Step 3 — Follow-up Text (skips if replied)": [
      {
        "json": {
          "message": {
            "_id": "69b4a1c2d3e4f5a6b7c8d9e0",
            "message": "Just circling back — any thoughts?",
            "messageType": "imessage",
            "direction": "sent",
            "recipientPhone": "+919042956129",
            "leadId": "69b2c41d352a78479d2c623b",
            "workspaceId": "org_SampleWorkspaceB00000000",
            "status": "sent",
            "sentAt": "2026-03-14T22:57:02.892Z"
          },
          "success": true,
          "leadId": "69b2c41d352a78479d2c623b",
          "ghlContactId": null,
          "ghlLocationId": null,
          "hsPortalId": null,
          "hsContactId": null,
          "status": "sent",
          "reason": ""
        },
        "pairedItem": {
          "item": 0
        }
      }
    ],
    "Send Step 1 — Opening Text": [
      {
        "json": {
          "message": {
            "_id": "69b344bc6dae1d942ece4d0e",
            "message": "Here’s your document.",
            "messageType": "imessage",
            "direction": "sent",
            "recipientEmail": "bg@tuco.ai",
            "recipientPhone": "+919042956129",
            "recipientName": "BG Tuco",
            "fromLineId": "69ab427ac1feb77d7f46462e",
            "fromLinePhone": "+15550100200",
            "fromLineEmail": "line-owner@example.com",
            "leadId": "69b2c41d352a78479d2c623b",
            "hsContactId": null,
            "hsPortalId": null,
            "ghlContactId": null,
            "ghlLocationId": null,
            "ghlConversationMessageId": null,
            "sendFallbackSmsOnFailed": false,
            "workspaceId": "org_SampleWorkspaceB00000000",
            "createdByUserId": "user_SampleUserB000000000000",
            "status": "sent",
            "scheduledDate": null,
            "batchId": null,
            "settings": null,
            "createdAt": "2026-03-12T22:57:00.856Z",
            "updatedAt": "2026-03-12T22:57:02.892Z",
            "externalMessageId": "5CA93911-F0FE-4D1F-8D8C-1E3495A124F6",
            "sentAt": "2026-03-12T22:57:02.892Z"
          },
          "success": true,
          "leadId": "69b2c41d352a78479d2c623b",
          "ghlContactId": "SAMPLE_CRM_CONTACT_ID",
          "ghlLocationId": "SAMPLE_CRM_LOCATION_ID",
          "hsPortalId": null,
          "hsContactId": null,
          "status": "sent",
          "reason": ""
        },
        "pairedItem": {
          "item": 0
        }
      }
    ]
  },
  "connections": {
    "Create Lead": {
      "main": [
        [
          {
            "node": "Send Step 1 — Opening Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook — Receive iMessage": {
      "main": [
        [
          {
            "node": "Map Tuco Reply (EDIT ME)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Map Tuco Reply (EDIT ME)": {
      "main": [
        []
      ]
    },
    "Map Message and Contact Info": {
      "main": [
        [
          {
            "node": "Valid E.164 Phone?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook — Send iMessage": {
      "main": [
        [
          {
            "node": "Map Message and Contact Info",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Map Fallback (EDIT ME)": {
      "main": [
        []
      ]
    },
    "Webhook — AI Draft Created": {
      "main": [
        [
          {
            "node": "Map AI Draft (EDIT ME)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Map AI Draft (EDIT ME)": {
      "main": [
        [
          {
            "node": "Approve & Send Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook — Message Fallback": {
      "main": [
        [
          {
            "node": "Map Fallback (EDIT ME)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook — Message Failed": {
      "main": [
        [
          {
            "node": "Map Failed (EDIT ME)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook — Draft Approved / Rejected": {
      "main": [
        [
          {
            "node": "Map Draft Resolution (EDIT ME)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check iMessage Availability": {
      "main": [
        [
          {
            "node": "Has iMessage?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has iMessage?": {
      "main": [
        [
          {
            "node": "Create Lead",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Wait 1 Day": {
      "main": [
        [
          {
            "node": "Send Step 2 — Voice Note (skips if replied)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Step 2 — Voice Note (skips if replied)": {
      "main": [
        [
          {
            "node": "Wait 1 More Day",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 1 More Day": {
      "main": [
        [
          {
            "node": "Send Step 3 — Follow-up Text (skips if replied)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Step 1 — Opening Text": {
      "main": [
        [
          {
            "node": "Wait 1 Day",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Valid E.164 Phone?": {
      "main": [
        [
          {
            "node": "Check iMessage Availability",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  }
}
