{
  "name": "AI_assistant_telegram",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        -864,
        -32
      ],
      "id": "YOUR_NODE_ID_1",
      "name": "Telegram Trigger"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "YOUR_ASSIGNMENT_ID_1",
              "name": "session_id",
              "value": "={{ $json.message.chat.id }}",
              "type": "number"
            },
            {
              "id": "YOUR_ASSIGNMENT_ID_2",
              "name": "message.text",
              "value": "={{ $json.message.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -208,
        -48
      ],
      "id": "YOUR_NODE_ID_2",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.message.text }}",
        "options": {
          "systemMessage": "=You are a personal assistant that helps user fulfill their requests.\n\nWhen you are asked to perform a task on the current date, please use the current time and date :  {{ $now }}\n\n## Output\n\nYou should output the result and don't include any thing unnecessary. Just  make sure that you politely answer user question and ask if any other information is required.\n\n\nIf there is something related to getting the tasks, please make sure that you use the tool 'get_many_google_task_tool' to get the tasks as user want. Give a summary of the same without any links etc.\n\n\nIf there is something related to calendar or schedule or events, you have to use tool 'calendar_flow_agent' to call the seperate workflow with detailed 'text' ( time is {{ $now }}) so that it can work on the Query."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2.2,
      "position": [
        384,
        -48
      ],
      "id": "YOUR_NODE_ID_3",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.output }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        800,
        -48
      ],
      "id": "YOUR_NODE_ID_4",
      "name": "Send a text message",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $json.session_id }}",
        "contextWindowLength": 7
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        464,
        400
      ],
      "id": "YOUR_NODE_ID_5",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "resource": "audio",
        "modelId": {
          "__rl": true,
          "value": "models/gemini-2.5-flash",
          "mode": "list",
          "cachedResultName": "models/gemini-2.5-flash"
        },
        "inputType": "binary",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "typeVersion": 1,
      "position": [
        -176,
        224
      ],
      "id": "YOUR_NODE_ID_6",
      "name": "Transcribe a recording",
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": "",
                    "operator": {
                      "type": "boolean",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "id": "YOUR_CONDITION_ID_1"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "text"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "YOUR_CONDITION_ID_2",
                    "leftValue": "={{ $json.message.voice.file_id }}",
                    "rightValue": "",
                    "operator": {
                      "type": "boolean",
                      "operation": "exists",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "audio"
            }
          ]
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.3,
      "position": [
        -608,
        -32
      ],
      "id": "YOUR_NODE_ID_7",
      "name": "Switch"
    },
    {
      "parameters": {
        "resource": "file",
        "fileId": "={{ $json.message.voice.file_id }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -432,
        144
      ],
      "id": "YOUR_NODE_ID_8",
      "name": "Get a file",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "YOUR_ASSIGNMENT_ID_3",
              "name": "message.text",
              "value": "={{ $json.content.parts[0].text }}",
              "type": "string"
            },
            {
              "id": "YOUR_ASSIGNMENT_ID_4",
              "name": "session_id",
              "value": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        32,
        224
      ],
      "id": "YOUR_NODE_ID_9",
      "name": "Edit Fields1"
    },
    {
      "parameters": {
        "operation": "getAll",
        "task": "YOUR_GOOGLE_TASKS_LIST_ID",
        "returnAll": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Return_All', ``, 'boolean') }}",
        "additionalFields": {
          "showCompleted": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Show_Completed', ``, 'boolean') }}"
        }
      },
      "type": "n8n-nodes-base.googleTasksTool",
      "typeVersion": 1,
      "position": [
        720,
        192
      ],
      "id": "YOUR_NODE_ID_10",
      "name": "Get many tasks in Google Tasks",
      "credentials": {
        "googleTasksOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        256,
        160
      ],
      "id": "YOUR_NODE_ID_11",
      "name": "Google Gemini Chat Model",
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "description": "This workflow helps to create events in google calendar or get events from the calendar.",
        "workflowId": {
          "__rl": true,
          "value": "YOUR_CALENDAR_WORKFLOW_ID",
          "mode": "list",
          "cachedResultUrl": "/workflow/YOUR_CALENDAR_WORKFLOW_ID",
          "cachedResultName": "My_gmail_calendar"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "text": "={{ $json.message.text }}",
            "session_id": "={{ $json.session_id }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "text",
              "displayName": "text",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            },
            {
              "id": "session_id",
              "displayName": "session_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        656,
        432
      ],
      "id": "YOUR_NODE_ID_12",
      "name": "Call 'My_gmail_calendar'"
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get a file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe a recording": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a file": {
      "main": [
        [
          {
            "node": "Transcribe a recording",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get many tasks in Google Tasks": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Call 'My_gmail_calendar'": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "YOUR_VERSION_ID",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "YOUR_WORKFLOW_ID",
  "tags": [
    {
      "createdAt": "2025-10-07T12:15:04.955Z",
      "updatedAt": "2025-10-07T12:15:04.955Z",
      "id": "YOUR_TAG_ID_1",
      "name": "telegram"
    },
    {
      "createdAt": "2025-10-05T06:00:43.469Z",
      "updatedAt": "2025-10-05T06:00:43.469Z",
      "id": "YOUR_TAG_ID_2",
      "name": "api"
    }
  ]
}