{
  "name": "Telelgram Get And Send Emails",
  "nodes": [
    {
      "parameters": {
        "sendTo": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('To', ``, 'string') }}",
        "subject": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Subject', ``, 'string') }}",
        "message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', ``, 'string') }}",
        "options": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        760,
        200
      ],
      "id": "2589eda2-aafd-4aec-bf58-591b2d3bba68",
      "name": "Gmail",
      "webhookId": "c2dced92-19fc-4283-9892-ae0a7a27b31d",
      "credentials": {
        "gmailOAuth2": {
          "id": "xmp6P6qtAw4JgOCe",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.output }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        840,
        0
      ],
      "id": "cb82958b-4993-4ee5-81c7-b3dab52db2a2",
      "name": "Telegram",
      "webhookId": "0074cd0d-a9e0-4b81-bf32-865aa8b512e4",
      "credentials": {
        "telegramApi": {
          "id": "IR7xqx0ILwANdL7f",
          "name": "n8n bot"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        460,
        200
      ],
      "id": "c9ff31a4-4d5e-4673-8d76-72fbbf00702c",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        340,
        200
      ],
      "id": "d36f14d3-f45e-4f08-bb7b-b7e9a5bc4cb5",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "MzIepidaRw9ZqcPB",
          "name": "OpenAi account Credentials"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.message.text }}",
        "options": {
          "systemMessage": "You are a helpful assistant. Use the GetEmailsFromGmail tool only when asked to retrieve my last 5 emails. Use the GMAIL tool only when asked to compose or send an email. Never use both tools at the same time."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.8,
      "position": [
        440,
        0
      ],
      "id": "156089a6-a2dd-44ef-96d1-0da104f9a558",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        220,
        0
      ],
      "id": "c1689b3d-8abf-4364-b7fb-0e3c1257f5b9",
      "name": "Telegram Trigger",
      "webhookId": "e97bd5f1-5ff9-41bf-a242-a63a64bbeb1c",
      "credentials": {
        "telegramApi": {
          "id": "IR7xqx0ILwANdL7f",
          "name": "n8n bot"
        }
      }
    },
    {
      "parameters": {
        "operation": "getAll",
        "limit": 5,
        "filters": {}
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        620,
        200
      ],
      "id": "ffd7ef71-3ae5-4944-ba05-44ad0cb56beb",
      "name": "GetEmailsFromGmail",
      "webhookId": "a2bc386a-6100-4753-8fc5-4bfe4b24b16b",
      "credentials": {
        "gmailOAuth2": {
          "id": "xmp6P6qtAw4JgOCe",
          "name": "Gmail account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Gmail": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GetEmailsFromGmail": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "b82ee4c5-ad35-469a-9cfa-da3cefcd01f7",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "4aabc0aa2e160dafa4f9d9bcedde563b5af29598cd16960f637ae2fb99aea720"
  },
  "id": "8BUCPOdz4nuAmAEX",
  "tags": []
}