{
  "name": "Echo",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        0
      ],
      "id": "1a9f05aa-3933-46b0-852a-9f4533bdc64e",
      "name": "Telegram Trigger",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "=https://api.telegram.org/bot{{$vars.TELEGRAM_BOT_TOKEN}}/getFile",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "=file_id",
              "value": "={{ $json.message.voice.file_id }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        208,
        0
      ],
      "id": "a6af6ca9-b346-4366-8524-ee0154268821",
      "name": "HTTP Request"
    },
    {
      "parameters": {
        "url": "=https://api.telegram.org/file/bot{{$vars.TELEGRAM_BOT_TOKEN}}/{{ $json.result.file_path }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        416,
        0
      ],
      "id": "e4d932d1-86e1-4fea-a474-b058630f2772",
      "name": "HTTP Request1",
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.groq.com/openai/v1/audio/transcriptions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "whisper-large-v3"
            },
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "data"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        832,
        0
      ],
      "id": "50d564de-8740-4854-a707-f5c780dba5b2",
      "name": "HTTP Request2",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "for (const item of $input.all()) {\n  if (item.binary && item.binary.data) {\n    item.binary.data.fileName = 'echo_voice.ogg';\n    item.binary.data.mimeType = 'audio/ogg';\n  }\n}\nreturn $input.all();"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        624,
        0
      ],
      "id": "79e153e3-d1bc-4a51-ac8d-406e8a3fa71f",
      "name": "Code in JavaScript"
    },
    {
      "parameters": {
        "jsCode": "for (const item of $input.all()) {\n  const rawContent = item.json.choices[0].message.content;\n  const parsed = JSON.parse(rawContent);\n  \n  item.json.title = parsed.title;\n  item.json.clean_content = parsed.clean_content;\n  item.json.category = parsed.category;\n  item.json.confidence = Number(parsed.confidence);\n  item.json.review_status = parsed.review_status;\n}\nreturn $input.all();"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1696,
        0
      ],
      "id": "0a2dabb7-3841-4860-84b7-8306b1bd5ea4",
      "name": "Code in JavaScript1"
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "value": "375a8a92-5d50-8094-a027-c44d85565720",
          "mode": "list",
          "cachedResultName": "Echo Tasks",
          "cachedResultUrl": "https://app.notion.com/p/375a8a925d508094a027c44d85565720"
        },
        "title": "={{ $json.title }}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Status|select",
              "selectValue": "Todo"
            },
            {
              "key": "Name|title",
              "title": "={{ $json.title }}"
            },
            {
              "key": "Confidence|number",
              "numberValue": "={{$json.confidence}}"
            }
          ]
        },
        "blockUi": {
          "blockValues": [
            {
              "textContent": "={{ $json.clean_content }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        2528,
        -480
      ],
      "id": "b5c3a278-69df-44b6-838d-6583a312ad1c",
      "name": "Create Task Page",
      "credentials": {
        "notionOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "fe1ea44d-2e72-4817-b2fb-e1b9cc5eaa95",
                    "leftValue": "={{$json.category}}",
                    "rightValue": "Todo",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "15622832-fa05-413f-b754-e56f568fb77f",
                    "leftValue": "={{$json.category}}",
                    "rightValue": "Idea",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "d02859fb-b23c-42f6-b78f-31c7f6db9b55",
                    "leftValue": "={{$json.category}}",
                    "rightValue": "Journal",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        2240,
        -208
      ],
      "id": "92918112-96e3-4a29-b24b-7a73f3f5fc85",
      "name": "Switch"
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "value": "375a8a92-5d50-8004-af50-ee6796cb3d58",
          "mode": "list",
          "cachedResultName": "Echo Idea Vault",
          "cachedResultUrl": "https://app.notion.com/p/375a8a925d508004af50ee6796cb3d58"
        },
        "title": "={{ $json.title }}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Name|title",
              "title": "={{ $json.title }}"
            },
            {
              "key": "Confidence|number",
              "numberValue": "={{$json.confidence}}"
            }
          ]
        },
        "blockUi": {
          "blockValues": [
            {
              "textContent": "={{ $json.clean_content }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        2528,
        -272
      ],
      "id": "4bdd6491-0783-4f22-9d68-87fb2e18b542",
      "name": "Create Idea Page",
      "credentials": {
        "notionOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "value": "375a8a92-5d50-8091-b42c-f5ad591bdb66",
          "mode": "list",
          "cachedResultName": "Echo Journal",
          "cachedResultUrl": "https://app.notion.com/p/375a8a925d508091b42cf5ad591bdb66"
        },
        "title": "={{ $json.title }}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Name|title",
              "title": "={{ $json.title }}"
            },
            {
              "key": "Confidence|number",
              "numberValue": "={{$json.confidence}}"
            }
          ]
        },
        "blockUi": {
          "blockValues": [
            {
              "textContent": "={{ $json.clean_content }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        2528,
        -64
      ],
      "id": "5543106c-cca6-490e-8e3e-96d299f27f1e",
      "name": "Create Journal Page",
      "credentials": {
        "notionOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "7bd63d2d-4863-4b44-9625-e3ac93e8edef",
              "leftValue": "={{$json.confidence}}",
              "rightValue": 0.7,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        1952,
        0
      ],
      "id": "77fb1c17-85b7-4579-8900-c47c23ba8d6d",
      "name": "If"
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "value": "375a8a92-5d50-807e-8724-d2a3eab07bcb",
          "mode": "list",
          "cachedResultName": "Echo Human Review Queue",
          "cachedResultUrl": "https://app.notion.com/p/375a8a925d50807e8724d2a3eab07bcb"
        },
        "title": "={{ $json.title }}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Name|title",
              "title": "={{ $json.title }}"
            },
            {
              "key": "Confidence|number",
              "numberValue": "={{$json.confidence}}"
            },
            {
              "key": "Category|select",
              "selectValue": "={{$json.category}}"
            },
            {
              "key": "Review Status|select",
              "selectValue": "={{$json.review_status}}"
            }
          ]
        },
        "blockUi": {
          "blockValues": [
            {
              "textContent": "={{ $json.clean_content }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        2256,
        192
      ],
      "id": "c334ef40-78d8-4ad0-a64c-7077c8986584",
      "name": "Create Review Item",
      "credentials": {
        "notionOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.groq.com/openai/v1/chat/completions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"llama-3.3-70b-versatile\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You are a Review Agent responsible for validating and improving notes produced by another AI agent.\\n\\nYour responsibilities:\\n1. Verify title quality and clarity.\\n2. Verify markdown formatting.\\n3. Verify category correctness.\\n4. Improve wording if necessary.\\n5. Estimate confidence in the category assignment.\\n6. Approve or reject the note.\\n\\nCategory Rules:\\n- Todo = an actionable task, commitment, reminder, or next step.\\n- Idea = a concept, startup idea, thought, observation, feature suggestion, or future possibility.\\n- Journal = a reflection, memory, experience, feeling, or personal log.\\n\\nConfidence Rules:\\n- Return a number between 0 and 1.\\n- Use high confidence (0.9-1.0) when the category is obvious.\\n- Use medium confidence (0.7-0.89) when there is minor ambiguity.\\n- Use low confidence (<0.7) when the transcript could reasonably belong to multiple categories.\\n\\nReview Rules:\\n- approved = output is usable.\\n- rejected = title, formatting, or categorization is unreliable.\\n\\nYou must strictly output a raw JSON object with exactly five keys and absolutely NO conversational text, markdown code fences, explanations, or additional fields.\\n\\nSchema:\\n{\\n  \\\"title\\\": \\\"Improved title if necessary\\\",\\n  \\\"clean_content\\\": \\\"Validated markdown content\\\",\\n  \\\"category\\\": \\\"Todo | Idea | Journal\\\",\\n  \\\"confidence\\\": 0.95,\\n  \\\"review_status\\\": \\\"approved | rejected\\\"\\n}\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Review and validate this extracted note:\\n\\nTitle: {{ $json.title }}\\n\\nContent:\\n{{ $json.clean_content }}\\n\\nCategory: {{ $json.category }}\"\n    }\n  ],\n  \"temperature\": 0.1,\n  \"response_format\": {\n    \"type\": \"json_object\"\n  }\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1472,
        0
      ],
      "id": "16100060-1683-4f04-8195-215d0e2964d2",
      "name": "Groq Reviewer Agent",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.groq.com/openai/v1/chat/completions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"llama-3.3-70b-versatile\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You are an Extraction Agent responsible for converting raw voice note transcripts into structured knowledge entries.\\n\\nYour responsibilities:\\n1. Correct grammar and sentence structure.\\n2. Remove filler words and verbal clutter.\\n3. Format content cleanly using Markdown.\\n4. Generate a concise title.\\n5. Classify the note into exactly one category.\\n\\nYou are NOT responsible for validation, confidence estimation, or quality review.\\nDo NOT critique your own output.\\nDo NOT explain your reasoning.\\n\\nCategory Rules:\\n- Todo = an actionable task, commitment, reminder, or next step.\\n- Idea = a concept, startup idea, thought, observation, feature suggestion, or future possibility.\\n- Journal = a reflection, memory, experience, feeling, or personal log.\\n\\nYou must strictly output a raw JSON object with exactly three keys and absolutely NO conversational text, markdown code fences, explanations, or additional fields.\\n\\nSchema:\\n{\\n  \\\"title\\\": \\\"A concise premium 4-5 word summary\\\",\\n  \\\"clean_content\\\": \\\"Beautifully formatted markdown content with escaped line breaks\\\",\\n  \\\"category\\\": \\\"Todo | Idea | Journal\\\"\\n}\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Here is the raw transcript: {{ $json.text }}\"\n    }\n  ],\n  \"temperature\": 0.2,\n  \"response_format\": {\n    \"type\": \"json_object\"\n  }\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1040,
        0
      ],
      "id": "85f3b7e3-34c0-4406-90ec-9f7e7a305904",
      "name": "Groq Extractor Agent",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const raw = $json.choices[0].message.content;\n\nconst parsed = JSON.parse(raw);\n\nreturn [\n  {\n    json: {\n      title: parsed.title,\n      clean_content: parsed.clean_content,\n      category: parsed.category\n    }\n  }\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1232,
        0
      ],
      "id": "21cbb68d-d927-496b-a586-075c15646adf",
      "name": "Code in JavaScript2"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        2896,
        -272
      ],
      "id": "9f243894-fd19-485e-9610-a259955f899d",
      "name": "Merge"
    },
    {
      "parameters": {
        "jsCode": "const categoryEmoji = {\n  Todo: \"\u2705\",\n  Idea: \"\ud83d\udca1\",\n  Journal: \"\ud83d\udcd6\"\n};\n\nconst note = $('Code in JavaScript1').first().json;\n\nreturn [{\n  json: {\n    chatId: $('Telegram Trigger').first().json.message.chat.id,\n    message:\n`${categoryEmoji[note.category] || \"\ud83d\udcdd\"} Stored Successfully\n\nCategory: ${note.category}\nTitle: ${note.title}\n\nSaved to Echo.`\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3104,
        -272
      ],
      "id": "bd530a4b-86a9-4dab-96b2-bed7c4879564",
      "name": "Code in JavaScript3"
    },
    {
      "parameters": {
        "chatId": "={{$json.chatId}}",
        "text": "={{$json.message}}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        3312,
        -272
      ],
      "id": "3414b3ca-d8c3-4b31-90d4-ea5782773eb8",
      "name": "Send a text message",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "HTTP Request2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request2": {
      "main": [
        [
          {
            "node": "Groq Extractor Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript1": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Task Page": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Create Task Page",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Idea Page",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Journal Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Review Item",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Extractor Agent": {
      "main": [
        [
          {
            "node": "Code in JavaScript2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Reviewer Agent": {
      "main": [
        [
          {
            "node": "Code in JavaScript1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript2": {
      "main": [
        [
          {
            "node": "Groq Reviewer Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Idea Page": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Journal Page": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Code in JavaScript3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript3": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "timeSavedMode": "fixed",
    "callerPolicy": "workflowsFromSameOwner",
    "availableInMCP": false
  },
  "versionId": "95021b25-3533-4ed7-ae00-eca4d3b8cf7e",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "TlCA0N8R7GbgRQ2r",
  "tags": []
}