وكيل ذكي لتحصيل الفواتير المتأخرة

كل صباح يراجع الوكيل الفواتير المتأخرة، ويكتب مسودات تذكير بالنبرة المناسبة، وينبّهك للفواتير التي تحتاج مكالمة.

وكيل ذكيمتقدم توفّر ~10 ساعة شهريًا وكلاء الذكاء الاصطناعيبواسطة فريق Flowngn

تعمل مع n8n · Make · Zapier

كيف تعمل

المشغّل: جدول زمني — أيام العمل الساعة 9:00
  1. يقرأ الوكيل جدول الفواتير.
  2. لكل فاتورة غير مدفوعة تجاوزت موعدها، يحدد الخطوة التالية حسب مدة التأخير.
  3. يكتب مسودة تذكير في Gmail (ودية أولًا ثم أكثر حزمًا) ويسجلها في الجدول.
  4. الفواتير المتأخرة أكثر من 30 يومًا تُرسل إلى Slack ليتصل أحد بالعميل.

ماذا يستطيع أن يفعل

على عكس الأتمتة الثابتة، يقرر الوكيل أي أدواته يستخدم وبأي ترتيب — ويتذكر المحادثة.

  • يختار النبرة حسب أيام التأخير وعدد التذكيرات السابقة
  • يكتب الرسائل بلغة العميل مع رقم الفاتورة والمبلغ ورابط الدفع
  • يحدّث الجدول بتاريخ آخر تذكير
  • يرسل للفريق ملخصًا يوميًا قصيرًا

التعليمات (System prompt)

التعليمات التي تشكّل سلوك الوكيل. موجودة بالفعل داخل قالب n8n — انسخها إلى Make أو Zapier، وعدّل أجزاء YOUR_….

التعليمات (System prompt)
You are the accounts receivable assistant for YOUR_COMPANY. Today is {{ $now.toFormat('cccc d LLLL yyyy') }}.

You get a list of overdue invoices. For EACH invoice, decide the next step:
- 1–7 days late, no reminder in the last 5 days: a friendly reminder ("in case it slipped through").
- 8–30 days late, no reminder in the last 5 days: a clear, polite reminder asking for a payment date.
- Over 30 days late: draft a firm but polite reminder AND include it in the team alert so someone calls the client.
- A reminder sent in the last 5 days: do nothing for that invoice.

Tools:
- "Draft reminder": creates a Gmail draft (never sends). Write in the client's language if it's clear from their name or company; otherwise English. Include the invoice number, amount, days overdue and the payment link YOUR_PAYMENT_LINK. Sign as YOUR_NAME.
- "Update invoice": records that a reminder was drafted. Call it once per invoice you drafted for, with the new reminder count.
- "Alert team": posts one message to Slack. Call it once at the end with a short summary: how many drafts, and the invoices over 30 days that need a call.

Rules:
- Never threaten, mention legal action, add late fees or offer discounts.
- Never invent amounts, dates or invoice numbers; use only the data you were given.
- Finish with a one-line summary of what you did.

قواعد الأمان

مدمجة في التعليمات والأدوات:

  • يكتب مسودات فقط ولا يرسل أي بريد
  • لا يهدد ولا يضيف غرامات ولا يعرض خصومات
  • يتجاهل الفواتير المعلَّمة بأنها محل خلاف

يستخدم مفتاح الذكاء الاصطناعي الخاص بك (Claude أو OpenAI أو غيرهما). التكلفة تعتمد على النموذج وطول المحادثة — والنموذج الصغير السريع يجعل معظم المحادثات بجزء من السنت.

المخطط

trueWeekdays 9:00Schedule TriggerGRead invoicesGoogle Sheets{ }Collect overdueCode⑂Any overdue?IfCollections agentAI AgentClaude modelAnthropic Chat Mo…GDraft reminderGmail ToolGUpdate invoiceGoogle Sheets ToolSAlert teamSlack Tool
مشغّل تطبيق منطق كود ذكاء اصطناعي أداة للوكيل

الكود

كود JavaScript المستخدم في خطوات Code، وهو مضمَّن بالفعل في القالب بالأسفل.

