{
  "name": "Log Telegram client updates to Notion and Google Sheets with Gemini",
  "nodes": [
    {
      "id": "80946e29-2bdf-4cce-81a4-2cbbd89e30d5",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1248,
        -160
      ],
      "parameters": {
        "width": 480,
        "height": 992,
        "content": "## Client Project Radar \u2014 The Ambiguity Gate\n\n### How it works\n\nThis workflow captures client project updates from Telegram, uses Gemini to extract the update details and match them against an active client roster, then routes ambiguous matches back to the user for clarification. Clear updates are normalized, appended to Notion, optionally archive Telegram attachments to Google Drive, logged in Google Sheets, and confirmed back in Telegram. A separate daily schedule gathers upcoming Google Calendar events and recent audit-log activity, summarizes them with Gemini, and sends a one-message Telegram digest.\n\n### Setup steps\n\n- Configure Telegram credentials for the trigger and message-sending nodes, including the chat IDs used for confirmations, ambiguity questions, failure alerts, and daily digests.\n- Connect Google Gemini credentials for the three LLM chains and verify the structured output parsers match the expected schemas.\n- Connect Google Sheets credentials and set the active-client roster sheet plus the audit/read-log sheet ranges and columns.\n- Connect Notion credentials and configure the target page or database used by the timeline append step.\n- Connect Google Drive credentials and choose the folder where Telegram attachments should be archived.\n- Connect Google Calendar credentials and select the calendar queried for the next seven days.\n- Confirm the daily schedule trigger time zone and 08:00 run time.\n\n### Customization\n\nAdjust the Gemini prompts and parser schemas for your preferred update fields, client-matching confidence threshold, ambiguity wording, audit-log columns, attachment folder structure, and daily brief format."
      },
      "typeVersion": 1
    },
    {
      "id": "030e4edf-e6b8-484f-b30f-896dc6dcf6ed",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -688,
        -32
      ],
      "parameters": {
        "color": 7,
        "width": 576,
        "height": 528,
        "content": "## Receive and extract update\n\nStarts from an incoming Telegram message and uses Gemini with a structured parser to extract the project update into usable fields."
      },
      "typeVersion": 1
    },
    {
      "id": "b5d10bb0-995a-4a0a-9c99-f3bdb24aade4",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        64
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 336,
        "content": "## Prepare client roster\n\nReads active clients from Google Sheets and collapses the roster into a single item so the matching model can evaluate the full list at once."
      },
      "typeVersion": 1
    },
    {
      "id": "c4070157-be6b-4857-8a8d-18becd829aad",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        368,
        -32
      ],
      "parameters": {
        "color": 7,
        "width": 352,
        "height": 528,
        "content": "## Match update to client\n\nUses Gemini and a structured parser to identify the most likely client for the extracted update."
      },
      "typeVersion": 1
    },
    {
      "id": "19ffa60e-4db0-47af-a866-a4b0a5834137",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        752,
        -32
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 528,
        "content": "## Resolve ambiguous matches\n\nChecks whether the client match is clear enough to continue; ambiguous updates trigger a Telegram clarification request, while valid matches are normalized for downstream processing."
      },
      "typeVersion": 1
    },
    {
      "id": "0f34389e-ebbc-40cc-ac40-753761c89491",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1200,
        -128
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 528,
        "content": "## Append timeline and route\n\nWrites the normalized update to Notion, sends a Telegram failure alert if that step fails, and checks whether the original Telegram update included an attachment."
      },
      "typeVersion": 1
    },
    {
      "id": "b9c8ae2d-81db-4fd7-835e-fb572cbb972d",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1648,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 304,
        "content": "## Archive message attachment\n\nDownloads any Telegram attachment and stores it in Google Drive before the update is logged."
      },
      "typeVersion": 1
    },
    {
      "id": "b229ac13-c756-4f90-b11b-b34bcd286db6",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2096,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 320,
        "content": "## Log and confirm update\n\nRecords the processed update in the Google Sheets audit log and sends a final Telegram confirmation."
      },
      "typeVersion": 1
    },
    {
      "id": "14a68dad-a4b7-4030-86ef-2d0e4722798b",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -688,
        528
      ],
      "parameters": {
        "color": 7,
        "width": 640,
        "height": 512,
        "content": "## Collect brief sources\n\nRuns every day at 08:00, fetching upcoming Google Calendar events and recent sheet log entries, then merging both streams for the brief builder."
      },
      "typeVersion": 1
    },
    {
      "id": "968f9b7b-e3fa-415f-a867-49625b3e1498",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -16,
        544
      ],
      "parameters": {
        "color": 7,
        "width": 768,
        "height": 496,
        "content": "## Write and send brief\n\nBuilds a compact context from the merged sources, has Gemini write the daily brief, and sends the digest as a single Telegram message."
      },
      "typeVersion": 1
    },
    {
      "id": "ed7615b4-bcd5-4f97-b3ef-c626f77dc665",
      "name": "When Telegram Update Received",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -640,
        240
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "a19bd83f-7220-4a39-bb34-2b2d09c3dfb7",
      "name": "Extract Client Update",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        -416,
        128
      ],
      "parameters": {
        "text": "=You extract project updates from a freelancer's casual message.\n\nMessage:\n\"\"\"\n{{ $json.message.text || $json.message.caption || \"\" }}\n\"\"\"\n\nRules:\n- client_hint: the client name or company exactly as the user wrote it. Do not correct it, do not expand it.\n- status: one of not_started | in_progress | blocked | done\n- blocker: the reason work is stuck, or empty string.\n- deadline_mentioned: ISO date (YYYY-MM-DD) ONLY if a date is explicitly stated or clearly derivable from words like \"Friday\" / \"next week\". Today is {{ $now.format('yyyy-MM-dd') }}. Otherwise empty string.\n- summary: one clean sentence, past tense, written for a client-facing timeline.\n\nNever invent a client name. If no client is named, return an empty client_hint.",
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.5
    },
    {
      "id": "8c2cbf54-478d-472f-9a07-dbb0a72e08ac",
      "name": "Gemini Model for Extraction",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -448,
        368
      ],
      "parameters": {
        "options": {
          "temperature": 0.1
        },
        "modelName": "models/gemini-3.1-flash-lite"
      },
      "typeVersion": 1
    },
    {
      "id": "f33c44bc-617d-4720-8879-e9c1382b25f1",
      "name": "Parse Extracted Data",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -240,
        368
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"client_hint\": { \"type\": \"string\" },\n    \"status\": { \"type\": \"string\", \"enum\": [\"not_started\", \"in_progress\", \"blocked\", \"done\"] },\n    \"blocker\": { \"type\": \"string\" },\n    \"deadline_mentioned\": { \"type\": \"string\" },\n    \"summary\": { \"type\": \"string\" }\n  },\n  \"required\": [\"client_hint\", \"status\", \"blocker\", \"deadline_mentioned\", \"summary\"]\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "21afc093-386a-4c20-8ef6-05cdfd4fc05b",
      "name": "Read Active Clients from Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "notes": "Tab 'Clients'. Headers: client_id | client_name | aliases | notion_page_id | drive_folder_id | deadline | active",
      "position": [
        -32,
        240
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_SHEET_GID",
          "cachedResultUrl": "REPLACE_WITH_SHEET_URL",
          "cachedResultName": "radar"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_GOOGLE_SHEET_ID",
          "cachedResultUrl": "REPLACE_WITH_GOOGLE_SHEET_URL",
          "cachedResultName": "triage log"
        },
        "authentication": "serviceAccount"
      },
      "typeVersion": 4.5
    },
    {
      "id": "cd4c8ded-a065-405b-8b2e-aa4dd6dd7555",
      "name": "Compile Client Roster",
      "type": "n8n-nodes-base.code",
      "position": [
        192,
        240
      ],
      "parameters": {
        "jsCode": "// Collapse the client roster into ONE item so the matcher sees the whole list at once.\nconst extracted = $('Extract Client Update').first().json.output;\n\nconst roster = $input.all()\n  .map(i => i.json)\n  .filter(r => String(r.active).toLowerCase() === 'true')\n  .map(r => ({\n    client_id: r.client_id,\n    client_name: r.client_name,\n    aliases: r.aliases || '',\n    notion_page_id: String(r.notion_page_id || '').trim(),\n    drive_folder_id: String(r.drive_folder_id || '').trim()\n  }));\n\nif (roster.length === 0) {\n  throw new Error('Roster is empty. Check the Clients tab: is the active column set to TRUE and are the headers spelled exactly right?');\n}\n\nreturn [{\n  json: {\n    extracted,\n    roster,\n    roster_text: roster.map(r => `${r.client_id} | ${r.client_name} | aliases: ${r.aliases}`).join('\\n')\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "24e39090-4309-4fbe-a5ec-000b5212d0c8",
      "name": "Match Client with Gemini",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        416,
        128
      ],
      "parameters": {
        "text": "=Match a client mention to exactly one client in the roster.\n\nMention: \"{{ $json.extracted.client_hint }}\"\n\nRoster (client_id | client_name | aliases):\n{{ $json.roster_text }}\n\nScoring rules:\n- Exact or alias match: confidence 95-100.\n- Unique unambiguous partial (\"Ahmed\" and only one Ahmed exists): 85-94.\n- Partial that fits TWO OR MORE clients: confidence 40 or below, and list every candidate in candidates.\n- No plausible match at all: confidence 0, client_id empty, candidates empty.\n\nBe pessimistic. A wrong write is far worse than a question.",
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.5
    },
    {
      "id": "fbf86e3c-f626-42e6-9d28-d3c8814ce490",
      "name": "Gemini Model for Matching",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        416,
        368
      ],
      "parameters": {
        "options": {
          "temperature": 0
        },
        "modelName": "models/gemini-3.1-flash-lite"
      },
      "typeVersion": 1
    },
    {
      "id": "8edee33c-1b63-4b4c-92d8-c4995bdd709b",
      "name": "Parse Matching Results",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        608,
        368
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"client_id\": { \"type\": \"string\" },\n    \"client_name\": { \"type\": \"string\" },\n    \"confidence\": { \"type\": \"number\" },\n    \"candidates\": { \"type\": \"array\", \"items\": { \"type\": \"string\" } }\n  },\n  \"required\": [\"client_id\", \"client_name\", \"confidence\", \"candidates\"]\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "4243f353-ee83-4924-a0ca-081544e400c2",
      "name": "Check Confidence Level",
      "type": "n8n-nodes-base.if",
      "position": [
        800,
        240
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "confidence-gate",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.output.confidence }}",
              "rightValue": 80
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "381a5a28-cab9-4a59-bc6c-931e8373c17a",
      "name": "Prompt Client Choice",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1024,
        336
      ],
      "parameters": {
        "text": "=\u26a0\ufe0f Ambiguity Gate\n\nI did not write anything yet.\n\nYou said: {{ $('Extract Client Update').first().json.output.client_hint }}\nConfidence: {{ $json.output.confidence }}%\n\nWhich one do you mean?\n{{ $json.output.candidates.length ? $json.output.candidates.map((c, i) => (i+1) + '. ' + c).join('\\n') : 'No match found in your active client list.' }}\n\nReply with the full client name and I will log it.",
        "chatId": "={{ $('When Telegram Update Received').first().json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e7d7d3d3-364a-46c9-a798-53483af8a646",
      "name": "Standardize Payload Format",
      "type": "n8n-nodes-base.code",
      "position": [
        1024,
        144
      ],
      "parameters": {
        "jsCode": "// One clean object for everything downstream.\nconst match = $input.first().json.output;\nconst extracted = $('Extract Client Update').first().json.output;\nconst msg = $('When Telegram Update Received').first().json.message;\nconst roster = $('Compile Client Roster').first().json.roster;\n\nconst row = roster.find(r => r.client_id === match.client_id) || {};\n\nif (!row.notion_page_id) {\n  throw new Error(`No notion_page_id in the Clients tab for ${match.client_name || match.client_id}. Add the 32-character page ID.`);\n}\n\nreturn [{\n  json: {\n    client_id: match.client_id,\n    client_name: match.client_name,\n    confidence: match.confidence,\n    notion_page_id: row.notion_page_id,\n    drive_folder_id: row.drive_folder_id || '',\n    status: extracted.status,\n    blocker: extracted.blocker,\n    deadline: extracted.deadline_mentioned,\n    summary: extracted.summary,\n    raw_message: msg.text || msg.caption || '',\n    chat_id: msg.chat.id,\n    has_file: Boolean(msg.photo || msg.document),\n    file_id: msg.document ? msg.document.file_id : (msg.photo ? msg.photo[msg.photo.length - 1].file_id : ''),\n    file_name: msg.document ? msg.document.file_name : `telegram-photo-${Date.now()}.jpg`,\n    timestamp: new Date().toISOString()\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "48e9d953-eaf0-480f-9d26-a87dfc66bcb4",
      "name": "Append Timeline in Notion",
      "type": "n8n-nodes-base.notion",
      "notes": "If Blocks is empty after import, add one Paragraph block manually and paste the expression.",
      "onError": "continueErrorOutput",
      "position": [
        1248,
        144
      ],
      "parameters": {
        "blockId": {
          "__rl": true,
          "mode": "id",
          "value": "REPLACE_WITH_NOTION_BLOCK_ID"
        },
        "blockUi": {
          "blockValues": [
            {
              "textContent": "={{ $now.format('yyyy-MM-dd HH:mm') }} \u2014 [{{ $json.status.toUpperCase() }}] {{ $json.summary }}{{ $json.blocker ? ' \u00b7 Blocked: ' + $json.blocker : '' }}{{ $json.deadline ? ' \u00b7 Due ' + $json.deadline : '' }}"
            }
          ]
        },
        "resource": "block"
      },
      "typeVersion": 2.2
    },
    {
      "id": "63f2e6e6-3b8a-4ea0-b74a-ef0187af9ab7",
      "name": "Check for Attachment",
      "type": "n8n-nodes-base.if",
      "position": [
        1472,
        48
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "has-file",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $('Standardize Payload Format').first().json.has_file }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "f1339b6c-d9db-43e1-ac5d-ec29a0460196",
      "name": "Download File from Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1696,
        -32
      ],
      "parameters": {
        "fileId": "={{ $('Standardize Payload Format').first().json.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "f0148d99-140c-48de-bfae-8603863f97dc",
      "name": "Archive Attachment in Drive",
      "type": "n8n-nodes-base.googleDrive",
      "notes": "Service account must have edit access on the target Drive folder.",
      "onError": "continueRegularOutput",
      "position": [
        1920,
        -32
      ],
      "parameters": {
        "name": "={{ $('Standardize Payload Format').first().json.file_name }}",
        "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": "REPLACE_WITH_DRIVE_FOLDER_ID",
          "cachedResultUrl": "REPLACE_WITH_DRIVE_FOLDER_URL",
          "cachedResultName": "radar"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "a1b8f3d9-84ae-4c5d-9f56-aa1b97c7f7f2",
      "name": "Append to Audit Log in Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "notes": "Tab 'Log'. Headers: timestamp | client_id | client_name | status | summary | blocker | deadline | confidence | raw_message",
      "position": [
        2144,
        48
      ],
      "parameters": {
        "columns": {
          "value": {},
          "schema": [
            {
              "id": "client_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "client_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "client_name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "client_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "aliases",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "aliases",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "notion_page_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "notion_page_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "drive_folder_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "drive_folder_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "deadline",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "deadline",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "active",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "active",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "autoMapInputData",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_SHEET_GID",
          "cachedResultUrl": "REPLACE_WITH_SHEET_URL",
          "cachedResultName": "radar"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_GOOGLE_SHEET_ID",
          "cachedResultUrl": "REPLACE_WITH_GOOGLE_SHEET_URL",
          "cachedResultName": "triage log"
        },
        "authentication": "serviceAccount"
      },
      "typeVersion": 4.5
    },
    {
      "id": "99ce759d-258f-4881-87f4-2f34ad5fa6ea",
      "name": "Send Confirmation to Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2368,
        48
      ],
      "parameters": {
        "text": "=\u2705 Logged for {{ $('Standardize Payload Format').first().json.client_name }} ({{ $('Standardize Payload Format').first().json.confidence }}%)\n{{ $('Standardize Payload Format').first().json.summary }}",
        "chatId": "={{ $('Standardize Payload Format').first().json.chat_id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9107d282-a902-4a0a-9f57-ca30102ef19a",
      "name": "Notify Notion Failure",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1472,
        240
      ],
      "parameters": {
        "text": "=\ud83d\udd34 Notion write failed for {{ $('Standardize Payload Format').first().json.client_name }}. The update was NOT saved to the project page.\n\nReason: {{ $json.error?.message || $json.error || 'unknown' }}",
        "chatId": "={{ $('Standardize Payload Format').first().json.chat_id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9cb519bb-372d-4924-a20c-1b68fd15c97e",
      "name": "Daily Trigger at 8AM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -640,
        784
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "a30d3d4a-0f81-48b7-8b33-df87afec38b2",
      "name": "Fetch Next 7 Days from Calendar",
      "type": "n8n-nodes-base.googleCalendar",
      "onError": "continueRegularOutput",
      "position": [
        -416,
        688
      ],
      "parameters": {
        "options": {},
        "timeMax": "={{ $now.plus(7, 'days').toISO() }}",
        "timeMin": "={{ $now.toISO() }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "user@example.com",
          "cachedResultName": "user@example.com"
        },
        "operation": "getAll",
        "returnAll": true
      },
      "typeVersion": 1.3,
      "alwaysOutputData": true
    },
    {
      "id": "d2745357-b448-430b-a947-5d393d95de1f",
      "name": "Read Log Data from Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -416,
        880
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_SHEET_GID",
          "cachedResultUrl": "REPLACE_WITH_SHEET_URL",
          "cachedResultName": "radar"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "REPLACE_WITH_GOOGLE_SHEET_ID",
          "cachedResultUrl": "REPLACE_WITH_GOOGLE_SHEET_URL",
          "cachedResultName": "triage log"
        },
        "authentication": "serviceAccount"
      },
      "typeVersion": 4.5,
      "alwaysOutputData": true
    },
    {
      "id": "95723152-a498-4845-8092-fd4c7c5064a7",
      "name": "Merge Data Sources for Brief",
      "type": "n8n-nodes-base.merge",
      "notes": "APPEND, not combine. Combine would cross-join events x log rows.",
      "position": [
        -192,
        784
      ],
      "parameters": {},
      "typeVersion": 3
    },
    {
      "id": "2826f29b-f233-4ada-beaf-b3f6b4883e57",
      "name": "Construct Brief Context",
      "type": "n8n-nodes-base.code",
      "position": [
        32,
        672
      ],
      "parameters": {
        "jsCode": "// Latest status per client + upcoming calendar events, as ONE item.\nconst items = $input.all().map(i => i.json);\n\nconst events = items\n  .filter(i => i.start && i.summary)\n  .map(i => ({\n    title: i.summary,\n    when: (i.start.dateTime || i.start.date || '').slice(0, 16).replace('T', ' ')\n  }));\n\nconst logs = items.filter(i => i.client_id && i.timestamp);\n\nconst latest = {};\nfor (const l of logs) {\n  if (!latest[l.client_id] || new Date(l.timestamp) > new Date(latest[l.client_id].timestamp)) {\n    latest[l.client_id] = l;\n  }\n}\n\nconst today = new Date();\nconst clients = Object.values(latest).map(l => {\n  const days = l.deadline ? Math.ceil((new Date(l.deadline) - today) / 86400000) : null;\n  return {\n    client: l.client_name,\n    status: l.status,\n    last_update: l.summary,\n    blocker: l.blocker || '',\n    deadline: l.deadline || '',\n    days_left: days\n  };\n});\n\nreturn [{ json: { clients, events, generated_for: today.toISOString().slice(0, 10) } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "dd7ed4f6-8fc7-4da0-a777-5e5bd5263e94",
      "name": "Generate Brief with Gemini",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        256,
        672
      ],
      "parameters": {
        "text": "=Write ONE short Telegram morning brief for a freelancer. Date: {{ $json.generated_for }}.\n\nClient states:\n{{ JSON.stringify($json.clients) }}\n\nCalendar, next 7 days:\n{{ JSON.stringify($json.events) }}\n\nHard rules:\n- Under 140 words total.\n- Plain text only. No markdown, no asterisks, no underscores.\n- Order by urgency: blocked first, then deadline within 3 days, then everything else.\n- Anything with days_left <= 3 gets \ud83d\udd34. days_left 4-7 gets \ud83d\udfe1.\n- One line per client. No preamble, no sign-off, no \"good morning\".\n- End with a single line: \"Today: <the one thing that matters most>\".\n- If there is nothing urgent, say so in one line and stop.",
        "promptType": "define"
      },
      "typeVersion": 1.5
    },
    {
      "id": "ce99581c-c9e7-429c-97fd-8eb50b15107b",
      "name": "Gemini Model for Briefing",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        336,
        896
      ],
      "parameters": {
        "options": {
          "temperature": 0.3
        },
        "modelName": "models/gemini-3.1-flash-lite"
      },
      "typeVersion": 1
    },
    {
      "id": "e2f53be4-d57d-4af4-9b7b-bd4c7aceb24a",
      "name": "Send One-Message Digest",
      "type": "n8n-nodes-base.telegram",
      "notes": "Replace chatId with your numeric Telegram chat ID.",
      "position": [
        608,
        672
      ],
      "parameters": {
        "text": "=\u2600\ufe0f {{ $now.format('EEEE, dd LLL') }}\n\n{{ $json.text }}",
        "chatId": "=REPLACE_WITH_YOUR_CHAT_ID",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "typeVersion": 1.2
    }
  ],
  "connections": {
    "Check for Attachment": {
      "main": [
        [
          {
            "node": "Download File from Telegram",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Append to Audit Log in Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Trigger at 8AM": {
      "main": [
        [
          {
            "node": "Fetch Next 7 Days from Calendar",
            "type": "main",
            "index": 0
          },
          {
            "node": "Read Log Data from Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Extracted Data": {
      "ai_outputParser": [
        [
          {
            "node": "Extract Client Update",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Compile Client Roster": {
      "main": [
        [
          {
            "node": "Match Client with Gemini",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Client Update": {
      "main": [
        [
          {
            "node": "Read Active Clients from Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Confidence Level": {
      "main": [
        [
          {
            "node": "Standardize Payload Format",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prompt Client Choice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Matching Results": {
      "ai_outputParser": [
        [
          {
            "node": "Match Client with Gemini",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Construct Brief Context": {
      "main": [
        [
          {
            "node": "Generate Brief with Gemini",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Match Client with Gemini": {
      "main": [
        [
          {
            "node": "Check Confidence Level",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append Timeline in Notion": {
      "main": [
        [
          {
            "node": "Check for Attachment",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Notify Notion Failure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Model for Briefing": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Brief with Gemini",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Model for Matching": {
      "ai_languageModel": [
        [
          {
            "node": "Match Client with Gemini",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Read Log Data from Sheets": {
      "main": [
        [
          {
            "node": "Merge Data Sources for Brief",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Generate Brief with Gemini": {
      "main": [
        [
          {
            "node": "Send One-Message Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Standardize Payload Format": {
      "main": [
        [
          {
            "node": "Append Timeline in Notion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Archive Attachment in Drive": {
      "main": [
        [
          {
            "node": "Append to Audit Log in Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download File from Telegram": {
      "main": [
        [
          {
            "node": "Archive Attachment in Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Model for Extraction": {
      "ai_languageModel": [
        [
          {
            "node": "Extract Client Update",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Merge Data Sources for Brief": {
      "main": [
        [
          {
            "node": "Construct Brief Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append to Audit Log in Sheets": {
      "main": [
        [
          {
            "node": "Send Confirmation to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Telegram Update Received": {
      "main": [
        [
          {
            "node": "Extract Client Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Next 7 Days from Calendar": {
      "main": [
        [
          {
            "node": "Merge Data Sources for Brief",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Active Clients from Sheets": {
      "main": [
        [
          {
            "node": "Compile Client Roster",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "instanceId": null
  },
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": false,
    "executionOrder": "v1"
  }
}