{
  "name": "Google Calendar Manager",
  "nodes": [
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $json.telegramID }}"
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        160,
        340
      ],
      "id": "f85ffc43-6d59-407a-acb0-34d93377811c",
      "name": "Window Buffer Memory"
    },
    {
      "parameters": {
        "operation": "search",
        "base": {
          "__rl": true,
          "value": "appXXXXXXXXXXXXXX",
          "mode": "list",
          "cachedResultName": "CRM Database",
          "cachedResultUrl": "https://airtable.com/appXXXXXXXXXXXXXX"
        },
        "table": {
          "__rl": true,
          "value": "tblXXXXXXXXXXXXXX",
          "mode": "list",
          "cachedResultName": "People",
          "cachedResultUrl": "https://airtable.com/appXXXXXXXXXXXXXX/tblXXXXXXXXXXXXXX"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.airtableTool",
      "typeVersion": 2.1,
      "position": [
        840,
        340
      ],
      "id": "956d57ee-0d86-44ae-9cab-189ea5327449",
      "name": "Search CRM",
      "disabled": true
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Searches google calendar events",
        "operation": "getAll",
        "calendar": {
          "__rl": true,
          "value": "your.email@gmail.com",
          "mode": "list",
          "cachedResultName": "your.email@gmail.com"
        },
        "timeMin": "={{ $fromAI('startTime','the start time and day of events being searched') }}",
        "timeMax": "={{ $fromAI('endTime','the end time and day of events being searched') }}",
        "options": {}
      },
      "type": "n8n-nodes-base.googleCalendarTool",
      "typeVersion": 1.3,
      "position": [
        340,
        340
      ],
      "id": "81cf3dbd-496e-4e07-bed7-61d868f094ab",
      "name": "Searches Calendar",
      "credentials": {
        "googleCalendarOAuth2Api": {
          "id": "hNiPd7dtiHalIacu",
          "name": "Google Calendar account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Creates google calendar events",
        "calendar": {
          "__rl": true,
          "value": "your.email@gmail.com",
          "mode": "list",
          "cachedResultName": "your.email@gmail.com"
        },
        "start": "={{ $fromAI('startTime','the start time and day of events being created') }}",
        "end": "={{ $fromAI('endTime','the end time and day of events being created') }}",
        "additionalFields": {
          "attendees": [],
          "description": "={{ $fromAI('eventDescription','the description of the event being created with zoom link if applicable') }}",
          "summary": "={{ $fromAI('eventName','the name of the event being created') }}"
        }
      },
      "type": "n8n-nodes-base.googleCalendarTool",
      "typeVersion": 1.3,
      "position": [
        500,
        340
      ],
      "id": "94fde447-cee9-4ab7-bb30-7ce0b55d1f99",
      "name": "Create Events",
      "credentials": {
        "googleCalendarOAuth2Api": {
          "id": "hNiPd7dtiHalIacu",
          "name": "Google Calendar account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Updates google calendar events",
        "operation": "update",
        "calendar": {
          "__rl": true,
          "value": "your.email@gmail.com",
          "mode": "list",
          "cachedResultName": "your.email@gmail.com"
        },
        "eventId": "={{ $fromAI('eventID','the ID of the event needing updated') }}",
        "updateFields": {
          "description": "={{ $fromAI('eventDescription','the new event description') }}",
          "end": "={{ $fromAI('eventEnd','the new event end date and time') }}",
          "start": "={{ $fromAI('eventStart','the new event start date and time') }}",
          "summary": "={{ $fromAI('eventName','the new event name') }}"
        }
      },
      "type": "n8n-nodes-base.googleCalendarTool",
      "typeVersion": 1.3,
      "position": [
        660,
        340
      ],
      "id": "8fba29a8-23d1-4b58-b46c-ae6b1c550caa",
      "name": "Update Events",
      "credentials": {
        "googleCalendarOAuth2Api": {
          "id": "hNiPd7dtiHalIacu",
          "name": "Google Calendar account"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.chatInput }}",
        "options": {
          "systemMessage": "=<AgentInstructions>\n    <Role>\n        <Name>Event Manager Agent</Name>\n        <Description>\n            This agent manages Google Calendar events—searches for existing events, creates new ones, and updates them as requested.\n        </Description>\n        <currentDate>{{$now}}</currentDate>\n    </Role>\n\n    <Goal>\n        <Primary>\n            Efficiently handle user requests for calendar events (search, create, update) with proper date formatting.\n        </Primary>\n    </Goal>\n\n    <Instructions>\n\n        <!-- Tools Section -->\n        <Instruction>\n            Tools Available:\n            1. Search Google Calendar\n            2. Create Google Calendar Event\n            3. Update Google Calendar Event\n            4. Search CRM in Airtable\n        </Instruction>\n\n        <!-- General Behavior -->\n        <Instruction>\n            Always check user availability and existing events before creating or updating an event.\n        </Instruction>\n        <Instruction>\n            Provide clear responses and confirm event details (time, date, attendees, purpose).\n        </Instruction>\n        <Instruction>\n            Utilize the CRM (Search CRM in Airtable) to find attendee contact information and, if needed, use \"Send Emails\" to share event details or updates directly with them.\n        </Instruction>\n\n        <!-- Date & Time Handling -->\n        <Instruction>\n            For a single-date request (e.g., “What do I have on Monday?”):\n            - Use StartDate as \"YYYY-MM-DD 00:00:00\"\n            - Use EndDate as \"YYYY-MM-DD 23:59:59\"\n        </Instruction>\n        <Instruction>\n            For a range request (e.g., “From Monday to Wednesday”):\n            - Use the first day of the range with \"00:00:00\" as StartDate\n            - Use the last day of the range with \"23:59:59\" as EndDate\n        </Instruction>\n\n        <!-- Event Management Steps -->\n        <Instruction>\n            1. Parse user request for date(s), time(s), and attendee(s).\n            2. Check availability or existing events with the \"Search Google Calendar\" tool.\n            3. If a conflict exists, offer alternative times.\n            4. On confirmation, create/update the event details (time, title, attendees, notes) using the appropriate tool.\n            5. Provide a succinct response to the user with the final event details or status.\n        </Instruction>\n\n    </Instructions>\n</AgentInstructions>\n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        340,
        0
      ],
      "id": "bf3b50f9-5c25-4fee-80de-b608a9c980c6",
      "name": "Calendar Guru"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -20,
        340
      ],
      "id": "996acd00-d486-4db7-9def-81d6af514696",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "0cs0RBSsQ3W1eoL7",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "chatInput"
            },
            {
              "name": "telegramID"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        0,
        0
      ],
      "id": "0e0acac3-64c1-47e2-b993-66b890075131",
      "name": "Workflow Input Trigger"
    }
  ],
  "pinData": {},
  "connections": {
    "Window Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "Calendar Guru",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Search CRM": {
      "ai_tool": [
        [
          {
            "node": "Calendar Guru",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Searches Calendar": {
      "ai_tool": [
        [
          {
            "node": "Calendar Guru",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Create Events": {
      "ai_tool": [
        [
          {
            "node": "Calendar Guru",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Update Events": {
      "ai_tool": [
        [
          {
            "node": "Calendar Guru",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Calendar Guru",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Input Trigger": {
      "main": [
        [
          {
            "node": "Calendar Guru",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6c35c393-f8f2-4630-bff8-600435610edc",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": ""
  },
  "id": "fOdHvWYGfSYJOlaw",
  "tags": []
}