{
  "id": "14MB25tL8q23UC6z",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Audio-Notizen zu Google Docs",
  "tags": [],
  "nodes": [
    {
      "id": "6dd948b1-2474-4a42-a9d1-e00a89db12a0",
      "name": "Telegram Sprachnachricht Empfang",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -480,
        -192
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {
          "download": true
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "87c4f0ee-ab1e-4514-8b0c-f311a405baf0",
      "name": "OpenAI Whisper Transkription",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        192,
        -288
      ],
      "parameters": {
        "options": {
          "language": "de"
        },
        "resource": "audio",
        "operation": "transcribe"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "37f19a94-f24b-41fb-a0cd-2f82e2e488e5",
      "name": "Text formatieren",
      "type": "n8n-nodes-base.function",
      "position": [
        768,
        -192
      ],
      "parameters": {
        "functionCode": "// Intelligente Erkennung: Audio oder Text?\nconst keywords = $input.first().json.message.content; // Von \"Message a model\"\nconst messageDate = new Date($('Telegram Sprachnachricht Empfang').first().json.message.date * 1000);\nconst userName = $('Telegram Sprachnachricht Empfang').first().json.message.from.first_name;\nconst originalMessage = $('Telegram Sprachnachricht Empfang').first().json.message;\n\n// Pr\u00fcfe ob es eine Sprachnachricht war\nconst isVoiceMessage = originalMessage.voice !== undefined;\n\nlet originalText;\nlet messageType;\n\nif (isVoiceMessage) {\n  // Sprachnachricht: Text von Whisper holen\n  originalText = $('OpenAI Whisper Transkription').first().json.text;\n  messageType = \"\ud83c\udfa4 Sprachnachricht\";\n} else {\n  // Textnachricht: Text direkt aus der Telegram-Nachricht\n  originalText = originalMessage.text;\n  messageType = \"\ud83d\udcac Textnachricht\";\n}\n\n// Deutsche Formatierung mit Schweizer Zeitzone\nconst formattedDate = messageDate.toLocaleString('de-CH', {\n  year: 'numeric',\n  month: '2-digit',\n  day: '2-digit',\n  hour: '2-digit',\n  minute: '2-digit',\n  timeZone: 'Europe/Zurich'\n});\n\n// Format: Datum, Typ, Schlagworte, Text\nconst formattedText = `\\n\\n\ud83d\udcc5 ${formattedDate} (${messageType})\\n\ud83c\udff7\ufe0f Schlagworte: ${keywords}\\n\ud83d\udcdd Inhalt: ${originalText}`;\n\nreturn [{\n  json: {\n    formattedText: formattedText,\n    originalText: originalText,\n    keywords: keywords,\n    timestamp: formattedDate,\n    userName: userName,\n    messageType: isVoiceMessage ? 'voice' : 'text'\n  }\n}];"
      },
      "typeVersion": 1
    },
    {
      "id": "bddc9bec-8574-4835-b45e-ed2a5a3f82c3",
      "name": "In Google Doc speichern",
      "type": "n8n-nodes-base.googleDocs",
      "position": [
        992,
        -192
      ],
      "parameters": {
        "actionsUi": {
          "actionFields": [
            {
              "text": "={{ $json.formattedText }}",
              "action": "insert"
            }
          ]
        },
        "operation": "update",
        "documentURL": "https://docs.google.com/document/d/1XYhGMHOPCMdZJgOyhIa77_LpUmVceyp-HjpyEj6fv48/edit?tab=t.0"
      },
      "credentials": {
        "googleDocsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "2778d7b4-6a14-4344-bb3e-f05f57cbef14",
      "name": "Best\u00e4tigung senden",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1216,
        -192
      ],
      "parameters": {
        "text": "=\u2705 Nachricht erfolgreich gespeichert!\n\n\ud83d\udcdd Text:\n\n{{ $('Text formatieren').first().json.originalText }} ",
        "chatId": "={{ $('Telegram Sprachnachricht Empfang').item.json.message.chat.id }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3d479616-eba7-4395-b8f7-16dc13601e96",
      "name": "Get a file",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -32,
        -288
      ],
      "parameters": {
        "fileId": "={{ $json.message.voice.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0bdf1854-ee89-4dd6-b70e-cd1f7495243f",
      "name": "Message a model",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        416,
        -192
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "chatgpt-4o-latest",
          "cachedResultName": "CHATGPT-4O-LATEST"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=Du erh\u00e4ltst den Text einer Nachricht von Julian Reich. Deine Aufgabe ist es, den Text mit maximal drei Schlagworten zusammenzufassen. Beispiele f\u00fcr Schlagworte sind: Arbeit, Idee, Privat, Sport, Ern\u00e4hrung, Schlaf, KI, Projekt, Effizienz, Problem.\nMache zudem falls n\u00f6tig minimale Anpassungen am Text, insbesondere wenn der Begriff \"Claude\" nicht erkannt wird. Dieser wird oft mit Cloth, Klot oder anderen falschen Begriffen transkribiert. Halte dich aber grunds\u00e4tzlich mit Eingriffen zur\u00fcck. \n\\n\\nHier der Text: {{ $json.text }} "
            }
          ]
        }
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "fa17de4c-7303-4e85-9385-3e0439e88c8f",
      "name": "Check if Audio file",
      "type": "n8n-nodes-base.if",
      "position": [
        -256,
        -192
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "2b538077-d3d3-4713-b973-68748313ff97",
              "operator": {
                "type": "object",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.message.voice }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "f49d300a-68a8-418d-80c0-78032ee65ee4",
      "name": "Set field",
      "type": "n8n-nodes-base.set",
      "position": [
        192,
        -96
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "eb912219-2436-4f04-8ffc-c1c20eb07344",
              "name": "text",
              "type": "string",
              "value": "={{ $json.message.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    }
  ],
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "9368fc5a-9ac9-4736-9990-f50a54f714fb",
  "connections": {
    "Set field": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a file": {
      "main": [
        [
          {
            "node": "OpenAI Whisper Transkription",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message a model": {
      "main": [
        [
          {
            "node": "Text formatieren",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text formatieren": {
      "main": [
        [
          {
            "node": "In Google Doc speichern",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Audio file": {
      "main": [
        [
          {
            "node": "Get a file",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set field",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "In Google Doc speichern": {
      "main": [
        [
          {
            "node": "Best\u00e4tigung senden",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Whisper Transkription": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Sprachnachricht Empfang": {
      "main": [
        [
          {
            "node": "Check if Audio file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}