Collect overdue · عقدة Code
// Invoices sheet columns: invoice | client | email | amount | currency | due_date | status | reminders | last_reminder
// Gathers every unpaid, undisputed invoice past its due date into one list for the agent.
const DAY = 24 * 60 * 60 * 1000;
const today = new Date();
today.setHours(0, 0, 0, 0);

const overdue = $input.all()
  .map((item) => item.json)
  .filter((r) => !["paid", "disputed"].includes(String(r.status).toLowerCase()))
  .filter((r) => r.email && new Date(r.due_date) < today)
  .map((r) => ({
    invoice: r.invoice,
    client: r.client,
    email: r.email,
    amount: `${r.amount} ${r.currency || ""}`.trim(),
    days_late: Math.floor((today - new Date(r.due_date)) / DAY),
    reminders_sent: Number(r.reminders) || 0,
    last_reminder: r.last_reminder || "never",
  }));

return [{ json: { count: overdue.length, invoices: overdue } }];

ابنِها بأداتك

اختر أداتك — نفس الأتمتة، خطوة بخطوة.

انسخه والصقه مباشرة في مساحة عمل n8n (Ctrl+V)، أو حمّله واستخدم Import from File. بعد ذلك اربط حساباتك واستبدل كل قيمة تبدأ بـ YOUR_. خطوات الذكاء الاصطناعي تستخدم نموذج Claude، ويمكنك استبداله بـ OpenAI أو Gemini أو Ollama.

