{
  "nodes": [
    {
      "id": "bf47fb65-15dd-44e7-a0ed-8bad3d6b21f8",
      "name": "Main Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -304,
        -432
      ],
      "parameters": {
        "color": 4,
        "width": 404,
        "height": 1424,
        "content": "## \ud83e\udd16 PRIVATE AI VIRTUAL ASSISTANT\n\n**What you're looking at:**\nA production-ready AI assistant that handles business tasks through natural conversation on Telegram. This example shows meeting scheduling, but the architecture supports ANY business automation you can imagine.\n\n**Why this is powerful:**\n- **Natural language interface:** Talk to your assistant like a human\n- **Autonomous execution:** AI decides which tools to use and executes multi-step workflows\n- **Context-aware:** Remembers conversations, understands your business\n- **Infinitely extensible:** Add new capabilities by connecting tools and updating instructions\n- **Privacy-first:** Your data stays in your Google Sheets/Calendar\n\n**Current capabilities (Meeting Scheduler):**\n\u2705 Natural language request parsing\n\u2705 CRM contact lookup from Google Sheets\n\u2705 Google Calendar availability checking\n\u2705 Intelligent time slot proposals\n\u2705 Automated event creation\n\u2705 Professional email confirmations\n\u2705 Conversation logging & analytics\n\u2705 Error handling & notifications\n\n**Easy to expand to:**\n\ud83d\udca1 Invoice generation & tracking\n\ud83d\udca1 Customer support automation\n\ud83d\udca1 Report generation from multiple sources\n\ud83d\udca1 Lead qualification & scoring\n\ud83d\udca1 Task management & reminders\n\ud83d\udca1 Email drafting & management\n\ud83d\udca1 Research & summarization\n\ud83d\udca1 Data entry & processing\n\ud83d\udca1 ...literally anything you need\n\n**How to customize:**\n1. Edit AI Agent system prompt (your \"instruction manual\")\n2. Connect new tools (APIs, databases, services)\n3. AI automatically learns to use them\n4. No code changes needed!\n\n**Perfect for:**\n\ud83c\udfaf Entrepreneurs automating operations\n\ud83c\udfaf Consultants managing clients\n\ud83c\udfaf Sales teams coordinating outreach\n\ud83c\udfaf Teams reducing manual work\n\ud83c\udfaf Anyone building custom automation\n\n**Tech stack:**\n- Telegram (natural interface)\n- OpenAI GPT-4o (autonomous reasoning)\n- Google Sheets (CRM/logging)\n- Google Calendar (scheduling)\n- Gmail (communications)\n\n**Getting started:**\n1. Connect your credentials\n2. Set up CRM in Google Sheets\n3. Customize AI prompt for your needs\n4. Start chatting with your assistant!\n\n\ud83d\ude80 **This is the future of personal business automation**"
      },
      "typeVersion": 1
    },
    {
      "id": "08613d19-4e62-4225-86cd-5c33bf4325c8",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        144,
        -432
      ],
      "parameters": {
        "color": 6,
        "content": "## 1\ufe0f\u20e3 TRIGGER\n\nReceives messages from Telegram.\nUser sends: \"Schedule meeting with Anna on Friday\""
      },
      "typeVersion": 1
    },
    {
      "id": "868b5e9c-985b-4015-bc97-450178ed739a",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        432,
        -432
      ],
      "parameters": {
        "color": 6,
        "content": "## 2\ufe0f\u20e3 PREPARE DATA\n\nExtracts:\n- User's message text\n- Chat ID\n- User name"
      },
      "typeVersion": 1
    },
    {
      "id": "d5073eaf-d908-4a00-b582-cadb1d054225",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        704,
        -432
      ],
      "parameters": {
        "color": 5,
        "content": "## 3\ufe0f\u20e3 LOAD CRM DATA\n\nFetches contact database from Google Sheets.\nFormat: Name | Email | Phone"
      },
      "typeVersion": 1
    },
    {
      "id": "a93b82a9-782e-41d6-94f1-21121579ac8d",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        992,
        -432
      ],
      "parameters": {
        "color": 3,
        "width": 280,
        "height": 200,
        "content": "## 4\ufe0f\u20e3 AI AGENT\n\nProcesses request:\n\u2705 Finds contact in CRM\n\u2705 Checks calendar availability\n\u2705 Proposes 3 time slots\n\u2705 Confirms selection\n\u2705 Creates meeting"
      },
      "typeVersion": 1
    },
    {
      "id": "60864fb3-8e64-48eb-8c55-d1d622227fb9",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1312,
        -432
      ],
      "parameters": {
        "color": 4,
        "height": 224,
        "content": "## 5\ufe0f\u20e3 SEND RESPONSE\n\nReplies to user on Telegram with:\n- Available time slots\n- Confirmation message\n- Meeting details"
      },
      "typeVersion": 1
    },
    {
      "id": "c56fe12f-7dc0-484b-bf26-07be9b128140",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1584,
        -432
      ],
      "parameters": {
        "color": 7,
        "width": 260,
        "height": 180,
        "content": "## 6\ufe0f\u20e3 CREATE EVENT & EMAIL\n\nOn confirmation:\n\u2705 Creates Google Calendar event\n\u2705 Sends email to attendee\n\u2705 Invites both parties"
      },
      "typeVersion": 1
    },
    {
      "id": "e2fafb54-d29c-41f5-a27b-eacdf06d19ac",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        192,
        -176
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "c341f437-2ee8-44aa-8244-d450f6090d3d",
      "name": "Prepare Data",
      "type": "n8n-nodes-base.set",
      "position": [
        368,
        -176
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "user-message",
              "name": "user_message",
              "type": "string",
              "value": "={{ $json.message.text }}"
            },
            {
              "id": "chat-id",
              "name": "chat_id",
              "type": "string",
              "value": "={{ $json.message.chat.id }}"
            },
            {
              "id": "user-name",
              "name": "user_name",
              "type": "string",
              "value": "={{ $json.message.from.first_name }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "5ec6cefc-a890-4835-ad74-d995f6b80eba",
      "name": "Load CRM Data",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        544,
        -176
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "CRM"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        },
        "authentication": "serviceAccount"
      },
      "typeVersion": 4.6
    },
    {
      "id": "9b0aa7f7-f978-4b12-8373-6ad750c1ef52",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        752,
        -176
      ],
      "parameters": {
        "text": "=Current date: {{ $now.setZone('Europe/Warsaw').toFormat('yyyy-MM-dd') }}\nUser message: {{ $('Prepare Data').item.json.user_message }}\nCRM contacts: {{ JSON.stringify($('Load CRM Data').all().map(item => ({name: item.json.Name, email: item.json.Email}))) }}",
        "options": {
          "maxIterations": 10,
          "systemMessage": "You are a scheduling assistant. Help users book meetings by:\n1. Finding contacts in the CRM database\n2. Checking Google Calendar for availability (9 AM - 4 PM)\n3. Proposing 3 available time slots\n4. Creating calendar events after user confirms\n\nAlways respond in a friendly, concise manner. When proposing times, format as:\n'I checked the calendar. Here are 3 available slots:\n\u2022 10:00-11:00\n\u2022 14:00-15:00  \n\u2022 16:00-17:00\nWhich time works for you?'\n\nOutput JSON format:\n{\n  \"message\": \"response to user\",\n  \"action\": \"propose_slots\" or \"create_event\" or \"clarify\",\n  \"contact_email\": \"user@example.com\",\n  \"meeting_date\": \"YYYY-MM-DD\",\n  \"meeting_time\": \"HH:00\"\n}"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.9
    },
    {
      "id": "6be1dd14-4e9b-4e2e-9b63-d290986c4ff9",
      "name": "OpenAI Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        576,
        32
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "ad13639a-4ec2-4c0e-a4b0-c2c7ad2da243",
      "name": "Google Calendar Tool",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        752,
        32
      ],
      "parameters": {
        "calendar": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_CALENDAR_ID"
        },
        "additionalFields": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "d9d903ea-2975-4e28-8a39-66e3c9f39459",
      "name": "CRM Search Tool",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        912,
        32
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "CRM"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "3f024701-0593-45b8-bd46-3ad1e31de8bf",
      "name": "Send Response",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1088,
        -176
      ],
      "parameters": {
        "text": "={{ $json.output.message || $json.message }}",
        "chatId": "={{ $('Prepare Data').item.json.chat_id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "bf820462-92f0-4de7-af70-a0f815fd0574",
      "name": "Should Create Event?",
      "type": "n8n-nodes-base.if",
      "position": [
        1104,
        32
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "action-check",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.output.action }}",
              "rightValue": "create_event"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "6a96d132-44fd-4c7c-a91d-2d4560d61d18",
      "name": "Create Calendar Event",
      "type": "n8n-nodes-base.googleCalendar",
      "position": [
        1344,
        -80
      ],
      "parameters": {
        "end": "={{ $json.output.meeting_date }}T{{ String(parseInt($json.output.meeting_time.split(':')[0]) + 1).padStart(2, '0') }}:00:00",
        "start": "={{ $json.output.meeting_date }}T{{ $json.output.meeting_time }}:00",
        "calendar": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_CALENDAR_ID"
        },
        "additionalFields": {
          "summary": "Meeting: {{ $('Prepare Data').item.json.user_name }} & {{ $json.output.contact_name }}",
          "attendees": [
            "={{ $json.output.contact_email }}"
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "7f609783-fbf6-4951-9d4d-cfcfc10185f0",
      "name": "Send Confirmation Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1552,
        -80
      ],
      "parameters": {
        "sendTo": "={{ $('AI Agent').item.json.output.contact_email }}",
        "message": "=<html>\n<body style=\"font-family: Arial, sans-serif; padding: 20px;\">\n  <h2>\ud83d\udcc5 Meeting Confirmation</h2>\n  <p>Hello {{ $('AI Agent').item.json.output.contact_name }},</p>\n  <p>Your meeting has been scheduled:</p>\n  <ul>\n    <li><strong>Date:</strong> {{ $('AI Agent').item.json.output.meeting_date }}</li>\n    <li><strong>Time:</strong> {{ $('AI Agent').item.json.output.meeting_time }}</li>\n    <li><strong>With:</strong> {{ $('Prepare Data').item.json.user_name }}</li>\n  </ul>\n  <p><a href=\"{{ $json.htmlLink }}\" style=\"background: #4285f4; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px; display: inline-block;\">Open in Calendar</a></p>\n  <p>Best regards,<br>Your AI Assistant</p>\n</body>\n</html>",
        "options": {},
        "subject": "Meeting Scheduled: {{ $('AI Agent').item.json.output.meeting_date }} {{ $('AI Agent').item.json.output.meeting_time }}"
      },
      "typeVersion": 2.1
    }
  ],
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send Response",
            "type": "main",
            "index": 0
          },
          {
            "node": "Should Create Event?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Data": {
      "main": [
        [
          {
            "node": "Load CRM Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load CRM Data": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CRM Search Tool": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Prepare Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Calendar Tool": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Should Create Event?": {
      "main": [
        [
          {
            "node": "Create Calendar Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Calendar Event": {
      "main": [
        [
          {
            "node": "Send Confirmation Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}