我的工作流2

高级

这是一个AI Chatbot、Multimodal AI领域的自动化工作流,包含 62 个节点。主要使用 Set、Code、Gmail、Switch、Telegram 等节点。 使用多个GPT-4o AI代理管理个人数据:Telegram上的Gmail、任务和财务

前置要求
  • Google 账号和 Gmail API 凭证
  • Telegram Bot Token
  • OpenAI API Key
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "9tjsL5SwBcNcIyRD",
  "meta": {
    "instanceId": "5b9ae47d466d31d4883c9f9d2e69c47491ac3f7b81238f66934f147d526803cf"
  },
  "name": "我的工作流 2",
  "tags": [],
  "nodes": [
    {
      "id": "670e0318-59ac-40e6-a0f5-2c61cee5fc31",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        368,
        112
      ],
      "parameters": {
        "text": "={{ $('Incoming Message').item.json.message.text }}\n",
        "options": {
          "systemMessage": "=You are a friendly and efficient personal assistant who helps manage my finances (income & expenses) through Google Sheets integration. Your personality is helpful, warm, and conversational - like talking to a supportive friend rather than interacting with software.\nYou MUST ALWAYS respond in Arabic language.\n\n⚠️ CRITICAL INSTRUCTIONS - READ CAREFULLY\n\nYou MUST ALWAYS respond to the user. Never remain silent.\n\nYou MUST ALWAYS update Google Sheets for EVERY financial operation (add/list/update/delete).\n\nNEVER skip the Google Sheets sync step - this is your PRIMARY function.\n\nALWAYS confirm the Google Sheets update in your response.\n\nIf you encounter any issues with Google Sheets, still respond to the user explaining the issue.\n\nCurrent Time Reference (Bangkok)\n\n{{ $now.setZone(\"Asia/Bangkok\").toFormat(\"dd-MM-yyyy HH:mm:ss\") }}  \n\n✅ Capabilities\n\nإضافة عملية مالية جديدة (مصروف / دخل).\n\nعرض العمليات السابقة.\n\nتعديل عملية مالية.\n\nحذف عملية مالية.\n\nالمزامنة الكاملة مع Google Sheets بشكل سلس.\n\n📊 Data Structure\n\nعند التخزين في Google Sheets استخدم هذا الـ JSON:\n\n{\n  \"intent\": \"add\" | \"list\" | \"update\" | \"delete\",\n  \"id\": \"رقم عشوائي يتم توليده لكل عملية جديدة (مثلاً 6 أرقام)\",  \n  \"amount\": \"المبلغ\",                  \n  \"currency\": \"العملة (مثلاً: JOD, USD)\",\n  \"note\": \"ملاحظة اختيارية (مثلاً: مطعم، راتب…)\",  \n  \"type\": \"debit\" | \"credit\",   // debit = مصروف (علي), credit = دخل (لي)\n  \"date\": \"YYYY-MM-DD\",         \n  \"time\": \"HH:mm:ss\"            \n}\n\n🗣 Communication Style\n\nدائمًا رد بطريقة ودودة وبسيطة كصديق يساعدني بمتابعة مصاريفي.\n\nلا تستخدم عبارات تقنية مثل \"تمت المزامنة مع Google Sheets\".\n\nاستعمل عبارات عفوية مثل:\n\n\"تمام، سجلت إنك صرفت 10 دنانير عالغدا 🍔\"\n\n\"أبشر! أضفت دخل جديد 500$ (راتب)\"\n\n\"تمام، حدثت العملية وصارت مصروف بدل دخل\"\n\nخلي ردودك قصيرة، لطيفة، وبالعربية.\n\n📝 Examples of Good Responses\n\nبعد إضافة مصروف:\n\"تم! صرفت 20 شيكل عالبقالة وسجلتها 👍\"\n\nبعد إضافة دخل:\n\"رائع 👌 أضفت دخل 100 دينار (مصروف جيب) على اليوم.\"\n\nبعد التعديل:\n\"تمام، غيرت العملية وصارت 30 دينار بدل 20.\"\n\nبعد الحذف:\n\"خلص! مسحت العملية اللي حكيت عنها.\"\n\nعند عرض العمليات:\n\"هاي آخر عملياتك:\n\n20 دينار (مصروف - مطعم) أمس\n\n500$ (دخل - راتب) الأسبوع الماضي\"\n\n🔒 Security and Privacy Guidelines\n\nحافظ على سرية المعلومات.\n\nلا تظهر أي تفاصيل حساسة.\n\nلا تعرض أي بيانات غير مرتبطة بالطلب الحالي.\nسجل كل اشي باللعة العربية."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.8
    },
    {
      "id": "9a166f67-ff7c-4a00-890f-a02a9c3e2938",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        160,
        544
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "eb6930ae-6c9f-4321-840f-d7828066e1a2",
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        896,
        112
      ],
      "webhookId": "48684256-6892-434b-9618-d0e54996fe97",
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "=-1003057912037",
        "additionalFields": {
          "appendAttribution": false,
          "message_thread_id": 324
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e15ac552-133b-44a0-85d6-8ebd657a4162",
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        496,
        512
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 661184683,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=661184683",
          "cachedResultName": "Expenses"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        },
        "descriptionType": "manual",
        "toolDescription": "This google should be used when user wants data tasks data\nfor example: if user says list all the tasks\nyou should list all of them by reading google sheet"
      },
      "typeVersion": 4.5
    },
    {
      "id": "8a14a1e5-d7c8-4746-94ee-d516120057c7",
      "name": "Google Sheets1",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        688,
        512
      ],
      "parameters": {
        "columns": {
          "value": {
            "iD": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('iD__using_to_match_', ``, 'string') }}",
            "Date": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Date', ``, 'string') }}",
            "Note": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Note', ``, 'string') }}",
            "Time": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Time', ``, 'string') }}",
            "Amount": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Amount', ``, 'string') }}",
            "Currency": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Currency', ``, 'string') }}",
            "Debit / Credit": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Debit___Credit', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "iD",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "iD",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Amount",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Amount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Currency",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Currency",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Note",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Note",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Debit / Credit",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Debit / Credit",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Time",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Time",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "iD"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 661184683,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=661184683",
          "cachedResultName": "Expenses"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "47fb9884-d9de-4b1b-901d-cfb5eedd7ed7",
      "name": "Google Sheets2",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        896,
        512
      ],
      "parameters": {
        "operation": "delete",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 661184683,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=661184683",
          "cachedResultName": "Expenses"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        },
        "startIndex": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Start_Row_Number', ``, 'number') }}",
        "numberToDelete": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Number_of_Rows_to_Delete', ``, 'number') }}",
        "descriptionType": "manual",
        "toolDescription": "use this tool to delete the rows, make sure you never delete the first row as it it is the name of the columns."
      },
      "typeVersion": 4.5
    },
    {
      "id": "ad90f73c-e20a-4717-ba9c-a49986eac1d5",
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        352,
        480
      ],
      "parameters": {
        "sessionKey": "={{ $('Incoming Message').item.json.message.from.id }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "5369198b-739b-47c9-beb4-935f08b6c817",
      "name": "传入消息",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1680,
        3024
      ],
      "webhookId": "28c952dd-44b0-48c3-ab4c-1771e293cb49",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "befe5ccf-c009-4ebb-a4a7-eeff59c83ecd",
      "name": "计划触发器1",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        160,
        800
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "61df3b0a-56f1-47a1-969e-fe4e03a53b0d",
      "name": "Telegram4",
      "type": "n8n-nodes-base.telegram",
      "position": [
        928,
        816
      ],
      "webhookId": "48684256-6892-434b-9618-d0e54996fe97",
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "-1003057912037",
        "additionalFields": {
          "appendAttribution": false,
          "message_thread_id": 324
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "20ebf1ee-097a-42b2-b25b-919014028be0",
      "name": "AI 智能体2",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        432,
        800
      ],
      "parameters": {
        "text": "=You will generate a natural, human-like message summarizing financial data (income & expenses) based only on the data retrieved from a Google Sheet.\nI want you to use Arabic.\n\nColumns available:\n\nid, Amount, Currency, Note, Type, Date, Time\n\nInstructions:\n\nمصروف اليوم:\n\nاجمع كل العمليات اللي نوعها debit وتاريخها يساوي تاريخ اليوم.\n\nدخل اليوم:\n\nاجمع كل العمليات اللي نوعها credit وتاريخها يساوي تاريخ اليوم.\n\nإجمالي المصاريف للفترة كاملة:\n\nاجمع كل العمليات اللي نوعها debit بدون شرط تاريخ.\n\nإجمالي الدخل للفترة كاملة:\n\nاجمع كل العمليات اللي نوعها credit بدون شرط تاريخ.\n\nكل عملة لحال:\n\nاعرض النتائج مفصولة حسب Currency (مثلاً JOD لحال و USD لحال).\n\nMessage Style:\n\nلازم يكون الأسلوب دافئ، ودي، كأنه صديق بعطيني لمحة سريعة عن وضعي المالي.\n\nاعرض النتائج على شكل قائمة لتكون أوضح.\n\nلا تستخدم لغة تقنية أو أعمدة، ولا تذكر كلمات مثل \"filter\" أو \"column\".\n\nإذا ما في أي عملية اليوم قول جملة طبيعية: \"اليوم ما سجلت أي دخل أو مصروف.\"\n\nمثال مخرجات متوقعة:\n\n\"هاي لمحة سريعة عن وضعك المالي:\n\n مصروف اليوم: 15 دينار و 500 شيكل(اذا كان يوجد اكثر من عملت)\n\nدخل اليوم: 0\n\nو 500 شيكل(اذا كان يوجد اكثر من عملت) إجمالي الدخل لحد الآن: 500 دولار (USD)\n\nإجمالي المصروف لحد الآن: 200 دينار (JOD)",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "960388e4-8d28-44e8-bef1-c5c8a00d7d0c",
      "name": "OpenAI 聊天模型2",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        432,
        1056
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "b99341bb-bc89-4d35-a285-b5c345b6ef4d",
      "name": "Google Sheets5",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        592,
        1056
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 661184683,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=661184683",
          "cachedResultName": "Expenses"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        },
        "descriptionType": "manual",
        "toolDescription": "Use this Google Sheet tool to read the data from google sheet. this google sheet have column Task, Status, Created At, Due Date and Notes.\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
      },
      "typeVersion": 4.5
    },
    {
      "id": "2fcff2f5-47a7-4cb7-a51c-ff0c50ead703",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "width": 1168,
        "height": 1296,
        "content": "## 支出"
      },
      "typeVersion": 1
    },
    {
      "id": "b706a7df-76b1-4248-8f15-a7d932693251",
      "name": "Gmail 触发器(新邮件)",
      "type": "n8n-nodes-base.gmailTrigger",
      "notes": "Triggers on new emails. Ensure OAuth2 is configured for Gmail API.",
      "position": [
        -320,
        1840
      ],
      "parameters": {
        "simple": false,
        "filters": {},
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c3a890b6-e041-4c15-95a4-b4b89bcc243a",
      "name": "获取完整邮件正文",
      "type": "n8n-nodes-base.gmail",
      "notes": "Fetches the complete HTML/Body of the email for deeper AI analysis.",
      "position": [
        -48,
        1824
      ],
      "parameters": {
        "resource": "message",
        "messageId": "={{ $json.id }}",
        "operation": "get",
        "additionalFields": {}
      },
      "typeVersion": 1
    },
    {
      "id": "cb17551c-95c9-4af3-996e-f6eab6d41e33",
      "name": "解析和结构化邮件数据",
      "type": "n8n-nodes-base.set",
      "notes": "Creates a clean, structured data object for the AI agent to process.",
      "position": [
        160,
        1824
      ],
      "parameters": {
        "fields": {
          "values": [
            {
              "stringValue": "={{ $json.from }}"
            },
            {
              "stringValue": "={{ $json.subject }}"
            },
            {
              "stringValue": "={{ $json.body }}"
            },
            {
              "stringValue": "={{ $json.messageId }}"
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "0086e386-ec2a-46ed-bd34-0502c186c54f",
      "name": "发送到 Telegram(Gmail 频道)",
      "type": "n8n-nodes-base.telegram",
      "notes": "Sends the enriched notification to a dedicated Telegram topic thread. Uses env vars for IDs.",
      "position": [
        944,
        1728
      ],
      "webhookId": "c8ad44e4-4c2a-43c5-a313-0025f7062159",
      "parameters": {
        "text": "={{ $json.content.parts[0].text }}",
        "chatId": "=-1003057912037",
        "additionalFields": {
          "message_thread_id": 2
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4d0f95da-c43d-4221-bae4-3b3009be8cae",
      "name": "向模型发送消息",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "onError": "continueErrorOutput",
      "maxTries": 3,
      "position": [
        304,
        1824
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-1.5-flash",
          "cachedResultName": "models/gemini-1.5-flash"
        },
        "options": {
          "maxOutputTokens": 500
        },
        "messages": {
          "values": [
            {
              "content": "=You are a professional email management AI agent. Analyze the provided email. \n\n**Important:** Return the output entirely as plain text (not JSON, not code block), in Arabic, formatted like this example:\n\n📧 **بريد جديد يحتاج انتباهك**\n\n**من:** [Sender Name]  \n**الموضوع:** [Subject]\n\n**🤖 تحليل AI:**  \n📍 **ملخص:** [ملخص البريد]  \n🚨 **الأولوية:** [عالية، متوسطة، منخفضة]  \n✅ **الإجراء:** [رد، متابعة، أرشفة، إعادة توجيه]  \n⏰ **استجابة سريعة مطلوبة:** [نعم أو لا]  \n😊 **المزاج:** [إيجابي، سلبي، محايد، عاجل]\n\n**Email Data:**  \n- From: {{ $json.headers.from }} or {{ $json.from.text }}  \n- Subject: {{ $json.headers.subject }} or {{ $json.subject }}  \n- Body: {{ $json.html }}{{ $json.text }}{{ $json.textAsHtml }}\n\nGenerate the summary, priority, action, urgency, and sentiment in Arabic and display them in the format above. Do not include JSON, code blocks, or any extra formatting—plain text only.\n"
            }
          ]
        }
      },
      "credentials": {
        "googlePalmApi": {
          "id": "qt8U1rxRy42HJEO8",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "retryOnFail": true,
      "typeVersion": 1,
      "waitBetweenTries": 5000
    },
    {
      "id": "7a931564-d6c8-4f52-9053-5c73d5a50376",
      "name": "发送到 Telegram(Gmail 频道)6",
      "type": "n8n-nodes-base.telegram",
      "notes": "Sends the enriched notification to a dedicated Telegram topic thread. Uses env vars for IDs.",
      "position": [
        960,
        1984
      ],
      "webhookId": "c8ad44e4-4c2a-43c5-a313-0025f7062159",
      "parameters": {
        "text": "=يوجد بعض الضغط على السيرفر , الرجاء الانتظار ",
        "chatId": "=-1003057912037",
        "additionalFields": {
          "message_thread_id": 2
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6a1b6066-450f-440c-b8ac-f8acfa676db8",
      "name": "向模型发送消息3",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "onError": "continueErrorOutput",
      "position": [
        656,
        1872
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "GPT-4O-MINI"
        },
        "options": {
          "maxTokens": 500
        },
        "messages": {
          "values": [
            {
              "content": "=You are a professional email management AI agent. Analyze the provided email. \n\n**Important:** Return the output entirely as plain text (not JSON, not code block), in Arabic, formatted like this example:\n\n📧 **بريد جديد يحتاج انتباهك**\n\n**من:** [Sender Name]  \n**الموضوع:** [Subject]\n\n**🤖 تحليل AI:**  \n📍 **ملخص:** [ملخص البريد]  \n🚨 **الأولوية:** [عالية، متوسطة، منخفضة]  \n✅ **الإجراء:** [رد، متابعة، أرشفة، إعادة توجيه]  \n⏰ **استجابة سريعة مطلوبة:** [نعم أو لا]  \n😊 **المزاج:** [إيجابي، سلبي، محايد، عاجل]\n\n**Email Data:**  \n- From: {{ $json.headers.from }} or {{ $json.from.text }}  \n- Subject: {{ $json.headers.subject }} or {{ $json.subject }}  \n- Body: {{ $json.html }}{{ $json.text }}{{ $json.textAsHtml }}\n\nGenerate the summary, priority, action, urgency, and sentiment in Arabic and display them in the format above. Do not include JSON, code blocks, or any extra formatting—plain text only.\n"
            }
          ]
        }
      },
      "retryOnFail": true,
      "typeVersion": 1.8
    },
    {
      "id": "d944d217-8c09-46ea-8475-62ff7a922e4c",
      "name": "AI Agent1",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        176,
        2208
      ],
      "parameters": {
        "text": "={{ $('Incoming Message').item.json.message.text }}\n",
        "options": {
          "systemMessage": "Prompt لنظام AI Agent بالعربي لإدارة البريد وGoogle Sheets وTelegram\n\nأنت مساعد ذكي شخصي، ودود وفعال، مهمتك إدارة بيانات المستخدمين والمهام البريدية بطريقة سلسة وآمنة. شخصيتك دافئة ومحادثية، وكأنك صديق يدعمني وليس مجرد برنامج.\n\nالتعليمات الحرجة - اقرأ بعناية:\n\nيجب دائمًا الرد على المستخدم. لا تبقى صامتًا أبدًا.\n\nيجب دائمًا تحديث Google Sheets لكل عملية (إضافة/تعديل/حذف/إرسال بريد). هذه هي وظيفتك الأساسية.\n\nإذا حدثت أي مشكلة مع Google Sheets، أجب دائمًا ووضح المشكلة للمستخدم بطريقة ودية.\n\nاستخدم اللغة العربية دائمًا.\n\nاستخدم أسلوب طبيعي، ودود، واستخدم رموز تعبيرية أحيانًا عند الحاجة.\n\nالوقت المرجعي الحالي (بانكوك):\n{{ $now.setZone(\"Asia/Bangkok\").toFormat(\"dd-MM-yyyy HH:mm:ss\") }}\n\nالقدرات:\n\nإرسال بريد إلكتروني باستخدام Gmail.\n\nإرسال رسائل عبر Telegram لإبلاغ المستخدم بحالة العمليات.\n\nإضافة بيانات مستخدمين جديدة إلى Google Sheets.\n\nتعديل بيانات مستخدمين موجودين.\n\nحذف بيانات مستخدمين.\n\nالتحقق من وجود المستخدم في Google Sheets قبل أي عملية.\n\nالتحقق من صحة البريد الإلكتروني قبل الإضافة أو التعديل.\n\nهيكل البيانات في Google Sheets:\n{\n  \"intent\": \"add\" | \"update\" | \"delete\" | \"send_email\",\n  \"user\": \"اسم المستخدم\",\n  \"email\": \"البريد الإلكتروني\",\n  \"status\": \"pending\" | \"done\", \n  \"notes\": \"ملاحظات اختيارية\",\n  \"date\": \"YYYY-MM-DD HH:mm:ss\"\n}\n\nسير العمليات:\n\nإرسال بريد إلكتروني لشخص ما (مثال: أحمد)\n\nأرسل رسالة Telegram: \"جار إرسال ايميل لـ أحمد...\"\n\nاحصل على اسم البريد الإلكتروني من Google Sheets.\n\nاكتب البريد الإلكتروني المثالي استنادًا لما طلبه المستخدم.\n\nأرسل البريد عبر Gmail.\n\nأرسل رسالة Telegram بعد الإرسال: \"تم إرسال الايميل لأحمد بنجاح ✅\"\n\nإضافة مستخدم جديد (مثال: سامر، البريد: 211000@gmail.com\n)\n\nأرسل رسالة Telegram: \"جار إضافة سامر...\"\n\nتحقق من صحة البريد الإلكتروني.\n\nتحقق مما إذا كان المستخدم موجودًا بالفعل:\n\nإذا موجود: \"سامر موجود بالفعل ⚠️\"\n\nإذا غير موجود: أضف البيانات إلى Google Sheets، وأرسل رسالة Telegram: \"تم إضافة سامر بنجاح ✅\"\n\nتعديل بيانات مستخدم (مثال: تعديل بريد سامر)\n\nأرسل رسالة Telegram: \"جار تعديل بيانات سامر...\"\n\nتحقق من صحة البريد الإلكتروني.\n\nتحقق من وجود المستخدم:\n\nإذا موجود: عدل البيانات وأرسل رسالة Telegram: \"تم تعديل البيانات بنجاح ✅\"\n\nإذا غير موجود: \"سامر غير موجود ❌\"\n\nحذف مستخدم (مثال: حذف سامر)\n\nأرسل رسالة Telegram: \"جار حذف سامر...\"\n\nتحقق من وجود المستخدم:\n\nإذا موجود: احذف البيانات وأرسل رسالة Telegram: \"تم حذف سامر بنجاح ✅\"\n\nإذا غير موجود: \"سامر غير موجود ❌\"\n\nأسلوب التواصل:\n\nرسائل ودية، قصيرة، ومباشرة.\n\nاستخدام رموز تعبيرية عند الحاجة ✅⚠️❌\n\nتأكيد كل عملية بعد تنفيذها.\n\nلا تستخدم لغة تقنية مثل \"تم مزامنة البيانات\" أو \"العملية اكتملت\" بل استخدم تعبيرات طبيعية مثل:\n\n\"تم الحفظ!\"\n\n\"تمام، خلصنا!\"\n\n\"تم الإرسال بنجاح!\""
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "8df47a3f-bd6c-4f7d-acda-a52274bd95a6",
      "name": "在 Google Sheets1 中获取行",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        672,
        2544
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=0",
          "cachedResultName": "email"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "c09d03b1-432f-4388-9dd5-a42760a4b3c0",
      "name": "在 Google Sheets 的表格中追加行",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        48,
        2560
      ],
      "parameters": {
        "columns": {
          "value": {
            "name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('name', ``, 'string') }}",
            "email": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('email', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=0",
          "cachedResultName": "email"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "0c1a0b97-297b-4e75-a754-ff8a872d2b64",
      "name": "在 Google Sheets 中更新行",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        960,
        2480
      ],
      "parameters": {
        "columns": {
          "value": {
            "name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('name', ``, 'string') }}",
            "email": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('email', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "name"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=0",
          "cachedResultName": "email"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "95cf9ac8-ba5c-4c84-9d11-c5f9c0410d17",
      "name": "在 Gmail1 中发送消息",
      "type": "n8n-nodes-base.gmailTool",
      "position": [
        384,
        2576
      ],
      "webhookId": "3ec926cf-43db-42da-a80a-859548f10d36",
      "parameters": {
        "sendTo": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('To', ``, 'string') }}",
        "message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', ``, 'string') }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Subject', ``, 'string') }}"
      },
      "typeVersion": 2.1
    },
    {
      "id": "a0bd3cbb-b65a-4b34-869f-9c608aeafecb",
      "name": "发送到 Telegram(Gmail 频道)8",
      "type": "n8n-nodes-base.telegram",
      "notes": "Sends the enriched notification to a dedicated Telegram topic thread. Uses env vars for IDs.",
      "position": [
        832,
        2224
      ],
      "webhookId": "c8ad44e4-4c2a-43c5-a313-0025f7062159",
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "=-1003057912037",
        "additionalFields": {
          "message_thread_id": 2
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e17465df-f54b-4811-9364-486315f7b174",
      "name": "在 Telegram 中发送文本消息",
      "type": "n8n-nodes-base.telegramTool",
      "position": [
        528,
        2560
      ],
      "webhookId": "aeafc2f9-8694-4a9b-940a-efa4132b0b4c",
      "parameters": {
        "text": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Text', ``, 'string') }}",
        "chatId": "-1003057912037",
        "additionalFields": {
          "appendAttribution": false,
          "message_thread_id": 2
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3ae2c302-e5a9-4ee4-9904-7adc185d1456",
      "name": "OpenAI 聊天模型1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -192,
        2432
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-3.5-turbo",
          "cachedResultName": "gpt-3.5-turbo"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "3ffb7169-da05-4353-8e43-41458534ea68",
      "name": "从 Google Sheets 中删除行或列",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        240,
        2560
      ],
      "parameters": {
        "operation": "delete",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=0",
          "cachedResultName": "email"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        },
        "startIndex": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Start_Row_Number', ``, 'number') }}",
        "numberToDelete": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Number_of_Rows_to_Delete', ``, 'number') }}"
      },
      "typeVersion": 4.7
    },
    {
      "id": "28717007-0d53-4e61-b812-cde2c8ba9757",
      "name": "简单记忆1",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -112,
        2560
      ],
      "parameters": {
        "sessionKey": "={{ $('Incoming Message').item.json.message.from.id }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 10
      },
      "typeVersion": 1.3
    },
    {
      "id": "e2bb9f34-7280-49fb-b638-a7da5ed0a34e",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -368,
        1616
      ],
      "parameters": {
        "width": 1552,
        "height": 1296,
        "content": "## Gmail"
      },
      "typeVersion": 1
    },
    {
      "id": "5c8b81e9-2846-42d6-ae4d-de9eb52e2aa7",
      "name": "Google Calendar MCP",
      "type": "n8n-nodes-base.switch",
      "position": [
        -1456,
        3008
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "fc9811ef-3462-4693-89e7-063e36269173",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.message.reply_to_message.forum_topic_created.name }}",
                    "rightValue": "Expenses"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "b19dae1a-5ee8-4f40-8d68-93cc919e238c",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.message.reply_to_message.forum_topic_created.name }}",
                    "rightValue": "Gmail"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "05f421a1-05fa-4333-ac9e-52dc9611c372",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.message.reply_to_message.forum_topic_created.name }}",
                    "rightValue": "task"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "47995041-ac6b-425d-bb60-79066355d8a5",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.message.reply_to_message.forum_topic_created.name }}",
                    "rightValue": "Work"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "844d3b92-b2b8-4a6f-8376-80b60202a085",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -144,
        3168
      ],
      "parameters": {
        "width": 1168,
        "height": 1296,
        "content": "任务"
      },
      "typeVersion": 1
    },
    {
      "id": "68bacbab-a8b4-4e94-99ca-ad50c89c620c",
      "name": "AI Agent3",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        240,
        3264
      ],
      "parameters": {
        "text": "={{ $('Incoming Message').item.json.message.text }}\n",
        "options": {
          "systemMessage": "=You are a friendly and efficient personal assistant who helps manage todo lists through Google Sheets integration. Your personality is helpful, warm, and conversational - like talking to a supportive friend rather than interacting with software.\n\nCRITICAL INSTRUCTIONS - READ CAREFULLY\n\nYou MUST ALWAYS respond to the user. Never remain silent.\nYou MUST ALWAYS update Google Sheets for EVERY task operation (add/update/delete/complete).\nNEVER skip the Google Sheets sync step - this is your PRIMARY function.\nALWAYS confirm the Google Sheets update in your response.\nIf you encounter any issues with Google Sheets, still respond to the user explaining the issue.\n\nCurrent Time Reference (Bangkok)\n\n{{ $now.setZone(\"Asia/Bangkok\").toFormat(\"dd-MM-yyyy HH:mm:ss\") }}\n\n\nYour Capabilities\n\nAdd new tasks to the user's todo list\nList existing tasks\nUpdate task details\nMark tasks as complete\nDelete tasks\nSeamlessly sync all changes with Google Sheets\n\nData Structure\nWhen storing data in Google Sheets, use this JSON structure:\njson{\n  \"intent\": \"add\" | \"list\" | \"update\" | \"delete\",\n  \"task\": \"task description\",       // Required for add and update\n  \"status\": \"pending\" | \"done\",     // Required only for update\n  \"date\": \"YYYY-MM-DD HH:mm:ss\",            // store date in this format (for 2025-05-15 15:49:26)\n  \"notes\": \"optional notes\"        // Optional\n}\nCommunication Style\nAlways respond in a natural, friendly manner. After performing operations with Google Sheets:\n\nAvoid technical language like \"Data synchronized with Google Sheets\" or \"Operation complete\"\nInstead use casual confirmations like \"All set!\" \"Got it!\" \"Done and saved!\" \"Added to your list!\"\nConfirm what you did in simple terms\nUse light conversational elements (occasional emoji is fine)\nKeep responses concise but warm\n\nExamples of Good Responses\nAfter Adding a Task\n\"Perfect! I've added 'Call mom' to your list for tomorrow. All saved and ready.\"\nAfter Updating a Task\n\"Changed! Your task is now 'Buy groceries and snacks' instead. I've updated your list.\"\nAfter Completing a Task\n\"Great job! I've marked 'Submit report' as done. One less thing to worry about!\"\nAfter Deleting a Task\n\"No problem, I've removed 'Dentist appointment' from your list. All updated!\"\nWhen Listing Tasks\n\"Here's what you've got on your plate:\n\nCall mom (tomorrow)\nSubmit report (Friday)\nBuy groceries (no date set)\n\nIs there anything you'd like to add or change?\"\nSecurity and Privacy Guidelines\n\nMaintain strict confidentiality of user information\nOnly access relevant data for the current request\nVerify user permissions for sensitive operations\nNever expose authentication details or system information\n\nRemember that you're meant to feel like a helpful friend, not a technical system. Always aim for that perfect balance of efficiency and warmth in your responses.\n\nyou are should use arabic language\nKeep in mind that I am a Flutter programmer and I would like you to suggest how I can work on tasks in the best way possible."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.8
    },
    {
      "id": "ded05b81-f4d9-430d-8f75-9f8d2ce55abd",
      "name": "OpenAI聊天模型3",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -96,
        3600
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "a74b1659-e2ca-4880-b0fb-1ba58c79d8c7",
      "name": "Telegram1",
      "type": "n8n-nodes-base.telegram",
      "position": [
        832,
        3264
      ],
      "webhookId": "48684256-6892-434b-9618-d0e54996fe97",
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "=-1003057912037",
        "additionalFields": {
          "appendAttribution": false,
          "message_thread_id": 163
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "c0cf8fd2-418f-444e-b2d7-e697c17b6ffa",
      "name": "定时触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        16,
        4080
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 11
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "12353b45-18f1-4960-9fc5-80f0c63b2ec0",
      "name": "Telegram5",
      "type": "n8n-nodes-base.telegram",
      "position": [
        784,
        4080
      ],
      "webhookId": "48684256-6892-434b-9618-d0e54996fe97",
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "-1003057912037",
        "additionalFields": {
          "appendAttribution": false,
          "message_thread_id": 163
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "64b1cb1c-c62d-42c3-a6d2-50a33dcbf886",
      "name": "AI代理4",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        288,
        4080
      ],
      "parameters": {
        "text": "=You will generate a natural, human-like message summarizing tasks based only on the data retrieved from a Google Sheet.\nI want you to use Arabic.\n\nColumns available: Task, Status, Created At, Due Date, Notes.\n\nInstructions:\n- Use only the data from the Google Sheet. Do not invent, add, or omit any information.\n\n{{ $now.setZone(\"Asia/Bangkok\").toFormat(\"dd-MM-yyyy HH:mm:ss\") }}\n\nTask Filtering:\n\n1. Completed Tasks Today:\n- Include only tasks where Status is \"done\" AND Due Date matches today's date.\n- Ignore tasks completed on any other date.\n\n2. Future Tasks Summary:\n- Include tasks where Status is \"pending\" AND Due Date is after today.\n- Ignore tasks with due dates before or equal to today.\n\n3. Created At Filtering:\n- For both completed and future tasks, consider only tasks that were created on or after today's date.\n\nMessage Style:\n- Write in a warm, friendly, and conversational tone, as it is a quick update.\n- list the tasks in a list so it become more visually appealing\n- Avoid robotic or overly formal language.\n- Donot include # or * \n\nContent Requirements:\n- List the names of tasks completed today.\n- Provide a brief summary of future tasks (e.g., number of pending tasks or highlight important upcoming tasks).\n- If no tasks were completed today, say naturally: “No tasks were completed today.”\n- Do not mention timestamps, column names, or technical filtering details.\n\nThe message should feel like a casual but informative update from a friendly team member.\n",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "10ab94ad-53b2-4593-8394-72c0866f0e60",
      "name": "OpenAI 聊天模型4",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        240,
        4336
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "25f47498-2c81-44a4-8fbb-adfdeef2809f",
      "name": "Google Sheets3",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        240,
        3584
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 259919770,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=259919770",
          "cachedResultName": "task"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        },
        "descriptionType": "manual",
        "toolDescription": "This google should be used when user wants data tasks data\nfor example: if user says list all the tasks\nyou should list all of them by reading google sheet"
      },
      "typeVersion": 4.5
    },
    {
      "id": "effd5d9b-5b91-41fd-b982-97b8e866014a",
      "name": "Google Sheets4",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        480,
        3584
      ],
      "parameters": {
        "columns": {
          "value": {
            "Task": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Task__using_to_match_', ``, 'string') }}",
            "Status": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Status', ``, 'string') }}",
            "Due Date": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Due_Date', ``, 'string') }}",
            "Created At": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Created_At', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "Task",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Task",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Created At",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Created At",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Due Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Due Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Notes ",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Notes ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Task"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 259919770,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=259919770",
          "cachedResultName": "task"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "b19f32e9-5c8e-4a8d-836e-b9d59da0f893",
      "name": "Google Sheets6",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        656,
        3568
      ],
      "parameters": {
        "operation": "delete",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 259919770,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=259919770",
          "cachedResultName": "task"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        },
        "startIndex": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Start_Row_Number', ``, 'number') }}",
        "numberToDelete": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Number_of_Rows_to_Delete', ``, 'number') }}",
        "descriptionType": "manual",
        "toolDescription": "use this tool to delete the rows, make sure you never delete the first row as it it is the name of the columns."
      },
      "typeVersion": 4.5
    },
    {
      "id": "8dc94d35-0c9e-4a80-a4b1-c33e8d3bdf0d",
      "name": "Google Sheets7",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        528,
        4304
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 259919770,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=259919770",
          "cachedResultName": "task"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        },
        "descriptionType": "manual",
        "toolDescription": "Use this Google Sheet tool to read the data from google sheet. this google sheet have column Task, Status, Created At, Due Date and Notes.\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
      },
      "typeVersion": 4.5
    },
    {
      "id": "ab964a56-4802-41e0-920e-d3ed685d34f3",
      "name": "简单记忆2",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        48,
        3584
      ],
      "parameters": {
        "sessionKey": "={{ $('Incoming Message').item.json.message.from.id }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "2f7f4692-aa89-4cb5-a38d-fb28745e402f",
      "name": "工作追踪 AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        256,
        5424
      ],
      "parameters": {
        "text": "={{ $('Incoming Message').item.json.message.text }}\n",
        "options": {
          "systemMessage": "=أنت مساعد شخصي ذكي ومتخصص في إدارة وتتبع ساعات العمل عبر Google Sheets. شخصيتك ودودة وفعالة ومحادثية - مثل التحدث مع صديق داعم وليس برنامج.\n\nيجب أن تكون ردودك دائماً باللغة العربية.\n\n⚠️ تعليمات حاسمة - اقرأ بعناية\n\nيجب أن ترد دائماً على المستخدم. لا تبق صامتاً أبداً.\n\nيجب أن تقوم بتحديث Google Sheets لكل عملية متعلقة بالعمل (بداية/نهاية/استعلام).\n\nلا تتجاهل أبداً خطوة مزامنة Google Sheets - هذه وظيفتك الأساسية.\n\nتأكد دائماً من تأكيد تحديث Google Sheets في ردك.\n\nإذا واجهت مشاكل مع Google Sheets، اشرح المشكلة للمستخدم فوراً.\n\nالوقت الحالي (بغداد)\n{{ $now.setZone(\"Asia/Baghdad\").toFormat(\"dd-MM-yyyy HH:mm:ss\") }}\n\n✅ القدرات\n\nتسجيل بداية العمل (\"بدء العمل\" أو \"start work\")\n\nتسجيل نهاية العمل (\"انتهاء العمل\" أو \"end work\")\n\nحساب ساعات العمل تلقائياً وتحديث عمود Total hours\n\nإضافة 30 دقيقة استراحة إذا كانت ساعات العمل أكثر من 4 ساعات\n\nعرض إحصائيات العمل (كم ساعة عملت في فترة معينة)\n\nالبحث والفلترة حسب المكان أو التاريخ\n\n📊 هيكل البيانات\n\nعند التخزين في Google Sheets استخدم هذا الـ JSON:\n\n{\n  \"action\": \"start_work\" | \"end_work\" | \"query\",\n  \"date\": \"YYYY-MM-DD\",\n  \"start_time\": \"HH:mm:ss\", // فقط عند البداية\n  \"end_time\": \"HH:mm:ss\", // فقط عند النهاية  \n  \"place\": \"مكان العمل (مثلاً: المصنع، المكتب، المنزل)\",\n  \"note\": \"ملاحظات اختيارية\",\n  \"total_hours\": \"عدد الساعات المحسوبة\", // يتم تحديثه تلقائياً في Google Sheets\n  \"with_break\": true/false // هل تم إضافة استراحة 30 دقيقة؟\n}\n\n\n🧮 قواعد حساب الساعات\n\nاحسب الفرق بين وقت البداية والنهاية\n\nإذا كان إجمالي الساعات > 4، أضف 30 دقيقة للاستراحة\n\nحدث عمود Total hours تلقائياً في Google Sheets\n\nاعرض النتيجة النهائية بوضوح\n\nمثال:\n\nبداية: 08:00\n\nنهاية: 14:00\n\nإجمالي: 6 ساعات\n\nبعد إضافة الاستراحة: 6.5 ساعة\n\n🔍 أنواع الاستعلامات المدعومة\n\n\"كم ساعة عملت اليوم؟\"\n\n\"كم ساعة عملت آخر 4 أيام في المصنع؟\"\n\n\"إجمالي ساعات العمل هذا الأسبوع؟\"\n\n\"أظهر لي عملي في المكتب الأسبوع الماضي\"\n\n🗣 أسلوب التواصل\n\nرد دائماً بطريقة ودودة وواضحة كصديق يساعدك في تتبع عملك.\nلا تستخدم مصطلحات تقنية معقدة.\nاستعمل عبارات طبيعية مثل:\n\n\"تمام! سجلت بداية عملك في المصنع الساعة 8:00 صباحاً 💼\"\n\n\"رائع! انتهيت من العمل الساعة 4:00 مساءً. عملت اليوم 8.5 ساعة (مع الاستراحة) 👏\"\n\n\"حسب حساباتي، عملت آخر 4 أيام في المصنع إجمالي 34 ساعة 📊\"\n\n\"خلاص! مسحت سجل العمل اللي طلبته 🗑️\"\n\nخلي ردودك قصيرة ولطيفة ومفيدة.\n\n📝 أمثلة على الردود الجيدة\n\nبعد بداية العمل:\n\"تمام! بدأت الشغل في المصنع الساعة 8:30. إن شاء الله يوم مثمر! 💪\"\n\nبعد انتهاء العمل:\n\"انتهيت من الشغل الساعة 5:00 مساءً. عملت اليوم 8.5 ساعة (مع استراحة 30 دقيقة). أحسنت! 🎉\"\n\nعند الاستعلام:\n\"حسب السجلات، عملت آخر أسبوع:\n• المصنع: 32 ساعة\n• المكتب: 8 ساعات\n• المجموع: 40 ساعة 📈\"\n\nعند التعديل:\n\"تمام، حدثت وقت البداية إلى 9:00 بدل 8:30 ✅\"\n\n🔒 إرشادات الأمان والخصوصية\n\nحافظ على سرية بيانات العمل.\n\nلا تظهر معلومات غير مطلوبة.\n\nتأكد من دقة حسابات الساعات وعمود Total hours.\n\nسجل كل شيء باللغة العربية."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.8
    },
    {
      "id": "9002fa76-0004-4a51-addc-79491f4740fa",
      "name": "Telegram 响应",
      "type": "n8n-nodes-base.telegram",
      "position": [
        976,
        5456
      ],
      "webhookId": "48684256-6892-434b-9618-d0e54996fe97",
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "=-1003057912037",
        "additionalFields": {
          "appendAttribution": false,
          "message_thread_id": 334
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "75b888b3-7f80-4b03-9947-1f3aa492bc73",
      "name": "读取工作数据",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        672,
        5872
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1596536961,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=1596536961",
          "cachedResultName": "work"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        },
        "descriptionType": "manual",
        "toolDescription": "استخدم هذه الأداة لقراءة وعرض بيانات العمل من Google Sheets. مفيدة للاستعلامات مثل: 'كم ساعة عملت اليوم؟' أو 'أظهر لي آخر أسبوع عمل'"
      },
      "typeVersion": 4.5
    },
    {
      "id": "eba7d094-efcf-4b12-b2f6-ea6c8ecbeded",
      "name": "添加/更新工作记录",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        416,
        5840
      ],
      "parameters": {
        "columns": {
          "value": {
            "Date": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Date', 'التاريخ بصيغة YYYY-MM-DD', 'string') }}",
            "note": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('note', `ملاحظات إضافية `, 'string') }}",
            "place": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('place', 'مكان العمل (المصنع، المكتب، إلخ)', 'string') }}",
            "end at ": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('end_at', 'وقت انتهاء العمل بصيغة HH:mm:ss، اتركه فارغ عند البداية', 'string') }}",
            "start at ": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('start_at', 'وقت بداية العمل بصيغة HH:mm:ss', 'string') }}",
            "Total hours": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Total_hours', `Total hours`, 'string') }}"
          },
          "schema": [
            {
              "id": "Date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "start at ",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "start at ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "end at ",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "end at ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "place",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "place",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "note",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "note",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Total hours",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Total hours",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Date",
            "start at "
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1596536961,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=1596536961",
          "cachedResultName": "work"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        },
        "descriptionType": "manual",
        "toolDescription": "استخدم هذه الأداة لإضافة أو تحديث سجلات العمل. يجب استخدامها عند بداية العمل، انتهاء العمل، أو تعديل السجلات. تأكد من حساب ساعات العمل وإضافة 30 دقيقة استراحة إذا كان العمل أكثر من 4 ساعات."
      },
      "typeVersion": 4.5
    },
    {
      "id": "cb4655f7-6eb3-4f76-8883-d3931c4bca3a",
      "name": "删除工作记录",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        928,
        5888
      ],
      "parameters": {
        "operation": "delete",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1596536961,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=1596536961",
          "cachedResultName": "work"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        },
        "startIndex": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Start_Row_Number', 'رقم الصف المراد حذفه (يبدأ من 2، لا تحذف الصف الأول)', 'number') }}",
        "numberToDelete": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Number_of_Rows_to_Delete', 'عدد الصفوف المراد حذفها (عادة 1)', 'number') }}",
        "descriptionType": "manual",
        "toolDescription": "استخدم هذه الأداة لحذف سجلات العمل. تأكد من عدم حذف الصف الأول (أسماء الأعمدة). استخدمها فقط عندما يطلب المستخدم حذف سجل معين."
      },
      "typeVersion": 4.5
    },
    {
      "id": "b067145c-18dc-4702-ad7f-f4adcfb94325",
      "name": "月度报告触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -320,
        6144
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "months"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "4adabe9d-f49e-4466-bb3f-8a6d1395960a",
      "name": "工作时长分析器",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -48,
        6144
      ],
      "parameters": {
        "text": "=You are a work tracking analyst who creates detailed monthly work hour reports in Arabic.\n\nYour task:\n1. Analyze the work data PROVIDED TO YOU directly below this message.\n2. Group the data by workplace (place column).\n3. Calculate total hours for each workplace.\n4. Create separate detailed reports for each workplace.\n\nData Structure:\nColumns: Date, start at, end at, place, note, Total hours\n\nInstructions:\n- Group by the 'place' field (e.g., المصنع, البرمجة, المكتب, etc.).\n- Use the 'Total hours' column for calculations if available.\n- If 'Total hours' is missing or zero, calculate manually as:\n    (end_time - start_time in hours) and subtract 0.5 hours if working hours > 4.\n- Extract the month automatically from the available dates.\n- Calculate for each workplace:\n    - total_hours: sum of hours for all days\n    - total_days: count of workdays\n    - average_daily_hours: total_hours ÷ total_days\n- For each workplace, include a detailed breakdown of all days with:\n    - date\n    - start_time\n    - end_time\n    - hours_worked (including any breaks)\n    - notes\n\nOutput:\n- Respond with ONLY a JSON array containing all workplace reports.\n- Example structure:\n\n[\n  {\n    \"workplace\": \"اسم مكان العمل\",\n    \"month\": \"yyyy-MM\",\n    \"total_hours\": total hours as number,\n    \"total_days\": total workdays as number,\n    \"average_daily_hours\": average hours as number,\n    \"detailed_days\": [\n      {\n        \"date\": \"yyyy-MM-dd\",\n        \"start_time\": \"HH:mm:ss\",\n        \"end_time\": \"HH:mm:ss\",\n        \"hours_worked\": number,\n        \"notes\": \"any notes\"\n      }\n    ]\n  }\n]\n",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "2b261b4b-9236-43df-ba65-9d01485ec34f",
      "name": "分割工作场所报告",
      "type": "n8n-nodes-base.code",
      "position": [
        240,
        6144
      ],
      "parameters": {
        "jsCode": "// Parse the AI response and extract only the JSON part\nlet aiResponse = $input.first().json.output;\n\n// استخراج النص بين أول \"[\" وآخر \"]\" ليصبح JSON صالح\nconst jsonStart = aiResponse.indexOf('[');\nconst jsonEnd = aiResponse.lastIndexOf(']');\nif (jsonStart === -1 || jsonEnd === -1) {\n  return [{\n    json: {\n      error: 'No JSON found in AI response',\n      raw_response: aiResponse\n    }\n  }];\n}\n\nconst jsonString = aiResponse.slice(jsonStart, jsonEnd + 1);\n\ntry {\n  const workplaceReports = JSON.parse(jsonString);\n  const outputItems = workplaceReports.map((report, index) => ({\n    json: {\n      workplace: report.workplace,\n      month: report.month,\n      total_hours: report.total_hours,\n      total_days: report.total_days,\n      average_daily_hours: report.average_daily_hours,\n      detailed_days: report.detailed_days,\n      index: index\n    }\n  }));\n  return outputItems;\n} catch (error) {\n  console.error('Error parsing AI response:', error);\n  return [{\n    json: {\n      error: 'Failed to parse workplace reports',\n      raw_response: aiResponse\n    }\n  }];\n}\n"
      },
      "typeVersion": 2
    },
    {
      "id": "f37fbafb-8fad-446d-8387-7f6e20d33f3e",
      "name": "生成 PDF 内容",
      "type": "n8n-nodes-base.code",
      "position": [
        528,
        6144
      ],
      "parameters": {
        "jsCode": "// استدعاء البيانات من الـ input\nconst workplaceData = $input.first().json;\nif (workplaceData.error) {\n  return [{ json: workplaceData }];\n}\n\n// نبني الصفوف\nconst rows = workplaceData.detailed_days.map(day => `\n  <tr>\n    <td>${day.date}</td>\n    <td>${day.start_time}</td>\n    <td>${day.end_time}</td>\n    <td>${day.hours_worked}</td>\n    <td>${day.notes || \"-\"}</td>\n  </tr>\n`).join(\"\");\n\n// HTML مع ستايل فخم\nconst htmlContent = `\n<!DOCTYPE html>\n<html lang=\"ar\">\n<head>\n  <meta charset=\"UTF-8\">\n  <title>تقرير ${workplaceData.workplace} - ${workplaceData.month}</title>\n  <style>\n    body {\n      font-family: \"Tahoma\", \"Arial\", sans-serif;\n      direction: rtl;\n      text-align: right;\n      background: #f9f9f9;\n      color: #333;\n      margin: 40px;\n      line-height: 1.6;\n    }\n    h1 {\n      color: #2c3e50;\n      text-align: center;\n      border-bottom: 3px solid #3498db;\n      padding-bottom: 10px;\n      margin-bottom: 30px;\n    }\n    h2 {\n      margin-top: 30px;\n      color: #34495e;\n    }\n    p {\n      font-size: 16px;\n      margin: 5px 0;\n    }\n    table {\n      width: 100%;\n      border-collapse: collapse;\n      margin-top: 20px;\n      background: #fff;\n      box-shadow: 0 2px 6px rgba(0,0,0,0.1);\n      border-radius: 6px;\n      overflow: hidden;\n    }\n    th {\n      background: #3498db;\n      color: #fff;\n      font-weight: bold;\n      font-size: 14px;\n      padding: 12px;\n    }\n    td {\n      border: 1px solid #ddd;\n      padding: 10px;\n      font-size: 14px;\n    }\n    tr:nth-child(even) { background: #f2f9ff; }\n    tr:hover { background: #eaf6ff; }\n  </style>\n</head>\n<body>\n  <h1>📊 تقرير ساعات العمل - ${workplaceData.workplace}</h1>\n\n  <p><b>📅 الشهر:</b> ${workplaceData.month}</p>\n  <p><b>⏱️ إجمالي الساعات:</b> ${workplaceData.total_hours}</p>\n  <p><b>📆 عدد الأيام:</b> ${workplaceData.total_days}</p>\n  <p><b>⚖️ المتوسط اليومي:</b> ${workplaceData.average_daily_hours}</p>\n\n  <h2>تفاصيل الأيام:</h2>\n  <table>\n    <thead>\n      <tr>\n        <th>التاريخ</th>\n        <th>بداية</th>\n        <th>نهاية</th>\n        <th>عدد الساعات</th>\n        <th>ملاحظات</th>\n      </tr>\n    </thead>\n    <tbody>\n      ${rows}\n    </tbody>\n  </table>\n</body>\n</html>\n`;\n\nreturn [{\n  json: {\n    workplace: workplaceData.workplace,\n    month: workplaceData.month,\n    htmlContent: htmlContent,\n    fileName: `تقرير_${workplaceData.workplace}_${workplaceData.month}.pdf`\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "b1a913cd-e3c8-4edc-9f61-eda1f2dc1cfb",
      "name": "读取工作数据1",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        112,
        6400
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1596536961,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit#gid=1596536961",
          "cachedResultName": "work"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1S_M-0IxU84HYrkNHlIC7CivdI0KYlC3tWh48rAIx3O8/edit?usp=drivesdk",
          "cachedResultName": "My Assistants"
        },
        "descriptionType": "manual",
        "toolDescription": "استخدم هذه الأداة لقراءة جميع بيانات العمل من Google Sheets. البيانات تحتوي على الأعمدة: Date, start at, end at, place, note"
      },
      "typeVersion": 4.5
    },
    {
      "id": "8c9c4311-16d9-4c36-998e-857df1adf515",
      "name": "发送 PDF 到 Telegram1",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1024,
        6144
      ],
      "webhookId": "2dcafbf1-8b2e-4e77-b6d2-8be23116e7e4",
      "parameters": {
        "chatId": "-1003057912037",
        "operation": "sendDocument",
        "binaryData": true,
        "additionalFields": {
          "caption": "📄 تقرير العمل الشهري",
          "message_thread_id": 334
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "d9645b89-8c5a-4431-ae3a-b86bcd56c3db",
      "name": "OpenAI 聊天模型5",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -224,
        5856
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "7e5bb234-9964-414c-a1e3-7aca6312d12f",
      "name": "简单记忆3",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        176,
        5872
      ],
      "parameters": {
        "sessionKey": "={{ $('Incoming Message').item.json.message.from.id }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "490c02bf-40b2-4245-8753-85ef97bcff88",
      "name": "OpenAI 聊天模型6",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -48,
        6400
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "b4a08cf1-eccf-425f-bf24-765753e34a2a",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -368,
        5328
      ],
      "parameters": {
        "width": 1664,
        "height": 1296,
        "content": "**工作"
      },
      "typeVersion": 1
    },
    {
      "id": "5139c930-4d6b-4d64-a9c6-68b0736fd793",
      "name": "转换为文件",
      "type": "n8n-nodes-base.code",
      "position": [
        736,
        6144
      ],
      "parameters": {
        "jsCode": "// ناخذ الـ item من الـ input (النود السابق)\nconst item = $input.first().json;\n\n// نقرأ الـ HTML\nconst html = item.htmlContent;\n\n// نرجع الناتج: JSON + Binary\nreturn [\n  {\n    json: {\n      workplace: item.workplace,\n      month: item.month,\n      fileName: item.fileName\n    },\n    binary: {\n      data: {\n        data: Buffer.from(html).toString(\"base64\"),\n        mimeType: \"text/html\",\n        fileName: \"document.html\" // ملف مؤقت، بعد التحويل بيصير PDF\n      }\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "3d7375de-15fa-44b2-a3b2-9e2250a0bb8a",
  "connections": {
    "Switch": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI Agent3",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Work Tracking AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent1": {
      "main": [
        [
          {
            "node": "Send to Telegram (Gmail Channel)8",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent2": {
      "main": [
        [
          {
            "node": "Telegram4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent3": {
      "main": [
        [
          {
            "node": "Telegram1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent4": {
      "main": [
        [
          {
            "node": "Telegram5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets1": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets2": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets3": {
      "ai_tool": [
        [
          {
            "node": "AI Agent3",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets4": {
      "ai_tool": [
        [
          {
            "node": "AI Agent3",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets5": {
      "ai_tool": [
        [
          {
            "node": "AI Agent2",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets6": {
      "ai_tool": [
        [
          {
            "node": "AI Agent3",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets7": {
      "ai_tool": [
        [
          {
            "node": "AI Agent4",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Read Work Data": {
      "ai_tool": [
        [
          {
            "node": "Work Tracking AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory1": {
      "ai_memory": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory2": {
      "ai_memory": [
        [
          {
            "node": "AI Agent3",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory3": {
      "ai_memory": [
        [
          {
            "node": "Work Tracking AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Message a model": {
      "main": [
        [
          {
            "node": "Send to Telegram (Gmail Channel)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Message a model3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Work Data1": {
      "ai_tool": [
        [
          {
            "node": "Work Hours Analyzer",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "convert to file": {
      "main": [
        [
          {
            "node": "Send PDF to Telegram1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Incoming Message": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message a model3": {
      "main": [
        [
          {
            "node": "Send to Telegram (Gmail Channel)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send to Telegram (Gmail Channel)6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "AI Agent4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger1": {
      "main": [
        [
          {
            "node": "AI Agent2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Work Record": {
      "ai_tool": [
        [
          {
            "node": "Work Tracking AI Agent",
            "type": "ai_tool",
            "index": 2
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent2",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model3": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent3",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model4": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent4",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model5": {
      "ai_languageModel": [
        [
          {
            "node": "Work Tracking AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model6": {
      "ai_languageModel": [
        [
          {
            "node": "Work Hours Analyzer",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Work Hours Analyzer": {
      "main": [
        [
          {
            "node": "Split Workplace Reports",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate PDF Content": {
      "main": [
        [
          {
            "node": "convert to file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Full Email Body": {
      "main": [
        [
          {
            "node": "Parse & Structure Email Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add/Update Work Record": {
      "ai_tool": [
        [
          {
            "node": "Work Tracking AI Agent",
            "type": "ai_tool",
            "index": 1
          }
        ]
      ]
    },
    "Monthly Report Trigger": {
      "main": [
        [
          {
            "node": "Work Hours Analyzer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Work Tracking AI Agent": {
      "main": [
        [
          {
            "node": "Telegram Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Workplace Reports": {
      "main": [
        [
          {
            "node": "Generate PDF Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message in Gmail1": {
      "ai_tool": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger (New Emails)": {
      "main": [
        [
          {
            "node": "Fetch Full Email Body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse & Structure Email Data": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a text message in Telegram": {
      "ai_tool": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Append row in sheet in Google Sheets": {
      "ai_tool": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Update row in sheet in Google Sheets": {
      "ai_tool": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet in Google Sheets1": {
      "ai_tool": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Delete rows or columns from sheet in Google Sheets": {
      "ai_tool": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

这是一个高级难度的工作流,适用于AI Chatbot、Multimodal AI等场景。适合高级用户,包含 16+ 个节点的复杂工作流

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量62
分类2
节点类型17
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Mahmoud Shrouf

Mahmoud Shrouf

@mahmoud-shrouf

Flutter Developer with 3+ years of experience. Skilled in building cross-platform apps with clean architecture. Experienced in AI agents, Automation AI, and workflow automation. Passionate about creating smart solutions that simplify daily tasks

外部链接
在 n8n.io 上查看 →

分享此工作流