ملف Workflow JSON
عرض الكود (322 سطر)
{
  "name": "وكيل ذكي لتحصيل الفواتير المتأخرة (Flowngn)",
  "nodes": [
    {
      "parameters": {
        "content": "## وكيل ذكي لتحصيل الفواتير المتأخرة\nكل صباح يراجع الوكيل الفواتير المتأخرة، ويكتب مسودات تذكير بالنبرة المناسبة، وينبّهك للفواتير التي تحتاج مكالمة.\n\n**Setup**\n1. Open each node and connect your own credentials.\n2. Replace every YOUR_… placeholder.\n3. Test once, then activate.\n\nFree template from Flowngn",
        "height": 260,
        "width": 340
      },
      "id": "2c527986-e838-40f5-a594-fbb4654a5a4e",
      "name": "Setup notes",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -420,
        -60
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 9 * * 1-5"
            }
          ]
        }
      },
      "id": "2c527986-e838-40f5-a594-fbb4654a5a4e",
      "name": "Weekdays 9:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "value": "YOUR_SPREADSHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Invoices",
          "mode": "name"
        },
        "options": {}
      },
      "id": "2c527986-e838-40f5-a594-fbb4654a5a4e",
      "name": "Read invoices",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        300,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Invoices sheet columns: invoice | client | email | amount | currency | due_date | status | reminders | last_reminder\n// Gathers every unpaid, undisputed invoice past its due date into one list for the agent.\nconst DAY = 24 * 60 * 60 * 1000;\nconst today = new Date();\ntoday.setHours(0, 0, 0, 0);\n\nconst overdue = $input.all()\n  .map((item) => item.json)\n  .filter((r) => ![\"paid\", \"disputed\"].includes(String(r.status).toLowerCase()))\n  .filter((r) => r.email && new Date(r.due_date) < today)\n  .map((r) => ({\n    invoice: r.invoice,\n    client: r.client,\n    email: r.email,\n    amount: `${r.amount} ${r.currency || \"\"}`.trim(),\n    days_late: Math.floor((today - new Date(r.due_date)) / DAY),\n    reminders_sent: Number(r.reminders) || 0,\n    last_reminder: r.last_reminder || \"never\",\n  }));\n\nreturn [{ json: { count: overdue.length, invoices: overdue } }];"
      },
      "id": "2c527986-e838-40f5-a594-fbb4654a5a4e",
      "name": "Collect overdue",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        600,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.count }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "2c527986-e838-40f5-a594-fbb4654a5a4e",
      "name": "Any overdue?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        900,
        0
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Overdue invoices:\n{{ JSON.stringify($json.invoices, null, 2) }}",
        "options": {
          "systemMessage": "=You are the accounts receivable assistant for YOUR_COMPANY. Today is {{ $now.toFormat('cccc d LLLL yyyy') }}.\n\nYou get a list of overdue invoices. For EACH invoice, decide the next step:\n- 1–7 days late, no reminder in the last 5 days: a friendly reminder (\"in case it slipped through\").\n- 8–30 days late, no reminder in the last 5 days: a clear, polite reminder asking for a payment date.\n- Over 30 days late: draft a firm but polite reminder AND include it in the team alert so someone calls the client.\n- A reminder sent in the last 5 days: do nothing for that invoice.\n\nTools:\n- \"Draft reminder\": creates a Gmail draft (never sends). Write in the client's language if it's clear from their name or company; otherwise English. Include the invoice number, amount, days overdue and the payment link YOUR_PAYMENT_LINK. Sign as YOUR_NAME.\n- \"Update invoice\": records that a reminder was drafted. Call it once per invoice you drafted for, with the new reminder count.\n- \"Alert team\": posts one message to Slack. Call it once at the end with a short summary: how many drafts, and the invoices over 30 days that need a call.\n\nRules:\n- Never threaten, mention legal action, add late fees or offer discounts.\n- Never invent amounts, dates or invoice numbers; use only the data you were given.\n- Finish with a one-line summary of what you did."
        }
      },
      "id": "2c527986-e838-40f5-a594-fbb4654a5a4e",
      "name": "Collections agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.9,
      "position": [
        1200,
        0
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "claude-sonnet-5",
          "mode": "list"
        },
        "options": {}
      },
      "id": "2c527986-e838-40f5-a594-fbb4654a5a4e",
      "name": "Claude model",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "typeVersion": 1.3,
      "position": [
        945,
        220
      ]
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Creates a Gmail draft reminder to a client (never sends).",
        "resource": "draft",
        "operation": "create",
        "subject": "={{ $fromAI('subject', \"Email subject, including the invoice number\", 'string') }}",
        "message": "={{ $fromAI('body', \"Email body\", 'string') }}",
        "options": {
          "sendTo": "={{ $fromAI('to', \"The client's email address\", 'string') }}"
        }
      },
      "id": "2c527986-e838-40f5-a594-fbb4654a5a4e",
      "name": "Draft reminder",
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        1115,
        220
      ]
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Records that a reminder was drafted for an invoice.",
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "YOUR_SPREADSHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Invoices",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "invoice": "={{ $fromAI('invoice', \"The invoice number\", 'string') }}",
            "reminders": "={{ $fromAI('reminders', \"New number of reminders sent\", 'number') }}",
            "last_reminder": "={{ $now.toISODate() }}"
          },
          "matchingColumns": [
            "invoice"
          ]
        },
        "options": {}
      },
      "id": "2c527986-e838-40f5-a594-fbb4654a5a4e",
      "name": "Update invoice",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.5,
      "position": [
        1285,
        220
      ]
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Posts the daily collections summary to the team.",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "#finance",
          "mode": "name"
        },
        "text": "={{ $fromAI('message', \"Drafts created, and invoices over 30 days that need a call\", 'string') }}",
        "otherOptions": {}
      },
      "id": "2c527986-e838-40f5-a594-fbb4654a5a4e",
      "name": "Alert team",
      "type": "n8n-nodes-base.slackTool",
      "typeVersion": 2.2,
      "position": [
        1455,
        220
      ]
    }
  ],
  "connections": {
    "Weekdays 9:00": {
      "main": [
        [
          {
            "node": "Read invoices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read invoices": {
      "main": [
        [
          {
            "node": "Collect overdue",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Collect overdue": {
      "main": [
        [
          {
            "node": "Any overdue?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Any overdue?": {
      "main": [
        [
          {
            "node": "Collections agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claude model": {
      "ai_languageModel": [
        [
          {
            "node": "Collections agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Draft reminder": {
      "ai_tool": [
        [
          {
            "node": "Collections agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Update invoice": {
      "ai_tool": [
        [
          {
            "node": "Collections agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Alert team": {
      "ai_tool": [
        [
          {
            "node": "Collections agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}

← افتحها في ساحة التجربة لتعديلها

نصائح

  • راجع المسودات كل صباح في الأسابيع الأولى، واحتفظ بالجيد منها كأمثلة داخل الـprompt.

أتمتات مشابهة