{
  "name": "AI speech coach & generator using Telegram, Open AI and Gemini",
  "nodes": [
    {
      "id": "8868fc75-4a21-4900-b2b9-7860ee981a9e",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1640,
        240
      ]
    },
    {
      "id": "23f48680-a190-48a5-bb7c-e070db41b9e7",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1620,
        800
      ]
    },
    {
      "id": "6a909fb0-f550-4b5e-94db-6e16682d70bd",
      "name": "Recieve Telegram Message",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -480,
        240
      ]
    },
    {
      "id": "73d19e09-efc4-43c4-a4e9-382ae66c7651",
      "name": "Check For Text or Voice Message",
      "type": "n8n-nodes-base.set",
      "position": [
        -260,
        240
      ]
    },
    {
      "id": "a7ade841-258d-45b2-9150-a56490a4c37f",
      "name": "Download Audio File",
      "type": "n8n-nodes-base.telegram",
      "position": [
        180,
        120
      ]
    },
    {
      "id": "73cb448e-f00e-4879-8fa2-facb259b76b2",
      "name": "Transcribe Audio File",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        400,
        120
      ]
    },
    {
      "id": "a1999ecd-cabf-4740-a9a6-98486a868b7f",
      "name": "If Voice Message",
      "type": "n8n-nodes-base.if",
      "position": [
        -60,
        240
      ]
    },
    {
      "id": "ac5cad34-3756-4fe3-9269-ae96e5b49e8f",
      "name": "Code to remove unwanted characters from LLM response",
      "type": "n8n-nodes-base.code",
      "position": [
        2060,
        240
      ]
    },
    {
      "id": "82761634-7472-4ce1-806a-2b80aca985e3",
      "name": "Code to split output into chunks under 4000 characters",
      "type": "n8n-nodes-base.code",
      "position": [
        2280,
        240
      ]
    },
    {
      "id": "9adbfd4c-bbb9-4c92-bf07-a3b50a92aa02",
      "name": "Respond to Telegram Message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2500,
        240
      ]
    },
    {
      "id": "5bdb6ec5-339e-4e8d-a746-9cdbe4d5f12f",
      "name": "Wipe Conversation Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryManager",
      "position": [
        940,
        -20
      ]
    },
    {
      "id": "aae703f4-e891-4681-aae4-c426ebba5146",
      "name": "Store Conversation Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1120,
        800
      ]
    },
    {
      "id": "7457f085-9b19-4a00-9ad6-af2ca8ee16d5",
      "name": "Set prompt to start a new speech",
      "type": "n8n-nodes-base.set",
      "position": [
        1340,
        -20
      ]
    },
    {
      "id": "0a9f2c04-7f7e-488c-866c-717a78bf7db1",
      "name": "Set prompt to generate a speech based on the feedback",
      "type": "n8n-nodes-base.set",
      "position": [
        1340,
        220
      ]
    },
    {
      "id": "f242361e-6bf4-4c4e-8cd0-72da06823842",
      "name": "Set prompt to provide feedback on speech",
      "type": "n8n-nodes-base.set",
      "position": [
        1340,
        420
      ]
    },
    {
      "id": "c1f69bc3-2c93-404e-b338-82663deb975b",
      "name": "Route Flow Based on Message Content",
      "type": "n8n-nodes-base.switch",
      "position": [
        680,
        260
      ]
    },
    {
      "id": "6cf41698-2345-4ff8-bd1e-9549e372b454",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1280,
        -300
      ],
      "parameters": {
        "width": 220,
        "height": 900,
        "content": "## Dynamic System Prompting:\n\nThis node sets the AI's system prompt according to the user's request identified in the incoming message."
      }
    },
    {
      "id": "1d967631-9300-4fb6-b488-8c09beccbb05",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2000,
        -300
      ],
      "parameters": {
        "width": 440,
        "height": 720,
        "content": "## Telegram-Ready Output: Formatting and Length Management:\n\nThese code nodes perform two crucial tasks:\n1.  **Formatting:** Removing characters that could cause issues with Telegram's message parsing"
      }
    },
    {
      "id": "c480550b-c94f-40ee-8338-3deb6bea28d8",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        900,
        -300
      ],
      "parameters": {
        "width": 340,
        "height": 420,
        "content": "## Clearing AI Agent Memory:\n\nThis node clears the AI agent's short-term memory. This helps to minimize the influence of past interactions on future responses, thereby reducing the likelihood of the A"
      }
    },
    {
      "id": "bd36f9a8-30d9-4e0a-978b-a74806685adc",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        -300
      ],
      "parameters": {
        "width": 1160,
        "height": 740,
        "content": "## Processing Telegram Messages:\n\nThis section handles incoming messages from Telegram. It first checks if the message contains text.\n\n1.  **Text Message:** If the message includes text, it's directly"
      }
    },
    {
      "id": "cf7d8897-b963-4bb5-9b0e-3ab628e478c7",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1620,
        -300
      ],
      "parameters": {
        "width": 300,
        "height": 740,
        "content": "## Gemini-Powered Response and Conversation Storage:\n\nThis node utilizes the Google Gemini model to generate a response to the user's prompt and stores the ongoing conversation."
      }
    },
    {
      "id": "9fffb613-536e-4b4d-8841-7b4bd3121eab",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -300,
        -500
      ],
      "parameters": {
        "width": 2740,
        "height": 140,
        "content": "## This n8n workflow acts as your personal AI speechwriting coach, directly accessible through Telegram. It listens to your spoken or typed drafts, provides insightful feedback on clarity, engagement,"
      }
    }
  ],
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Code to remove unwanted characters from LLM response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Voice Message": {
      "main": [
        [
          {
            "node": "Download Audio File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Route Flow Based on Message Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Audio File": {
      "main": [
        [
          {
            "node": "Transcribe Audio File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe Audio File": {
      "main": [
        [
          {
            "node": "Route Flow Based on Message Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Recieve Telegram Message": {
      "main": [
        [
          {
            "node": "Check For Text or Voice Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wipe Conversation Memory": {
      "main": [
        [
          {
            "node": "Set prompt to start a new speech",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Store Conversation Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          },
          {
            "node": "Wipe Conversation Memory",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Check For Text or Voice Message": {
      "main": [
        [
          {
            "node": "If Voice Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set prompt to start a new speech": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Flow Based on Message Content": {
      "main": [
        [
          {
            "node": "Wipe Conversation Memory",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set prompt to generate a speech based on the feedback",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set prompt to provide feedback on speech",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set prompt to provide feedback on speech": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code to remove unwanted characters from LLM response": {
      "main": [
        [
          {
            "node": "Code to split output into chunks under 4000 characters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set prompt to generate a speech based on the feedback": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code to split output into chunks under 4000 characters": {
      "main": [
        [
          {
            "node": "Respond to Telegram Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}