{
  "id": "kUAss6TbBXLb8HG6",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Telegram-first personal AI agent",
  "tags": [
    {
      "id": "TIMIlK5hNxVuDAlg",
      "name": "public",
      "createdAt": "2025-08-11T13:46:00.810Z",
      "updatedAt": "2025-08-11T13:46:00.810Z"
    }
  ],
  "nodes": [
    {
      "id": "15741804-50b9-4252-89e3-0f135c6a127f",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        736,
        -96
      ],
      "parameters": {
        "sessionKey": "={{ $('If').item.json.message.chat.id }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 30
      },
      "typeVersion": 1.3
    },
    {
      "id": "81ea7f9d-e749-46c7-be40-616429a439e7",
      "name": "Save Memory",
      "type": "n8n-nodes-base.airtableTool",
      "position": [
        864,
        -96
      ],
      "parameters": {
        "base": {
          "__rl": true,
          "mode": "list",
          "value": "appSSdueQKZUG68Wu",
          "cachedResultUrl": "https://airtable.com/appSSdueQKZUG68Wu",
          "cachedResultName": "Agent Memories"
        },
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "tbl59eqgFoXOJ9vv9",
          "cachedResultUrl": "https://airtable.com/appSSdueQKZUG68Wu/tbl59eqgFoXOJ9vv9",
          "cachedResultName": "Table 1"
        },
        "columns": {
          "value": {
            "User": "Your_Name",
            "Memory": "={{ $fromAI('Memory') }}"
          },
          "schema": [
            {
              "id": "Memory",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Memory",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "User",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "User",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Created",
              "type": "string",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "Created",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "create"
      },
      "credentials": {
        "airtableTokenApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "b8192282-2bd6-4a84-9ea2-0e0ac58673df",
      "name": "Get memories",
      "type": "n8n-nodes-base.airtable",
      "position": [
        -64,
        -128
      ],
      "parameters": {
        "base": {
          "__rl": true,
          "mode": "list",
          "value": "appSSdueQKZUG68Wu",
          "cachedResultUrl": "https://airtable.com/appSSdueQKZUG68Wu",
          "cachedResultName": "Agent Memories"
        },
        "sort": {
          "property": [
            {
              "field": "Created"
            }
          ]
        },
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "tbl59eqgFoXOJ9vv9",
          "cachedResultUrl": "https://airtable.com/appSSdueQKZUG68Wu/tbl59eqgFoXOJ9vv9",
          "cachedResultName": "Table 1"
        },
        "options": {},
        "operation": "search",
        "filterByFormula": "({User} = 'your_name')"
      },
      "credentials": {
        "airtableTokenApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "70adb85f-d25b-41f1-b886-19ffe2303bb4",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        160,
        -128
      ],
      "parameters": {
        "include": "specifiedFields",
        "options": {},
        "aggregate": "aggregateAllItemData",
        "fieldsToInclude": "Memory, Created",
        "destinationFieldName": "Memories"
      },
      "typeVersion": 1
    },
    {
      "id": "c0a63e6d-1cc9-4c96-aa93-25e26031bcc3",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        384,
        -320
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineAll"
      },
      "typeVersion": 3.2
    },
    {
      "id": "65fed632-8371-4b3a-a4a8-5b1441f4909b",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -960,
        -272
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {
          "chatIds": "your_telegram_id",
          "download": true
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0cbca25b-507e-4771-b2fe-9d316bbe7ded",
      "name": "Send a text message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2096,
        -320
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9164db77-04c2-4f5e-a3a8-c641d2f823c6",
      "name": "Search Web with SerpAPI",
      "type": "@n8n/n8n-nodes-langchain.toolSerpApi",
      "position": [
        992,
        -96
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "serpApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a8ecc80e-1569-4df0-8f55-1b0d8a93346c",
      "name": "Get many events in Google Calendar",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        1120,
        -96
      ],
      "parameters": {
        "options": {},
        "timeMax": "={{ $now.plus({ week: 4 }) }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": ""
        },
        "operation": "getAll"
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "fc24c542-e26a-4f8d-a7ae-3d108dd50d0c",
      "name": "Create an event in Google Calendar",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        1248,
        -96
      ],
      "parameters": {
        "end": "=",
        "start": "=",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": ""
        },
        "additionalFields": {}
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "77665a24-7ca6-4d77-904f-21bbdbc2c3a1",
      "name": "Update an event in Google Calendar",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        1376,
        -96
      ],
      "parameters": {
        "eventId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Event_ID', ``, 'string') }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": ""
        },
        "operation": "update",
        "updateFields": {}
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "f88dba24-8ab0-44c7-8cc3-438b15081fc2",
      "name": "Delete an event in Google Calendar",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        1504,
        -96
      ],
      "parameters": {
        "eventId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Event_ID', ``, 'string') }}",
        "options": {},
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultName": ""
        },
        "operation": "delete"
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "660ddae0-9950-4419-a459-822b846d86c1",
      "name": "Get many messages in Gmail",
      "type": "n8n-nodes-base.gmailTool",
      "position": [
        1632,
        -96
      ],
      "parameters": {
        "simple": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Simplify', ``, 'boolean') }}",
        "filters": {},
        "options": {},
        "operation": "getAll",
        "returnAll": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Return_All', ``, 'boolean') }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "e6b4cf06-3546-4e51-9cc4-9ca2f977c8e6",
      "name": "Get a message in Gmail",
      "type": "n8n-nodes-base.gmailTool",
      "position": [
        1760,
        -96
      ],
      "parameters": {
        "simple": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Simplify', ``, 'boolean') }}",
        "options": {},
        "messageId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message_ID', ``, 'string') }}",
        "operation": "get"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "7c9ae477-0077-4084-98be-5265ac2941f6",
      "name": "xAI Grok Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatXAiGrok",
      "position": [
        608,
        -96
      ],
      "parameters": {
        "model": "grok-4-0709",
        "options": {}
      },
      "credentials": {
        "xAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ddaa9d4d-3ce1-4400-908d-1a059240a677",
      "name": "Text vs Voice Router",
      "type": "n8n-nodes-base.if",
      "position": [
        -736,
        -272
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "3c44273e-c862-447e-9512-afa1320ff950",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.message.text }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "c3464ae3-abe6-48b5-a37e-46384488a92f",
      "name": "Transcribe a recording",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -288,
        -272
      ],
      "parameters": {
        "options": {},
        "resource": "audio",
        "operation": "transcribe"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "5efdd1d7-3a22-49f2-a95e-3aa3349795ef",
      "name": "Get a file",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -512,
        -272
      ],
      "parameters": {
        "fileId": "={{ $json.message.voice.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0dcc47a7-8c78-4328-bb78-d3b78cdd18c7",
      "name": "Get a database in Notion",
      "type": "n8n-nodes-base.notionTool",
      "position": [
        1888,
        -96
      ],
      "parameters": {
        "simple": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Simplify', ``, 'boolean') }}",
        "resource": "database",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        }
      },
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "d5abb03f-5fd6-4103-b4f1-f357e448977a",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1184,
        -320
      ],
      "parameters": {
        "text": "={{ $json.text }}{{ $json.message.text }}",
        "options": {
          "systemMessage": "=# ROLE  \nYou are a friendly AI assistant.  \nYou are talking to ____. Your name is ____, your gender is ____.\n\n# RULES  \nWhen the user sends a new message, determine whether it contains information that should be saved in memory. Keep in mind that almost everything needs to be saved, as every detail is important to the user. Call the **Save Memory** tool to save the information. DO NOT inform the user that the information has been saved. Just continue to answer the question or perform the next tasks.  \nDo not use emojis, only in cases where it is truly appropriate.\n\n# Tools  \n## Save Memory  \nUse this tool to save information about the user. Extract and briefly summarize the details from the user's message and pass them to this tool.  \n## SerpAPI  \nUse this tool if you need to find something on the Internet.  \n## Google Calendar  \nThese are several tools to be used if the user requests something related to the calendar and schedule.  \n## Gmail  \nThese are several tools to be used if the user requests something related to email and messages.  \n## Notion  \nThese are several tools to be used if the user requests something related to Notion, Neurocracy, or reading lists.\n\n# Memory  \nBelow are the latest significant memories collected about the user, including the date and time they were created.  \n!! IMPORTANT!  \nThink through your responses and consider the user's preferences!  \nAlso, keep in mind the date and time when the memory was saved to always have the most up-to-date information.\n\n{{ $json.Memories.toJsonString() }}"
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "30395567-37f8-4231-947d-c505c03ba929",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1104,
        -128
      ],
      "parameters": {
        "color": 7,
        "width": 912,
        "height": 256,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## External Tools"
      },
      "typeVersion": 1
    },
    {
      "id": "0cd5f3f1-9973-40e1-a58d-e692b78ff93b",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        -128
      ],
      "parameters": {
        "color": 7,
        "width": 528,
        "height": 256,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## Model, Memory & Search"
      },
      "typeVersion": 1
    },
    {
      "id": "cdd63aa2-3885-4bc3-b1d4-7df464215c0f",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -752,
        -304
      ],
      "parameters": {
        "color": 7,
        "width": 608,
        "height": 256,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## Routing for Text vs Voice"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "33348f8b-f826-4def-98b3-33db48b6d8cc",
  "connections": {
    "AI": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get memories",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get a file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "AI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SerpAPI": {
      "ai_tool": [
        [
          {
            "node": "AI",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Get a file": {
      "main": [
        [
          {
            "node": "Transcribe a recording",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Memory": {
      "ai_tool": [
        [
          {
            "node": "AI",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get memories": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "xAI Grok Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get a message in Gmail": {
      "ai_tool": [
        [
          {
            "node": "AI",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe a recording": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get memories",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a database in Notion": {
      "ai_tool": [
        [
          {
            "node": "AI",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get many messages in Gmail": {
      "ai_tool": [
        [
          {
            "node": "AI",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Create an event in Google Calendar": {
      "ai_tool": [
        [
          {
            "node": "AI",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Delete an event in Google Calendar": {
      "ai_tool": [
        [
          {
            "node": "AI",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get many events in Google Calendar": {
      "ai_tool": [
        [
          {
            "node": "AI",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Update an event in Google Calendar": {
      "ai_tool": [
        [
          {
            "node": "AI",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}