{
  "nodes": [
    {
      "id": "0cf90016-2ac7-4109-8d36-60e14d9cd69e",
      "name": "Upload Image",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        32,
        496
      ],
      "parameters": {
        "options": {},
        "formTitle": "Upload Image",
        "formFields": {
          "values": [
            {
              "fieldType": "file",
              "fieldLabel": "data",
              "requiredField": true
            }
          ]
        }
      },
      "typeVersion": 2.2,
      "alwaysOutputData": true
    },
    {
      "id": "81f0f027-e52c-4c1f-af8e-0ad7650d7452",
      "name": "Send Image",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1344,
        432
      ],
      "parameters": {
        "chatId": "1872183963",
        "operation": "sendDocument",
        "binaryData": true,
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "07ba8942-4b77-4553-8102-208e4ccdd817",
      "name": "Upload File",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1344,
        224
      ],
      "parameters": {
        "name": "Patient Info",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive",
          "cachedResultUrl": "https://drive.google.com/drive/my-drive",
          "cachedResultName": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "1S6baavqJn98MjUlbB6KtmARCWuWEekIZ",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1S6baavqJn98MjUlbB6KtmARCWuWEekIZ",
          "cachedResultName": "test_data"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "983d6f4c-de32-47a8-8e06-5e5c81ee5826",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -144,
        -16
      ],
      "parameters": {
        "color": 5,
        "width": 432,
        "height": 640,
        "content": "# \ud83e\udde0 Image Segmentation & Object Detection  \n\nThis workflow processes uploaded files using **VLM Run**, extracts signed URLs, downloads results, and distributes them across multiple services automatically.\n\n## \ud83d\udd04 Workflow Overview\n\n1. User uploads a file via **Form Trigger**.\n2. File is sent to two VLM Run agents:\n   - Segmentation Agent\n   - Detection Agent\n3. VLM Run returns signed Google Cloud Storage URLs.\n4. Webhooks receive the completed outputs.\n5. Code Node extracts the **full signed URL** (no trimming).\n6. n8n downloads the image using the signed URL.\n7. Final output is shared to:\n   - **Google Drive**\n   - **Gmail**\n   - **Telegram**\n"
      },
      "typeVersion": 1
    },
    {
      "id": "a3388528-c890-4fd3-a41e-ffeb9223e13b",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        288,
        -16
      ],
      "parameters": {
        "color": 2,
        "width": 496,
        "height": 640,
        "content": "# \ud83d\udfe4 VLM Run Agents & Webhooks\n\n- **VLM Run (Segmentation)** and **VLM Run (Detection)** agents process uploaded images.\n- Each agent sends results asynchronously to their respective **Webhook nodes**.\n- Webhooks capture completed data from VLM Run, triggering the next steps.\n- This design allows simultaneous segmentation and detection processing.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "10f43c1f-63f8-4202-9c56-19263bed234e",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        784,
        112
      ],
      "parameters": {
        "color": 3,
        "width": 464,
        "height": 512,
        "content": "# \ud83d\udfea Artifact Handling\n\n- Extract generated image/video IDs from VLM Run response.\n  - Plain: img_182573\n  - With tags: img_c7ae8c\n- Fetch artifacts using:\n  - Get Image Artifact \u2192 img_* ID\n- Artifacts are ready to send or further \nprocess in the workflow."
      },
      "typeVersion": 1
    },
    {
      "id": "5a71c76b-b467-4306-8411-5478085e500a",
      "name": "Webhook for Segmented Image",
      "type": "n8n-nodes-base.webhook",
      "position": [
        608,
        304
      ],
      "parameters": {
        "path": "image_segmentation",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "3414f9da-0634-4cab-b405-dbe9bd3069f1",
      "name": "Webhook for Detected Image",
      "type": "n8n-nodes-base.webhook",
      "position": [
        608,
        480
      ],
      "parameters": {
        "path": "image_detection",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "553f65b2-803c-4062-94b3-f6e0702073bd",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1552,
        112
      ],
      "parameters": {
        "color": 4,
        "width": 368,
        "height": 512,
        "content": "# \ud83d\udfe9 Upload to Drive & Send via Telegram\n\n- The downloaded image is uploaded to **Google Drive** under the specified folder.\n- **Google Drive OAuth2** credentials are required with upload permissions.\n- The same image is sent to a Telegram chat via the **Send Image** node.\n- Ensure Telegram Bot token and chat ID are correctly configured.\n- This enables automated multi-channel sharing of processed images.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "eac2acae-bdac-48fa-913c-01e81bd4c1a5",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1248,
        112
      ],
      "parameters": {
        "color": 4,
        "width": 304,
        "height": 512,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "af8fb977-457d-4124-9574-faf10feed0e7",
      "name": "VLM Run (Detection)",
      "type": "@vlm-run/n8n-nodes-vlmrun.vlmRun",
      "position": [
        352,
        480
      ],
      "parameters": {
        "operation": "executeAgent",
        "agentPrompt": "=Detect all objects from the given input and generate tight bounding box image. Gve only valid artifact reference of the generated image for download.",
        "agentCallbackUrl": "https://playground.vlm.run/webhook/image_detection"
      },
      "credentials": {
        "vlmRunApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "da2f6847-4764-4c6e-a2a7-6ecffacdf3c2",
      "name": "VLM Run (Segmentation)",
      "type": "@vlm-run/n8n-nodes-vlmrun.vlmRun",
      "position": [
        352,
        304
      ],
      "parameters": {
        "operation": "executeAgent",
        "agentPrompt": "=Segment all objects from the given input and generate segmented image. Give only artifact of the generated segmented image for download.",
        "agentCallbackUrl": "https://playground.vlm.run/webhook/image_segmentation"
      },
      "credentials": {
        "vlmRunApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "bcca0b4c-afee-4316-acaa-4a388c853404",
      "name": "Get Image Artifact",
      "type": "@vlm-run/n8n-nodes-vlmrun.vlmRun",
      "position": [
        960,
        432
      ],
      "parameters": {
        "objectId": "={{ $json.body.response.annotated_image_id || $json.body.response.segmented_image}}",
        "operation": "artifacts",
        "executionId": "={{ $json.body.id }}",
        "artifactType": "agent"
      },
      "credentials": {
        "vlmRunApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Upload Image": {
      "main": [
        [
          {
            "node": "VLM Run (Detection)",
            "type": "main",
            "index": 0
          },
          {
            "node": "VLM Run (Segmentation)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Image Artifact": {
      "main": [
        [
          {
            "node": "Upload File",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook for Detected Image": {
      "main": [
        [
          {
            "node": "Get Image Artifact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook for Segmented Image": {
      "main": [
        [
          {
            "node": "Get Image Artifact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}