8
n8n 中文网amn8n.com

使用Gemini AI和PostgreSQL数据库处理Telegram中的多个媒体文件

高级

这是一个Support Chatbot, Multimodal AI领域的自动化工作流,包含 100 个节点。主要使用 If, Set, Code, Html, Wait 等节点。 使用Gemini AI和PostgreSQL数据库处理Telegram中的多个媒体文件

前置要求
  • PostgreSQL 数据库连接信息
  • Telegram Bot Token
  • Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "50be75eaab016244f302e16f06394e6613d664bfc61e8cd41452474a0de6a3ee",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "7218515a-cd97-491d-b0c9-c5fd208fe17d",
      "name": "下载语音消息",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        592
      ],
      "webhookId": "d3e9d36d-6402-45d6-9f56-5886e616f9fa",
      "parameters": {
        "fileId": "={{ $json.message.voice.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b9fa4c03-b570-465f-a9fe-23552d158d2c",
      "name": "发送短信1",
      "type": "n8n-nodes-base.telegram",
      "position": [
        3248,
        224
      ],
      "webhookId": "ef6a9544-83e3-4631-93bc-ecefd56951fb",
      "parameters": {
        "text": "={{ $json.message }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "parse_mode": "MarkdownV2",
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7f22b6f2-ed6d-4bab-a54c-d726ac888571",
      "name": "输入消息路由器1",
      "type": "n8n-nodes-base.switch",
      "position": [
        288,
        816
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Text",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "fcb767ee-565e-4b56-a54e-6f97f739fc24",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Voice Message",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c1016c40-f8f2-4e08-8ec8-5cdb88f5c87a",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.voice }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Video note",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "9b94667e-c79b-4e4a-81ca-c4cd0d55f465",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.video_note.file_id }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Image",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "f8150ac7-eea4-4658-8da9-f7a1c88a471d",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.photo[0].file_id }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Audio",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "24ad08e0-6567-41e2-921f-b2a5cd6e2d47",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.audio.file_id }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Video",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c266ee51-45e8-45e0-ba4a-d3d8f41f2e43",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.video.file_id }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Document",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "67b350d3-97e9-4966-a05e-cabbe825fe8d",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.document.file_id }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "ignoreCase": false,
          "fallbackOutput": "extra",
          "allMatchingOutputs": true
        }
      },
      "typeVersion": 3.2
    },
    {
      "id": "c23c658e-8bc6-479a-8bfc-f6dd11ba93f5",
      "name": "媒体组?2",
      "type": "n8n-nodes-base.if",
      "position": [
        1952,
        896
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "df19fe9e-d1bd-42e4-9617-654fb984cc55",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $('Telegram Trigger').item.json.message.media_group_id }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "cefc16d9-9ae0-42f5-8553-48022f6f2b25",
      "name": "字幕?1",
      "type": "n8n-nodes-base.if",
      "position": [
        1776,
        1040
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e6c61b94-9a84-4d6f-91a4-1839209fdc89",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $('Telegram Trigger').first().json.message.caption }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "5074e254-a87e-41c4-b1bb-5ad2dbcf5a1b",
      "name": "媒体组?3",
      "type": "n8n-nodes-base.if",
      "position": [
        1952,
        1168
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "df19fe9e-d1bd-42e4-9617-654fb984cc55",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $('Telegram Trigger').first().json.message.media_group_id }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "063a0fa1-157b-45ab-be3d-b04f5d6fa395",
      "name": "在 media_group 中插入文档",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2160,
        800
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "media_group",
          "cachedResultName": "media_group"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "media_group": "={{ $('Telegram Trigger').item.json.message.media_group_id }}",
            "file_description": "={{ $json.message }}"
          },
          "schema": [
            {
              "id": "id",
              "type": "number",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "id",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "media_group",
              "type": "string",
              "display": true,
              "required": true,
              "displayName": "media_group",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "file_description",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "file_description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "credentials": {
        "postgres": {
          "id": "eQR2NFRag48wov9g",
          "name": "Postgres account"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "ce0e22ef-ba0d-4fa4-b543-ccf87047bbad",
      "name": "在 media_group1 中插入文档",
      "type": "n8n-nodes-base.postgres",
      "onError": "continueRegularOutput",
      "position": [
        2160,
        1120
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "media_group",
          "cachedResultName": "media_group"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public",
          "cachedResultName": "public"
        },
        "columns": {
          "value": {
            "media_group": "={{ $('Telegram Trigger').item.json.message.media_group_id }}",
            "file_description": "={{ $json.message }}"
          },
          "schema": [
            {
              "id": "id",
              "type": "number",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "id",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "media_group",
              "type": "string",
              "display": true,
              "required": true,
              "displayName": "media_group",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "file_description",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "file_description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "credentials": {
        "postgres": {
          "id": "eQR2NFRag48wov9g",
          "name": "Postgres account"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "6cae921d-b7e9-49ed-850b-1b6eecf216ea",
      "name": "等待",
      "type": "n8n-nodes-base.wait",
      "position": [
        2336,
        1120
      ],
      "webhookId": "bffdffe2-7993-4f9f-9852-9dcda3e1b283",
      "parameters": {
        "amount": 2
      },
      "typeVersion": 1.1
    },
    {
      "id": "f7ab12bc-dd41-4e8e-a0d1-a0fa8894938f",
      "name": "插入带字幕的 media_queue(触发器)",
      "type": "n8n-nodes-base.postgres",
      "onError": "continueRegularOutput",
      "position": [
        2336,
        800
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "media_queue",
          "cachedResultName": "media_queue"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "chat_id": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
            "captions": "={{ $('Telegram Trigger').item.json.message.caption }}",
            "media_group_id": "={{ $('Telegram Trigger').item.json.message.media_group_id }}"
          },
          "schema": [
            {
              "id": "media_group_id",
              "type": "string",
              "display": true,
              "required": true,
              "displayName": "media_group_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "chat_id",
              "type": "number",
              "display": true,
              "required": true,
              "displayName": "chat_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "captions",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "captions",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "credentials": {
        "postgres": {
          "id": "eQR2NFRag48wov9g",
          "name": "Postgres account"
        }
      },
      "typeVersion": 2.6,
      "alwaysOutputData": false
    },
    {
      "id": "fd1ad4a5-8309-463f-bdec-714d68e4cfc3",
      "name": "插入 media_queue(触发器)",
      "type": "n8n-nodes-base.postgres",
      "onError": "continueRegularOutput",
      "position": [
        2512,
        1120
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "media_queue",
          "cachedResultName": "media_queue"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "chat_id": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
            "media_group_id": "={{ $('Telegram Trigger').item.json.message.media_group_id }}"
          },
          "schema": [
            {
              "id": "media_group_id",
              "type": "string",
              "display": true,
              "required": true,
              "displayName": "media_group_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "chat_id",
              "type": "number",
              "display": true,
              "required": true,
              "displayName": "chat_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "captions",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "captions",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "credentials": {
        "postgres": {
          "id": "eQR2NFRag48wov9g",
          "name": "Postgres account"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "87e81c7f-d1e4-4db9-98ce-2663f0aedb44",
      "name": "获取文件及字幕",
      "type": "n8n-nodes-base.set",
      "position": [
        2160,
        960
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "c9c892e7-7f78-4a8d-a749-452a0d1b92cf",
              "name": "message",
              "type": "string",
              "value": "=Captions: {{ $('Telegram Trigger').item.json.message.caption }}\n{{ $json.message }}\n"
            },
            {
              "id": "cda76cee-0b9c-4062-b987-10e438eb3b8f",
              "name": "chat_id",
              "type": "string",
              "value": "={{ $json.chat_id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2f793130-dfb1-4129-b4df-c2be18aab277",
      "name": "get_message(文本)",
      "type": "n8n-nodes-base.set",
      "position": [
        656,
        448
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "801ec600-22ad-4a94-a2b4-ae72eb271df0",
              "name": "message",
              "type": "string",
              "value": "={{ $json.message.text }}"
            },
            {
              "id": "263071fb-bcdf-42b0-bb46-71b75fa0bf2a",
              "name": "chat_id",
              "type": "string",
              "value": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "07fbf7d0-e156-4b29-82a1-1d459e13f8fa",
      "name": "仅获取文件",
      "type": "n8n-nodes-base.set",
      "position": [
        2160,
        1280
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "9e549a53-8801-42ea-8c41-e1e38032f62c",
              "name": "message",
              "type": "string",
              "value": "=File description: {{ $json.message }}"
            },
            {
              "id": "df93f18e-9e2d-4ea6-8a0a-44046ee60f19",
              "name": "chat_id",
              "type": "string",
              "value": "={{ $json.chat_id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "6da2a610-4164-4592-9adc-9afa755844d3",
      "name": "统一变量",
      "type": "n8n-nodes-base.code",
      "position": [
        832,
        224
      ],
      "parameters": {
        "jsCode": "const allItems = $input.all().map((item) => item.json);\n\nlet telegramItems = [];\ntry {\n  telegramItems = $(\"Media_queue Trigger\").all().map((item) => item.json);\n} catch (e) {\n  telegramItems = [];\n}\n\n// Capturamos el caption (solo una vez, del primer elemento disponible)\nconst caption = telegramItems[0]?.payload?.captions || \"\";\n\n// Creamos la lista de archivos usando file_description\nconst fileList = allItems.map((item, index) => {\n  const fileDesc = item.file_description || \"\";\n  return `file${index + 1}: ${fileDesc}`;\n});\n\n// Unificamos el mensaje\nconst unifiedMessage = `caption: ${caption}\\n${fileList.join(\"\\n\")}`;\n\nreturn {\n  json: {\n    unifiedMessage\n  }\n};\n"
      },
      "typeVersion": 2
    },
    {
      "id": "63483292-c36e-47ef-8cb3-7e5072a85391",
      "name": "等待所有文件",
      "type": "n8n-nodes-base.wait",
      "position": [
        464,
        224
      ],
      "webhookId": "0d0e28fa-8b35-48ba-ab86-6bde64e81670",
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "9ceb5545-1c92-4c7a-af5a-14d4dd11c2b8",
      "name": "从 group_id 获取所有文件",
      "type": "n8n-nodes-base.postgres",
      "position": [
        656,
        224
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "media_group",
          "cachedResultName": "media_group"
        },
        "where": {
          "values": [
            {
              "value": "={{ $('get_chat_id').item.json.payload.media_group_id }}",
              "column": "media_group"
            }
          ]
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "options": {},
        "operation": "select"
      },
      "credentials": {
        "postgres": {
          "id": "eQR2NFRag48wov9g",
          "name": "Postgres account"
        }
      },
      "typeVersion": 2.6,
      "alwaysOutputData": true
    },
    {
      "id": "01fbef8e-8e56-4480-9234-614693d87d76",
      "name": "Media_queue 触发器",
      "type": "n8n-nodes-base.postgresTrigger",
      "position": [
        128,
        224
      ],
      "parameters": {
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public",
          "cachedResultName": "public"
        },
        "options": {},
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "media_queue",
          "cachedResultName": "media_queue"
        },
        "additionalFields": {}
      },
      "credentials": {
        "postgres": {
          "id": "eQR2NFRag48wov9g",
          "name": "Postgres account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "cf25fb7a-f856-4411-8410-fc0ea2930ae9",
      "name": "Telegram 触发器",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        112,
        912
      ],
      "webhookId": "7e4a813d-20e7-4f7f-aefd-d8d303fab85d",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {
          "download": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "6dc5be73-05bd-4605-acc2-31e86dafc035",
      "name": "获取聊天 ID",
      "type": "n8n-nodes-base.set",
      "position": [
        304,
        224
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "3f3ff787-3c12-494e-8d64-bc313956bc96",
              "name": "chat_id",
              "type": "string",
              "value": "={{ $json.payload.chat_id }}"
            },
            {
              "id": "28e55878-a7c3-4b6f-b92c-6a71d62a8250",
              "name": "payload.media_group_id",
              "type": "string",
              "value": "={{ $json.payload.media_group_id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "14906ada-5342-4f01-85eb-a473f988fe86",
      "name": "当点击\"执行工作流\"时",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        128,
        -16
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "eee26c0d-8508-49c8-be8c-8e715f497d78",
      "name": "创建表格",
      "type": "n8n-nodes-base.postgres",
      "position": [
        304,
        -16
      ],
      "parameters": {
        "query": "CREATE TABLE IF NOT EXISTS public.media_group (\n  id bigint GENERATED BY DEFAULT AS IDENTITY NOT NULL,\n  media_group text NOT NULL,\n  file_description text NULL,\n  CONSTRAINT media_group_pkey PRIMARY KEY (id)\n) TABLESPACE pg_default;\n\nCREATE TABLE IF NOT EXISTS public.media_queue (\n  media_group_id text NOT NULL,\n  chat_id bigint NOT NULL,\n  captions text NULL,\n  CONSTRAINT media_queue_pkey PRIMARY KEY (media_group_id),\n  CONSTRAINT media_queue_media_group_id_key UNIQUE (media_group_id)\n) TABLESPACE pg_default;\n\nCREATE TABLE IF NOT EXISTS public.chat_histories (\n  id serial NOT NULL,\n  session_id character varying(255) NOT NULL,\n  message jsonb NOT NULL,\n  CONSTRAINT chat_histories_pkey PRIMARY KEY (id)\n) TABLESPACE pg_default;\n\nCREATE INDEX IF NOT EXISTS idx_pch_session \n  ON public.chat_histories USING btree (session_id) TABLESPACE pg_default;\n\nCREATE INDEX IF NOT EXISTS idx_pch_message_gin \n  ON public.chat_histories USING gin (message) TABLESPACE pg_default;\n\nCREATE INDEX IF NOT EXISTS idx_pch_message_type \n  ON public.chat_histories USING btree (((message ->> 'type'::text))) TABLESPACE pg_default;\n",
        "options": {},
        "operation": "executeQuery"
      },
      "credentials": {
        "postgres": {
          "id": "eQR2NFRag48wov9g",
          "name": "Postgres account"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "79acb218-684f-4b07-b1eb-9aa4fc580442",
      "name": "AI Agent1",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2752,
        224
      ],
      "parameters": {
        "text": "={{ $json.message }}",
        "options": {
          "systemMessage": "",
          "returnIntermediateSteps": true
        },
        "promptType": "define"
      },
      "typeVersion": 2.1
    },
    {
      "id": "a6085708-21b3-45f4-a22d-c16a5fa555b9",
      "name": "分组相似文档",
      "type": "n8n-nodes-base.code",
      "position": [
        112,
        2384
      ],
      "parameters": {
        "jsCode": "const results = [];\nfor (const item of $input.all()) {\n  const fileName = item.json?.fileName || item.json?.message?.document?.file_name || '';\n  const ext = fileName.toLowerCase().split('.').pop();\n\n  let type = 'fallback';\n  if (['csv'].includes(ext)) type = 'csv';\n  else if (['html', 'htm'].includes(ext)) type = 'html';\n  else if (['ics'].includes(ext)) type = 'ics';\n  else if (['json'].includes(ext)) type = 'json';\n  else if (['ods'].includes(ext)) type = 'ods';\n  else if (['pdf'].includes(ext)) type = 'pdf';\n  else if (['rtf'].includes(ext)) type = 'rtf';\n  else if (['txt', 'md', 'log'].includes(ext)) type = 'text file';\n  else if (['xml'].includes(ext)) type = 'xml';\n  else if (['xls', 'xlsx'].includes(ext)) type = 'spreadsheet';\n  else if (['jpg', 'jpeg', 'png', 'webp', 'gif', 'bmp', 'tiff'].includes(ext)) type = 'image';\n  else if (['mp3', 'wav', 'ogg', 'm4a', 'flac'].includes(ext)) type = 'audio';\n  else if (['mp4', 'mov', 'avi', 'mkv', 'webm'].includes(ext)) type = 'video';\n\n  item.json.fileTypeCategory = type;\n  results.push(item);\n}\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "103e1b3e-d6d9-4978-8764-c2b33b2a0d48",
      "name": "下载 CSV",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        1568
      ],
      "webhookId": "b4a21f4c-e6a6-4c83-9e8e-af73cb7cc96a",
      "parameters": {
        "fileId": "={{ ($json.message.photo?.[3]?.file_id ?? $json.message.photo?.[2]?.file_id ?? $json.message.photo?.[1]?.file_id ?? $json.message.photo?.[0]?.file_id) ?? $json.message.document?.file_id ?? $json.message.video?.file_id ?? $json.message.voice?.file_id ?? $json.message.video_note?.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e9cd5e19-eea6-403d-b5a3-36883d9782ec",
      "name": "从 CSV 提取",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        816,
        1568
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "9e531414-67e3-424e-9726-29c8c863d76c",
      "name": "下载 HTML",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        1712
      ],
      "webhookId": "b4a21f4c-e6a6-4c83-9e8e-af73cb7cc96a",
      "parameters": {
        "fileId": "={{ ($json.message.photo?.[3]?.file_id ?? $json.message.photo?.[2]?.file_id ?? $json.message.photo?.[1]?.file_id ?? $json.message.photo?.[0]?.file_id) ?? $json.message.document?.file_id ?? $json.message.video?.file_id ?? $json.message.voice?.file_id ?? $json.message.video_note?.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "667a75c9-a45b-40b5-9de6-cd840f5d6995",
      "name": "下载 ICS",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        1856
      ],
      "webhookId": "b4a21f4c-e6a6-4c83-9e8e-af73cb7cc96a",
      "parameters": {
        "fileId": "={{ ($json.message.photo?.[3]?.file_id ?? $json.message.photo?.[2]?.file_id ?? $json.message.photo?.[1]?.file_id ?? $json.message.photo?.[0]?.file_id) ?? $json.message.document?.file_id ?? $json.message.video?.file_id ?? $json.message.voice?.file_id ?? $json.message.video_note?.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "6e4a10de-3c7e-41cf-810f-281a62574e91",
      "name": "从 ICS 提取",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        816,
        1856
      ],
      "parameters": {
        "options": {},
        "operation": "fromIcs"
      },
      "typeVersion": 1
    },
    {
      "id": "3165d1f7-e8f5-484a-971b-af2ed35eacdf",
      "name": "下载 JSON",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        2000
      ],
      "webhookId": "b4a21f4c-e6a6-4c83-9e8e-af73cb7cc96a",
      "parameters": {
        "fileId": "={{ ($json.message.photo?.[3]?.file_id ?? $json.message.photo?.[2]?.file_id ?? $json.message.photo?.[1]?.file_id ?? $json.message.photo?.[0]?.file_id) ?? $json.message.document?.file_id ?? $json.message.video?.file_id ?? $json.message.voice?.file_id ?? $json.message.video_note?.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "fc4e50c8-0d01-46a2-96c0-b8f0d5fdba82",
      "name": "从 JSON 提取",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        816,
        2000
      ],
      "parameters": {
        "options": {},
        "operation": "fromJson"
      },
      "typeVersion": 1
    },
    {
      "id": "d2622448-e13d-4375-b574-8e5a0b79181f",
      "name": "下载 ODS",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        2144
      ],
      "webhookId": "b4a21f4c-e6a6-4c83-9e8e-af73cb7cc96a",
      "parameters": {
        "fileId": "={{ ($json.message.photo?.[3]?.file_id ?? $json.message.photo?.[2]?.file_id ?? $json.message.photo?.[1]?.file_id ?? $json.message.photo?.[0]?.file_id) ?? $json.message.document?.file_id ?? $json.message.video?.file_id ?? $json.message.voice?.file_id ?? $json.message.video_note?.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "56d95b61-5d98-483c-97b2-4047581eebc6",
      "name": "从 ODS 提取",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        816,
        2144
      ],
      "parameters": {
        "options": {},
        "operation": "ods"
      },
      "typeVersion": 1
    },
    {
      "id": "2eda95e3-ee26-44a5-9b04-8c48ce2dd102",
      "name": "下载 PDF",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        2384
      ],
      "webhookId": "b4a21f4c-e6a6-4c83-9e8e-af73cb7cc96a",
      "parameters": {
        "fileId": "={{ ($json.message.photo?.[3]?.file_id ?? $json.message.photo?.[2]?.file_id ?? $json.message.photo?.[1]?.file_id ?? $json.message.photo?.[0]?.file_id) ?? $json.message.document?.file_id ?? $json.message.video?.file_id ?? $json.message.voice?.file_id ?? $json.message.video_note?.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "bc486be9-a168-44ba-bc94-7cdbe34de8a6",
      "name": "从 PDF 提取",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        816,
        2304
      ],
      "parameters": {
        "options": {},
        "operation": "pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "b74f2a87-eeb9-4fdf-bd96-8eaa84c6725a",
      "name": "下载 RTF",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        2608
      ],
      "webhookId": "b4a21f4c-e6a6-4c83-9e8e-af73cb7cc96a",
      "parameters": {
        "fileId": "={{ ($json.message.photo?.[3]?.file_id ?? $json.message.photo?.[2]?.file_id ?? $json.message.photo?.[1]?.file_id ?? $json.message.photo?.[0]?.file_id) ?? $json.message.document?.file_id ?? $json.message.video?.file_id ?? $json.message.voice?.file_id ?? $json.message.video_note?.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "35ea0a0b-5fac-405c-a71f-96d0147c1398",
      "name": "从 RTF 文件提取",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        816,
        2608
      ],
      "parameters": {
        "options": {},
        "operation": "rtf"
      },
      "typeVersion": 1
    },
    {
      "id": "ae31e6c1-f78c-4433-bf25-ed0012651b0f",
      "name": "下载文本文件",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        2752
      ],
      "webhookId": "b4a21f4c-e6a6-4c83-9e8e-af73cb7cc96a",
      "parameters": {
        "fileId": "={{ ($json.message.photo?.[3]?.file_id ?? $json.message.photo?.[2]?.file_id ?? $json.message.photo?.[1]?.file_id ?? $json.message.photo?.[0]?.file_id) ?? $json.message.document?.file_id ?? $json.message.video?.file_id ?? $json.message.voice?.file_id ?? $json.message.video_note?.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "6f4cd402-8587-49d3-a7d0-48a0786a54db",
      "name": "从文件提取",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        816,
        2752
      ],
      "parameters": {
        "options": {},
        "operation": "text"
      },
      "typeVersion": 1
    },
    {
      "id": "4eacf584-639b-4ac3-b8d6-44d70fb15e50",
      "name": "下载 XML",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        2896
      ],
      "webhookId": "b4a21f4c-e6a6-4c83-9e8e-af73cb7cc96a",
      "parameters": {
        "fileId": "={{ ($json.message.photo?.[3]?.file_id ?? $json.message.photo?.[2]?.file_id ?? $json.message.photo?.[1]?.file_id ?? $json.message.photo?.[0]?.file_id) ?? $json.message.document?.file_id ?? $json.message.video?.file_id ?? $json.message.voice?.file_id ?? $json.message.video_note?.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "2c2b2612-7742-41b6-b9af-e9532eb02ffa",
      "name": "下载 XLSX",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        3040
      ],
      "webhookId": "b4a21f4c-e6a6-4c83-9e8e-af73cb7cc96a",
      "parameters": {
        "fileId": "={{ ($json.message.photo?.[3]?.file_id ?? $json.message.photo?.[2]?.file_id ?? $json.message.photo?.[1]?.file_id ?? $json.message.photo?.[0]?.file_id) ?? $json.message.document?.file_id ?? $json.message.video?.file_id ?? $json.message.voice?.file_id ?? $json.message.video_note?.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "4a176c17-3e17-40ce-b393-f8368fb1876f",
      "name": "从 XLSX 文件提取",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        816,
        3040
      ],
      "parameters": {
        "options": {},
        "operation": "xlsx"
      },
      "typeVersion": 1
    },
    {
      "id": "531d3f75-df5f-46bb-a744-b8d58933e7de",
      "name": "下载图片",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        896
      ],
      "webhookId": "b4a21f4c-e6a6-4c83-9e8e-af73cb7cc96a",
      "parameters": {
        "fileId": "={{ $json.message.photo[3]?.file_id || $json.message.photo[2]?.file_id || $json.message.photo[1]?.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7f8d7983-07c3-49a4-89ca-3e6ac78b06ad",
      "name": "下载音频",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        1040
      ],
      "webhookId": "b4a21f4c-e6a6-4c83-9e8e-af73cb7cc96a",
      "parameters": {
        "fileId": "={{ $json.message.audio.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "676fbda5-b36f-4bb5-988c-88686039a843",
      "name": "下载视频",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        1184
      ],
      "webhookId": "b4a21f4c-e6a6-4c83-9e8e-af73cb7cc96a",
      "parameters": {
        "fileId": "={{ ($json.message.photo?.[3]?.file_id ?? $json.message.photo?.[2]?.file_id ?? $json.message.photo?.[1]?.file_id ?? $json.message.photo?.[0]?.file_id) ?? $json.message.document?.file_id ?? $json.message.video?.file_id ?? $json.message.voice?.file_id ?? $json.message.video_note?.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "254f644a-b997-48e3-9951-1b7c73d1b9a1",
      "name": "分析图片",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        992,
        896
      ],
      "parameters": {
        "text": "What's in this image from telegram user?",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-flash",
          "cachedResultName": "models/gemini-2.5-flash"
        },
        "options": {},
        "resource": "image",
        "inputType": "binary",
        "operation": "analyze"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "to92mdfNe3L6sBae",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a7907789-e61f-4c78-99fa-5ab6628c593c",
      "name": "分析视频",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        992,
        1184
      ],
      "parameters": {
        "text": "What's in this video from telegram user?",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-pro",
          "cachedResultName": "models/gemini-2.5-pro"
        },
        "options": {},
        "resource": "video",
        "inputType": "binary",
        "operation": "analyze"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "to92mdfNe3L6sBae",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f51d23f0-ca23-47ed-a5ad-02dd0a076f26",
      "name": "Google Gemini 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        2704,
        432
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.5-pro"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "to92mdfNe3L6sBae",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "df67ffb8-5c61-4f80-9821-31e27fb19f37",
      "name": "分析语音消息",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        992,
        592
      ],
      "parameters": {
        "text": "What's in this audio message from telegram user?",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-pro",
          "cachedResultName": "models/gemini-2.5-pro"
        },
        "options": {},
        "resource": "audio",
        "inputType": "binary",
        "operation": "analyze"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "to92mdfNe3L6sBae",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "41686292-d7e8-485c-a5ab-e77d773e832e",
      "name": "分析音频",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        992,
        1040
      ],
      "parameters": {
        "text": "What's in this audio from telegram user?",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-flash",
          "cachedResultName": "models/gemini-2.5-flash"
        },
        "options": {},
        "resource": "audio",
        "inputType": "binary",
        "operation": "analyze"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "to92mdfNe3L6sBae",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "59ede965-ef67-48fd-8561-3ac74b33d47a",
      "name": "修复 mime4",
      "type": "n8n-nodes-base.code",
      "position": [
        832,
        1184
      ],
      "parameters": {
        "jsCode": "// --- Mapa Extendido de Tipos MIME ---\n// Una lista completa para cubrir la mayoría de los formatos de archivo comunes.\nconst mimeMap = {\n  // --- Formatos de Documentos ---\n  'pdf': 'application/pdf',\n  'txt': 'text/plain',\n  'rtf': 'application/rtf',\n  'csv': 'text/csv',\n  'html': 'text/html',\n  'htm': 'text/html',\n  'json': 'application/json',\n  'xml': 'application/xml', // 'text/xml' también es válido pero 'application/xml' es más común\n  'yaml': 'application/x-yaml',\n  'yml': 'application/x-yaml',\n\n  // --- Formatos de Microsoft Office ---\n  'doc': 'application/msword',\n  'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n  'xls': 'application/vnd.ms-excel',\n  'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n  'ppt': 'application/vnd.ms-powerpoint',\n  'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n  'pub': 'application/vnd.ms-publisher',\n\n  // --- Formatos de OpenOffice / LibreOffice ---\n  'odt': 'application/vnd.oasis.opendocument.text',\n  'ods': 'application/vnd.oasis.opendocument.spreadsheet',\n  'odp': 'application/vnd.oasis.opendocument.presentation',\n  'odg': 'application/vnd.oasis.opendocument.graphics',\n\n  // --- Formatos de Apple iWork ---\n  'pages': 'application/vnd.apple.pages',\n  'numbers': 'application/vnd.apple.numbers',\n  'key': 'application/vnd.apple.keynote',\n\n  // --- Formatos de Imagen ---\n  'png': 'image/png',\n  'jpg': 'image/jpeg',\n  'jpeg': 'image/jpeg',\n  'gif': 'image/gif',\n  'webp': 'image/webp',\n  'svg': 'image/svg+xml',\n  'bmp': 'image/bmp',\n  'ico': 'image/vnd.microsoft.icon',\n  'tif': 'image/tiff',\n  'tiff': 'image/tiff',\n  'heic': 'image/heic',\n  'heif': 'image/heif',\n\n  // --- Formatos de Audio ---\n  'mp3': 'audio/mpeg',\n  'wav': 'audio/wav',\n  'oga': 'audio/ogg',\n  'ogg': 'audio/ogg',\n  'flac': 'audio/flac',\n  'm4a': 'audio/mp4',\n  'aac': 'audio/aac',\n  'opus': 'audio/opus',\n  'wma': 'audio/x-ms-wma',\n  'mid': 'audio/midi',\n  'midi': 'audio/midi',\n\n  // --- Formatos de Video ---\n  'mp4': 'video/mp4',\n  'mov': 'video/quicktime',\n  'webm': 'video/webm',\n  'mpeg': 'video/mpeg',\n  'mpg': 'video/mpeg',\n  'avi': 'video/x-msvideo',\n  'wmv': 'video/x-ms-wmv',\n  'flv': 'video/x-flv',\n  'mkv': 'video/x-matroska',\n\n  // --- Formatos de Archivos y Compresión ---\n  'zip': 'application/zip',\n  'rar': 'application/vnd.rar',\n  '7z': 'application/x-7z-compressed',\n  'tar': 'application/x-tar',\n  'gz': 'application/gzip',\n  'bz2': 'application/x-bzip2',\n\n  // --- Otros Formatos ---\n  'epub': 'application/epub+zip',\n  'ics': 'text/calendar',\n  'vcf': 'text/vcard',\n  'js': 'text/javascript',\n  'css': 'text/css',\n  'sh': 'application/x-sh',\n  'py': 'text/x-python',\n};\n\n// --- Lógica de Procesamiento (sin cambios) ---\n\n// Obtenemos todos los items que llegan al nodo\nconst items = $input.all();\n\n// Iteramos sobre cada item para procesarlo\nfor (const item of items) {\n  // Verificamos que el item tenga datos binarios para procesar\n  if (item.binary && item.binary['data']) {\n    // Obtenemos el nombre del archivo de forma segura\n    const fileName = item.binary['data'].fileName || '';\n    if (!fileName) {\n      continue; // Si no hay nombre de archivo, pasamos al siguiente item\n    }\n\n    // Extraemos la extensión del archivo de forma robusta\n    const extension = fileName.slice((fileName.lastIndexOf(\".\") - 1 >>> 0) + 2).toLowerCase();\n\n    // Buscamos la extensión en nuestro mapa\n    const newMimeType = mimeMap[extension];\n\n    // Si encontramos una coincidencia en el mapa, actualizamos el mimeType\n    if (newMimeType) {\n      if(item.binary['data'].mimeType !== newMimeType) {\n        console.log(`Cambiando mimeType para '${fileName}' de '${item.binary['data'].mimeType}' a '${newMimeType}'.`);\n        item.binary['data'].mimeType = newMimeType;\n      }\n    }\n  }\n}\n\n// Devolvemos todos los items, modificados o no\nreturn items;"
      },
      "typeVersion": 2
    },
    {
      "id": "2b523644-3ba1-4207-b911-aa969952aef4",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        288,
        2240
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "csv",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "f1aefe24-17fb-4bf8-84fb-949a6802b66e",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "csv"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "html",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "b09d29b5-b263-4115-963d-d6879de78649",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "html"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "ics",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "2a7822f4-889b-41d3-8a1c-7f4405eacb42",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "ics"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "json",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "f09cd376-96df-4f3d-9218-6a918715335a",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "json"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "ods",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "1bf5c1f9-38a9-4bc5-8757-b85f98441579",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "ods"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "pdf",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "4988d14f-4e3f-4494-96b0-a1a9d70a2787",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "pdf"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "rtf",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "f5bc921e-c083-4b12-8167-86a24e39fe5c",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "rtf"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "text file",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "29251fca-c611-419c-85a2-a9e1ad6bd102",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "text file"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "xml",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "fd1cbb91-f3c6-4b20-91dc-2e490f77fe96",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "xml"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "spreadsheet",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "16fc2a80-c341-4a5d-9d50-a1856ffb5242",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.fileTypeCategory }}",
                    "rightValue": "spreadsheet"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "typeVersion": 3.2
    },
    {
      "id": "7670cee6-0878-4d74-87d3-2630b946b6e1",
      "name": "下载视频笔记",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        752
      ],
      "webhookId": "b4a21f4c-e6a6-4c83-9e8e-af73cb7cc96a",
      "parameters": {
        "fileId": "={{ ($json.message.photo?.[3]?.file_id ?? $json.message.photo?.[2]?.file_id ?? $json.message.photo?.[1]?.file_id ?? $json.message.photo?.[0]?.file_id) ?? $json.message.document?.file_id ?? $json.message.video?.file_id ?? $json.message.voice?.file_id ?? $json.message.video_note?.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "380c0b9e-ba40-4099-bbaf-b36436d37929",
      "name": "分析视频笔记",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        992,
        752
      ],
      "parameters": {
        "text": "What's in this video message from telegram user? don't talk about the circular frame of telegram",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-pro",
          "cachedResultName": "models/gemini-2.5-pro"
        },
        "options": {},
        "resource": "video",
        "simplify": false,
        "inputType": "=binary",
        "operation": "analyze"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "to92mdfNe3L6sBae",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "97b671be-497f-4a55-8ec1-f09aa8a2cb59",
      "name": "get_message(音频/视频消息)",
      "type": "n8n-nodes-base.set",
      "position": [
        1344,
        672
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d8935452-fe20-469d-a68d-1aad056cb8dd",
              "name": "message",
              "type": "string",
              "value": "=Media message description:{{ $json.candidates?.[0]?.content?.parts?.[0]?.text || $json.content?.parts?.[0]?.text }}"
            },
            {
              "id": "93f1bba1-1180-404a-93ca-c34cf1d1b7ac",
              "name": "chat_id",
              "type": "string",
              "value": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "75b413f5-5fcd-46de-8350-30fb21cda45c",
      "name": "获取消息(媒体消息)",
      "type": "n8n-nodes-base.set",
      "position": [
        1328,
        1040
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d8935452-fe20-469d-a68d-1aad056cb8dd",
              "name": "message",
              "type": "string",
              "value": "=Media description: {{ $json.content.parts[0].text }}"
            },
            {
              "id": "53e34499-7dad-4f94-aa7d-f778321f13f4",
              "name": "chat_id",
              "type": "string",
              "value": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "51f6188d-d24c-49d1-9c65-0ab65fe928b4",
      "name": "获取消息(文件消息)",
      "type": "n8n-nodes-base.set",
      "position": [
        1600,
        2352
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d8935452-fe20-469d-a68d-1aad056cb8dd",
              "name": "message",
              "type": "string",
              "value": "=File name:{{ $('Telegram Trigger').item.json.message.document.file_name }}\nFile type:{{ $('Group Similar Documents').first().json.fileTypeCategory }}\nExtracted data from file:\n{{ $json.data }}"
            },
            {
              "id": "6bceaed5-5a79-4354-a49a-d794ce4fb3ee",
              "name": "chat_id",
              "type": "number",
              "value": "={{ $('Telegram Trigger').first().json.message.chat.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "96ed37cd-7be0-40ee-b835-56cbfdc01045",
      "name": "正在输入...",
      "type": "n8n-nodes-base.telegram",
      "position": [
        288,
        672
      ],
      "webhookId": "412793ca-7cad-4a84-acea-98debbbfa2ac",
      "parameters": {
        "chatId": "={{ $json.message.chat.id }}",
        "operation": "sendChatAction"
      },
      "credentials": {
        "telegramApi": {
          "id": "rzhkYoexl5hHvqnv",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "38c087b9-b4aa-4f46-a9d6-441973c673cb",
      "name": "修复MIME类型",
      "type": "n8n-nodes-base.code",
      "position": [
        832,
        592
      ],
      "parameters": {
        "jsCode": "// --- Mapa Extendido de Tipos MIME ---\n// Una lista completa para cubrir la mayoría de los formatos de archivo comunes.\nconst mimeMap = {\n  // --- Formatos de Documentos ---\n  'pdf': 'application/pdf',\n  'txt': 'text/plain',\n  'rtf': 'application/rtf',\n  'csv': 'text/csv',\n  'html': 'text/html',\n  'htm': 'text/html',\n  'json': 'application/json',\n  'xml': 'application/xml', // 'text/xml' también es válido pero 'application/xml' es más común\n  'yaml': 'application/x-yaml',\n  'yml': 'application/x-yaml',\n\n  // --- Formatos de Microsoft Office ---\n  'doc': 'application/msword',\n  'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n  'xls': 'application/vnd.ms-excel',\n  'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n  'ppt': 'application/vnd.ms-powerpoint',\n  'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n  'pub': 'application/vnd.ms-publisher',\n\n  // --- Formatos de OpenOffice / LibreOffice ---\n  'odt': 'application/vnd.oasis.opendocument.text',\n  'ods': 'application/vnd.oasis.opendocument.spreadsheet',\n  'odp': 'application/vnd.oasis.opendocument.presentation',\n  'odg': 'application/vnd.oasis.opendocument.graphics',\n\n  // --- Formatos de Apple iWork ---\n  'pages': 'application/vnd.apple.pages',\n  'numbers': 'application/vnd.apple.numbers',\n  'key': 'application/vnd.apple.keynote',\n\n  // --- Formatos de Imagen ---\n  'png': 'image/png',\n  'jpg': 'image/jpeg',\n  'jpeg': 'image/jpeg',\n  'gif': 'image/gif',\n  'webp': 'image/webp',\n  'svg': 'image/svg+xml',\n  'bmp': 'image/bmp',\n  'ico': 'image/vnd.microsoft.icon',\n  'tif': 'image/tiff',\n  'tiff': 'image/tiff',\n  'heic': 'image/heic',\n  'heif': 'image/heif',\n\n  // --- Formatos de Audio ---\n  'mp3': 'audio/mpeg',\n  'wav': 'audio/wav',\n  'oga': 'audio/ogg',\n  'ogg': 'audio/ogg',\n  'flac': 'audio/flac',\n  'm4a': 'audio/mp4',\n  'aac': 'audio/aac',\n  'opus': 'audio/opus',\n  'wma': 'audio/x-ms-wma',\n  'mid': 'audio/midi',\n  'midi': 'audio/midi',\n\n  // --- Formatos de Video ---\n  'mp4': 'video/mp4',\n  'mov': 'video/quicktime',\n  'webm': 'video/webm',\n  'mpeg': 'video/mpeg',\n  'mpg': 'video/mpeg',\n  'avi': 'video/x-msvideo',\n  'wmv': 'video/x-ms-wmv',\n  'flv': 'video/x-flv',\n  'mkv': 'video/x-matroska',\n\n  // --- Formatos de Archivos y Compresión ---\n  'zip': 'application/zip',\n  'rar': 'application/vnd.rar',\n  '7z': 'application/x-7z-compressed',\n  'tar': 'application/x-tar',\n  'gz': 'application/gzip',\n  'bz2': 'application/x-bzip2',\n\n  // --- Otros Formatos ---\n  'epub': 'application/epub+zip',\n  'ics': 'text/calendar',\n  'vcf': 'text/vcard',\n  'js': 'text/javascript',\n  'css': 'text/css',\n  'sh': 'application/x-sh',\n  'py': 'text/x-python',\n};\n\n// --- Lógica de Procesamiento (sin cambios) ---\n\n// Obtenemos todos los items que llegan al nodo\nconst items = $input.all();\n\n// Iteramos sobre cada item para procesarlo\nfor (const item of items) {\n  // Verificamos que el item tenga datos binarios para procesar\n  if (item.binary && item.binary['data']) {\n    // Obtenemos el nombre del archivo de forma segura\n    const fileName = item.binary['data'].fileName || '';\n    if (!fileName) {\n      continue; // Si no hay nombre de archivo, pasamos al siguiente item\n    }\n\n    // Extraemos la extensión del archivo de forma robusta\n    const extension = fileName.slice((fileName.lastIndexOf(\".\") - 1 >>> 0) + 2).toLowerCase();\n\n    // Buscamos la extensión en nuestro mapa\n    const newMimeType = mimeMap[extension];\n\n    // Si encontramos una coincidencia en el mapa, actualizamos el mimeType\n    if (newMimeType) {\n      if(item.binary['data'].mimeType !== newMimeType) {\n        console.log(`Cambiando mimeType para '${fileName}' de '${item.binary['data'].mimeType}' a '${newMimeType}'.`);\n        item.binary['data'].mimeType = newMimeType;\n      }\n    }\n  }\n}\n\n// Devolvemos todos los items, modificados o no\nreturn items;"
      },
      "typeVersion": 2
    },
    {
      "id": "7c36439c-3651-4f2a-b352-8b08d1e1011a",
      "name": "修复 mime1",
      "type": "n8n-nodes-base.code",
      "position": [
        832,
        752
      ],
      "parameters": {
        "jsCode": "// --- Mapa Extendido de Tipos MIME ---\n// Una lista completa para cubrir la mayoría de los formatos de archivo comunes.\nconst mimeMap = {\n  // --- Formatos de Documentos ---\n  'pdf': 'application/pdf',\n  'txt': 'text/plain',\n  'rtf': 'application/rtf',\n  'csv': 'text/csv',\n  'html': 'text/html',\n  'htm': 'text/html',\n  'json': 'application/json',\n  'xml': 'application/xml', // 'text/xml' también es válido pero 'application/xml' es más común\n  'yaml': 'application/x-yaml',\n  'yml': 'application/x-yaml',\n\n  // --- Formatos de Microsoft Office ---\n  'doc': 'application/msword',\n  'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n  'xls': 'application/vnd.ms-excel',\n  'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n  'ppt': 'application/vnd.ms-powerpoint',\n  'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n  'pub': 'application/vnd.ms-publisher',\n\n  // --- Formatos de OpenOffice / LibreOffice ---\n  'odt': 'application/vnd.oasis.opendocument.text',\n  'ods': 'application/vnd.oasis.opendocument.spreadsheet',\n  'odp': 'application/vnd.oasis.opendocument.presentation',\n  'odg': 'application/vnd.oasis.opendocument.graphics',\n\n  // --- Formatos de Apple iWork ---\n  'pages': 'application/vnd.apple.pages',\n  'numbers': 'application/vnd.apple.numbers',\n  'key': 'application/vnd.apple.keynote',\n\n  // --- Formatos de Imagen ---\n  'png': 'image/png',\n  'jpg': 'image/jpeg',\n  'jpeg': 'image/jpeg',\n  'gif': 'image/gif',\n  'webp': 'image/webp',\n  'svg': 'image/svg+xml',\n  'bmp': 'image/bmp',\n  'ico': 'image/vnd.microsoft.icon',\n  'tif': 'image/tiff',\n  'tiff': 'image/tiff',\n  'heic': 'image/heic',\n  'heif': 'image/heif',\n\n  // --- Formatos de Audio ---\n  'mp3': 'audio/mpeg',\n  'wav': 'audio/wav',\n  'oga': 'audio/ogg',\n  'ogg': 'audio/ogg',\n  'flac': 'audio/flac',\n  'm4a': 'audio/mp4',\n  'aac': 'audio/aac',\n  'opus': 'audio/opus',\n  'wma': 'audio/x-ms-wma',\n  'mid': 'audio/midi',\n  'midi': 'audio/midi',\n\n  // --- Formatos de Video ---\n  'mp4': 'video/mp4',\n  'mov': 'video/quicktime',\n  'webm': 'video/webm',\n  'mpeg': 'video/mpeg',\n  'mpg': 'video/mpeg',\n  'avi': 'video/x-msvideo',\n  'wmv': 'video/x-ms-wmv',\n  'flv': 'video/x-flv',\n  'mkv': 'video/x-matroska',\n\n  // --- Formatos de Archivos y Compresión ---\n  'zip': 'application/zip',\n  'rar': 'application/vnd.rar',\n  '7z': 'application/x-7z-compressed',\n  'tar': 'application/x-tar',\n  'gz': 'application/gzip',\n  'bz2': 'application/x-bzip2',\n\n  // --- Otros Formatos ---\n  'epub': 'application/epub+zip',\n  'ics': 'text/calendar',\n  'vcf': 'text/vcard',\n  'js': 'text/javascript',\n  'css': 'text/css',\n  'sh': 'application/x-sh',\n  'py': 'text/x-python',\n};\n\n// --- Lógica de Procesamiento (sin cambios) ---\n\n// Obtenemos todos los items que llegan al nodo\nconst items = $input.all();\n\n// Iteramos sobre cada item para procesarlo\nfor (const item of items) {\n  // Verificamos que el item tenga datos binarios para procesar\n  if (item.binary && item.binary['data']) {\n    // Obtenemos el nombre del archivo de forma segura\n    const fileName = item.binary['data'].fileName || '';\n    if (!fileName) {\n      continue; // Si no hay nombre de archivo, pasamos al siguiente item\n    }\n\n    // Extraemos la extensión del archivo de forma robusta\n    const extension = fileName.slice((fileName.lastIndexOf(\".\") - 1 >>> 0) + 2).toLowerCase();\n\n    // Buscamos la extensión en nuestro mapa\n    const newMimeType = mimeMap[extension];\n\n    // Si encontramos una coincidencia en el mapa, actualizamos el mimeType\n    if (newMimeType) {\n      if(item.binary['data'].mimeType !== newMimeType) {\n        console.log(`Cambiando mimeType para '${fileName}' de '${item.binary['data'].mimeType}' a '${newMimeType}'.`);\n        item.binary['data'].mimeType = newMimeType;\n      }\n    }\n  }\n}\n\n// Devolvemos todos los items, modificados o no\nreturn items;"
      },
      "typeVersion": 2
    },
    {
      "id": "106c972e-16c3-475a-97f0-cf82925f0418",
      "name": "修复 mime5",
      "type": "n8n-nodes-base.code",
      "position": [
        832,
        896
      ],
      "parameters": {
        "jsCode": "// --- Mapa Extendido de Tipos MIME ---\n// Una lista completa para cubrir la mayoría de los formatos de archivo comunes.\nconst mimeMap = {\n  // --- Formatos de Documentos ---\n  'pdf': 'application/pdf',\n  'txt': 'text/plain',\n  'rtf': 'application/rtf',\n  'csv': 'text/csv',\n  'html': 'text/html',\n  'htm': 'text/html',\n  'json': 'application/json',\n  'xml': 'application/xml', // 'text/xml' también es válido pero 'application/xml' es más común\n  'yaml': 'application/x-yaml',\n  'yml': 'application/x-yaml',\n\n  // --- Formatos de Microsoft Office ---\n  'doc': 'application/msword',\n  'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n  'xls': 'application/vnd.ms-excel',\n  'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n  'ppt': 'application/vnd.ms-powerpoint',\n  'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n  'pub': 'application/vnd.ms-publisher',\n\n  // --- Formatos de OpenOffice / LibreOffice ---\n  'odt': 'application/vnd.oasis.opendocument.text',\n  'ods': 'application/vnd.oasis.opendocument.spreadsheet',\n  'odp': 'application/vnd.oasis.opendocument.presentation',\n  'odg': 'application/vnd.oasis.opendocument.graphics',\n\n  // --- Formatos de Apple iWork ---\n  'pages': 'application/vnd.apple.pages',\n  'numbers': 'application/vnd.apple.numbers',\n  'key': 'application/vnd.apple.keynote',\n\n  // --- Formatos de Imagen ---\n  'png': 'image/png',\n  'jpg': 'image/jpeg',\n  'jpeg': 'image/jpeg',\n  'gif': 'image/gif',\n  'webp': 'image/webp',\n  'svg': 'image/svg+xml',\n  'bmp': 'image/bmp',\n  'ico': 'image/vnd.microsoft.icon',\n  'tif': 'image/tiff',\n  'tiff': 'image/tiff',\n  'heic': 'image/heic',\n  'heif': 'image/heif',\n\n  // --- Formatos de Audio ---\n  'mp3': 'audio/mpeg',\n  'wav': 'audio/wav',\n  'oga': 'audio/ogg',\n  'ogg': 'audio/ogg',\n  'flac': 'audio/flac',\n  'm4a': 'audio/mp4',\n  'aac': 'audio/aac',\n  'opus': 'audio/opus',\n  'wma': 'audio/x-ms-wma',\n  'mid': 'audio/midi',\n  'midi': 'audio/midi',\n\n  // --- Formatos de Video ---\n  'mp4': 'video/mp4',\n  'mov': 'video/quicktime',\n  'webm': 'video/webm',\n  'mpeg': 'video/mpeg',\n  'mpg': 'video/mpeg',\n  'avi': 'video/x-msvideo',\n  'wmv': 'video/x-ms-wmv',\n  'flv': 'video/x-flv',\n  'mkv': 'video/x-matroska',\n\n  // --- Formatos de Archivos y Compresión ---\n  'zip': 'application/zip',\n  'rar': 'application/vnd.rar',\n  '7z': 'application/x-7z-compressed',\n  'tar': 'application/x-tar',\n  'gz': 'application/gzip',\n  'bz2': 'application/x-bzip2',\n\n  // --- Otros Formatos ---\n  'epub': 'application/epub+zip',\n  'ics': 'text/calendar',\n  'vcf': 'text/vcard',\n  'js': 'text/javascript',\n  'css': 'text/css',\n  'sh': 'application/x-sh',\n  'py': 'text/x-python',\n};\n\n// --- Lógica de Procesamiento (sin cambios) ---\n\n// Obtenemos todos los items que llegan al nodo\nconst items = $input.all();\n\n// Iteramos sobre cada item para procesarlo\nfor (const item of items) {\n  // Verificamos que el item tenga datos binarios para procesar\n  if (item.binary && item.binary['data']) {\n    // Obtenemos el nombre del archivo de forma segura\n    const fileName = item.binary['data'].fileName || '';\n    if (!fileName) {\n      continue; // Si no hay nombre de archivo, pasamos al siguiente item\n    }\n\n    // Extraemos la extensión del archivo de forma robusta\n    const extension = fileName.slice((fileName.lastIndexOf(\".\") - 1 >>> 0) + 2).toLowerCase();\n\n    // Buscamos la extensión en nuestro mapa\n    const newMimeType = mimeMap[extension];\n\n    // Si encontramos una coincidencia en el mapa, actualizamos el mimeType\n    if (newMimeType) {\n      if(item.binary['data'].mimeType !== newMimeType) {\n        console.log(`Cambiando mimeType para '${fileName}' de '${item.binary['data'].mimeType}' a '${newMimeType}'.`);\n        item.binary['data'].mimeType = newMimeType;\n      }\n    }\n  }\n}\n\n// Devolvemos todos los items, modificados o no\nreturn items;"
      },
      "typeVersion": 2
    },
    {
      "id": "7ec7948e-2911-4210-ba01-8aa336222d37",
      "name": "修复 mime6",
      "type": "n8n-nodes-base.code",
      "position": [
        832,
        1040
      ],
      "parameters": {
        "jsCode": "// --- Mapa Extendido de Tipos MIME ---\n// Una lista completa para cubrir la mayoría de los formatos de archivo comunes.\nconst mimeMap = {\n  // --- Formatos de Documentos ---\n  'pdf': 'application/pdf',\n  'txt': 'text/plain',\n  'rtf': 'application/rtf',\n  'csv': 'text/csv',\n  'html': 'text/html',\n  'htm': 'text/html',\n  'json': 'application/json',\n  'xml': 'application/xml', // 'text/xml' también es válido pero 'application/xml' es más común\n  'yaml': 'application/x-yaml',\n  'yml': 'application/x-yaml',\n\n  // --- Formatos de Microsoft Office ---\n  'doc': 'application/msword',\n  'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n  'xls': 'application/vnd.ms-excel',\n  'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n  'ppt': 'application/vnd.ms-powerpoint',\n  'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n  'pub': 'application/vnd.ms-publisher',\n\n  // --- Formatos de OpenOffice / LibreOffice ---\n  'odt': 'application/vnd.oasis.opendocument.text',\n  'ods': 'application/vnd.oasis.opendocument.spreadsheet',\n  'odp': 'application/vnd.oasis.opendocument.presentation',\n  'odg': 'application/vnd.oasis.opendocument.graphics',\n\n  // --- Formatos de Apple iWork ---\n  'pages': 'application/vnd.apple.pages',\n  'numbers': 'application/vnd.apple.numbers',\n  'key': 'application/vnd.apple.keynote',\n\n  // --- Formatos de Imagen ---\n  'png': 'image/png',\n  'jpg': 'image/jpeg',\n  'jpeg': 'image/jpeg',\n  'gif': 'image/gif',\n  'webp': 'image/webp',\n  'svg': 'image/svg+xml',\n  'bmp': 'image/bmp',\n  'ico': 'image/vnd.microsoft.icon',\n  'tif': 'image/tiff',\n  'tiff': 'image/tiff',\n  'heic': 'image/heic',\n  'heif': 'image/heif',\n\n  // --- Formatos de Audio ---\n  'mp3': 'audio/mpeg',\n  'wav': 'audio/wav',\n  'oga': 'audio/ogg',\n  'ogg': 'audio/ogg',\n  'flac': 'audio/flac',\n  'm4a': 'audio/mp4',\n  'aac': 'audio/aac',\n  'opus': 'audio/opus',\n  'wma': 'audio/x-ms-wma',\n  'mid': 'audio/midi',\n  'midi': 'audio/midi',\n\n  // --- Formatos de Video ---\n  'mp4': 'video/mp4',\n  'mov': 'video/quicktime',\n  'webm': 'video/webm',\n  'mpeg': 'video/mpeg',\n  'mpg': 'video/mpeg',\n  'avi': 'video/x-msvideo',\n  'wmv': 'video/x-ms-wmv',\n  'flv': 'video/x-flv',\n  'mkv': 'video/x-matroska',\n\n  // --- Formatos de Archivos y Compresión ---\n  'zip': 'application/zip',\n  'rar': 'application/vnd.rar',\n  '7z': 'application/x-7z-compressed',\n  'tar': 'application/x-tar',\n  'gz': 'application/gzip',\n  'bz2': 'application/x-bzip2',\n\n  // --- Otros Formatos ---\n  'epub': 'application/epub+zip',\n  'ics': 'text/calendar',\n  'vcf': 'text/vcard',\n  'js': 'text/javascript',\n  'css': 'text/css',\n  'sh': 'application/x-sh',\n  'py': 'text/x-python',\n};\n\n// --- Lógica de Procesamiento (sin cambios) ---\n\n// Obtenemos todos los items que llegan al nodo\nconst items = $input.all();\n\n// Iteramos sobre cada item para procesarlo\nfor (const item of items) {\n  // Verificamos que el item tenga datos binarios para procesar\n  if (item.binary && item.binary['data']) {\n    // Obtenemos el nombre del archivo de forma segura\n    const fileName = item.binary['data'].fileName || '';\n    if (!fileName) {\n      continue; // Si no hay nombre de archivo, pasamos al siguiente item\n    }\n\n    // Extraemos la extensión del archivo de forma robusta\n    const extension = fileName.slice((fileName.lastIndexOf(\".\") - 1 >>> 0) + 2).toLowerCase();\n\n    // Buscamos la extensión en nuestro mapa\n    const newMimeType = mimeMap[extension];\n\n    // Si encontramos una coincidencia en el mapa, actualizamos el mimeType\n    if (newMimeType) {\n      if(item.binary['data'].mimeType !== newMimeType) {\n        console.log(`Cambiando mimeType para '${fileName}' de '${item.binary['data'].mimeType}' a '${newMimeType}'.`);\n        item.binary['data'].mimeType = newMimeType;\n      }\n    }\n  }\n}\n\n// Devolvemos todos los items, modificados o no\nreturn items;"
      },
      "typeVersion": 2
    },
    {
      "id": "fd158cd1-0b00-46af-9e93-5ca547ec50cf",
      "name": "聚合",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        992,
        1568
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "204de387-f70d-4896-ad2c-de7de33f6c39",
      "name": "get_error_message",
      "type": "n8n-nodes-base.set",
      "position": [
        656,
        3200
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d8935452-fe20-469d-a68d-1aad056cb8dd",
              "name": "message",
              "type": "string",
              "value": "=It was not possible to process the file.File type not supported."
            },
            {
              "id": "38ba2498-2141-4a04-a22a-64563fe2ee6f",
              "name": "chat_id",
              "type": "string",
              "value": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "b69049a0-4636-41df-9e16-4858a615c694",
      "name": "HTML 通用提取1",
      "type": "n8n-nodes-base.html",
      "position": [
        816,
        1712
      ],
      "parameters": {
        "options": {
          "cleanUpText": true
        },
        "operation": "extractHtmlContent",
        "sourceData": "binary",
        "extractionValues": {
          "values": [
            {
              "key": "pageTitle",
              "cssSelector": "title"
            },
            {
              "key": "metaDescription",
              "cssSelector": "meta[name=\"description\"]"
            },
            {
              "key": "fullBodyText",
              "cssSelector": "body",
              "returnValue": "html"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b148db43-c8f0-40ab-a036-c2c95ca4d517",
      "name": "获取 ODS 数据",
      "type": "n8n-nodes-base.code",
      "position": [
        992,
        2144
      ],
      "parameters": {
        "jsCode": "// Get the first item from the input array.\nconst firstItem = items[0];\n\n// Create a new object that has a single key: \"data\".\n// The value of \"data\" will be the entire json object from the input.\n// This gathers all fields (First Name, Last Name, Age, etc.) dynamically.\nconst result = {\n  data: firstItem.json\n};\n\n// Return the newly structured object.\n// It will be outputted as a single item with a 'json' property\n// containing the 'data' object.\nreturn result;"
      },
      "typeVersion": 2
    },
    {
      "id": "442323ac-185c-4fc6-8dd9-00d4ae8e1468",
      "name": "标准化 ODS",
      "type": "n8n-nodes-base.set",
      "position": [
        1152,
        2144
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "24b93984-e305-4c11-a856-5fa0bfaaaa79",
              "name": "data",
              "type": "string",
              "value": "={{ $json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "0d73a0f8-7c3b-4f17-b514-d93ec0249723",
      "name": "标准化 CSV",
      "type": "n8n-nodes-base.set",
      "position": [
        1184,
        1568
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "24b93984-e305-4c11-a856-5fa0bfaaaa79",
              "name": "data",
              "type": "string",
              "value": "={{ $json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "884fe46d-7a14-48e7-be5c-a7def4b90a89",
      "name": "标准化 HTML",
      "type": "n8n-nodes-base.set",
      "position": [
        992,
        1712
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "b4ab7227-9db9-4c74-aa17-80071ee0a7f0",
              "name": "data",
              "type": "string",
              "value": "=Page title:  {{ $json.pageTitle}}\nMeta description: {{ $json.metaDescription }}\nbody: {{ $json.fullBodyText }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "903ec5a1-3499-4afc-9e93-2b2a053851a3",
      "name": "标准化 ICS",
      "type": "n8n-nodes-base.set",
      "position": [
        992,
        1856
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "24b93984-e305-4c11-a856-5fa0bfaaaa79",
              "name": "data",
              "type": "string",
              "value": "={{ $json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "31b3b69a-b52d-4270-b931-4fcd1989a2d9",
      "name": "标准化 JSON",
      "type": "n8n-nodes-base.set",
      "position": [
        992,
        2000
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "24b93984-e305-4c11-a856-5fa0bfaaaa79",
              "name": "data",
              "type": "string",
              "value": "={{ $json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2dc5bcf2-f069-4d6a-a6a4-5d2196ec00e7",
      "name": "标准化 PDF",
      "type": "n8n-nodes-base.set",
      "position": [
        1152,
        2288
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "24b93984-e305-4c11-a856-5fa0bfaaaa79",
              "name": "data",
              "type": "string",
              "value": "={{ $json.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "1dc4cb0d-91fb-475f-9372-6632004575ad",
      "name": "标准化 RTF",
      "type": "n8n-nodes-base.set",
      "position": [
        1152,
        2608
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "24b93984-e305-4c11-a856-5fa0bfaaaa79",
              "name": "data",
              "type": "string",
              "value": "={{ $json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "3be04317-b1ed-4cc8-a1f1-9df1d812933c",
      "name": "标准化文本文件",
      "type": "n8n-nodes-base.set",
      "position": [
        992,
        2752
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "24b93984-e305-4c11-a856-5fa0bfaaaa79",
              "name": "data",
              "type": "string",
              "value": "={{ $json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "636dc479-d4f7-4479-9419-5d9d2b4a3e17",
      "name": "标准化 XML",
      "type": "n8n-nodes-base.set",
      "position": [
        992,
        2896
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "24b93984-e305-4c11-a856-5fa0bfaaaa79",
              "name": "data",
              "type": "string",
              "value": "={{ $json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a69753d3-2192-4403-88e4-c2501ef7674e",
      "name": "从 XML 提取",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        816,
        2896
      ],
      "parameters": {
        "options": {},
        "operation": "xml"
      },
      "typeVersion": 1
    },
    {
      "id": "8b7ef925-ffae-48e0-a9d2-8709e8e8eeeb",
      "name": "标准化 XLSX",
      "type": "n8n-nodes-base.set",
      "position": [
        1152,
        3040
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "24b93984-e305-4c11-a856-5fa0bfaaaa79",
              "name": "data",
              "type": "string",
              "value": "={{ $json.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d0f59676-cc67-4969-89a3-d9bec0636b61",
      "name": "获取 RTF 数据",
      "type": "n8n-nodes-base.code",
      "position": [
        992,
        2608
      ],
      "parameters": {
        "jsCode": "// Get the first item from the input array.\nconst firstItem = items[0];\n\n// Create a new object that has a single key: \"data\".\n// The value of \"data\" will be the entire json object from the input.\n// This gathers all fields (First Name, Last Name, Age, etc.) dynamically.\nconst result = {\n  data: firstItem.json\n};\n\n// Return the newly structured object.\n// It will be outputted as a single item with a 'json' property\n// containing the 'data' object.\nreturn result;"
      },
      "typeVersion": 2
    },
    {
      "id": "9b32b25d-ddc0-4586-a111-e8c342ea09c8",
      "name": "获取 RTF 数据1",
      "type": "n8n-nodes-base.code",
      "position": [
        992,
        3040
      ],
      "parameters": {
        "jsCode": "// Get the first item from the input array.\nconst firstItem = items[0];\n\n// Create a new object that has a single key: \"data\".\n// The value of \"data\" will be the entire json object from the input.\n// This gathers all fields (First Name, Last Name, Age, etc.) dynamically.\nconst result = {\n  data: firstItem.json\n};\n\n// Return the newly structured object.\n// It will be outputted as a single item with a 'json' property\n// containing the 'data' object.\nreturn result;"
      },
      "typeVersion": 2
    },
    {
      "id": "f190d5be-6691-4e5f-a575-3f191945676f",
      "name": "获取错误消息1",
      "type": "n8n-nodes-base.set",
      "position": [
        656,
        1328
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d8935452-fe20-469d-a68d-1aad056cb8dd",
              "name": "message",
              "type": "string",
              "value": "=It was not possible to process the file.File type not supported."
            },
            {
              "id": "38ba2498-2141-4a04-a22a-64563fe2ee6f",
              "name": "chat_id",
              "type": "string",
              "value": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e08164f0-1d78-4252-a988-51710f9be936",
      "name": "文本?",
      "type": "n8n-nodes-base.if",
      "position": [
        992,
        2304
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "333a436f-c087-4250-a181-40657874959b",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.text }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "3b3c4328-17d1-4d81-8eea-040daf8a7589",
      "name": "分析文档",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        992,
        2448
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-pro",
          "cachedResultName": "models/gemini-2.5-pro"
        },
        "options": {},
        "resource": "document",
        "inputType": "binary"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "to92mdfNe3L6sBae",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9c7b9703-f8d3-4de2-9dda-16771848a331",
      "name": "标准化 PDF(AI)",
      "type": "n8n-nodes-base.set",
      "position": [
        1152,
        2448
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "24b93984-e305-4c11-a856-5fa0bfaaaa79",
              "name": "data",
              "type": "string",
              "value": "={{ $json.content.parts[0].text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e61850a8-4cba-4bef-8173-742977466b6c",
      "name": "合并",
      "type": "n8n-nodes-base.merge",
      "position": [
        816,
        2448
      ],
      "parameters": {
        "mode": "chooseBranch",
        "useDataOfInput": 2
      },
      "typeVersion": 3.2
    },
    {
      "id": "19562ab5-8f0d-4c20-81ae-77d2f44599c4",
      "name": "MarkdownV2",
      "type": "n8n-nodes-base.code",
      "position": [
        3056,
        224
      ],
      "parameters": {
        "jsCode": "/**\n * MarkdownV2-safe formatter + auto-chunker for Telegram (n8n Code node)\n * --------------------------------------------------------------------\n * - Allows: *bold*, _italic_, ||spoiler||, [label](url)\n * - Escapes everything else for Telegram MarkdownV2\n * - Validates/normalizes URLs\n * - Converts \"# Heading\" lines to bold titles\n * - Splits long messages into <= 4096-char chunks (uses a 4000-char budget)\n * - Outputs one item per chunk so the Telegram node sends all parts\n *\n * Recommended: Run this node in \"Run Once for All Items\".\n */\n\nconst MAX_TELEGRAM = 4096;\nconst SAFE_BUDGET = 4000; // small margin to avoid edge overflows\n\n// ============ MarkdownV2 helpers ============\nfunction escapeMarkdownV2(text) {\n  if (!text) return '';\n  return String(text).replace(/([\\\\_*[\\]()~`>#+\\-=|{}.!])/g, '\\\\$1');\n}\n\nfunction escapeForUrl(url) {\n  return String(url).replace(/[)\\\\]/g, '\\\\$&');\n}\n\nfunction normalizeAndValidateUrl(url) {\n  let raw = String(url || '').trim();\n  try {\n    const u = new URL(raw);\n    return u.toString();\n  } catch {}\n  // Try https:// for bare domains\n  const domainLike = /^[a-z0-9.-]+\\.[a-z]{2,}([/:?#].*)?$/i.test(raw);\n  if (domainLike) {\n    try {\n      const u2 = new URL('https://' + raw);\n      return u2.toString();\n    } catch {}\n  }\n  return null;\n}\n\nfunction normalizeHeadings(text) {\n  // Turn \"# Title\" → \"*Title*\"\n  return text.replace(/^(#{1,6})\\s+(.*)$/gm, (m, hashes, title) => `*${title.trim()}*`);\n}\n\nfunction normalizeCommonMd(text) {\n  return String(text)\n    .replace(/\\*\\*([\\s\\S]*?)\\*\\*/g, '*$1*') // **bold** → *bold*\n    .replace(/__([\\s\\S]*?)__/g, '_$1_');    // __italic__ → _italic_\n}\n\n/**\n * Convert incoming text to Telegram-safe MarkdownV2.\n */\nfunction processMarkdownV2Safe(inputText) {\n  if (!inputText) return '';\n\n  let text = normalizeCommonMd(String(inputText));\n  text = normalizeHeadings(text);\n\n  const placeholders = { links: [], bolds: [], italics: [], spoilers: [] };\n\n  // Links: keep safe via placeholders during escaping\n  text = text.replace(/\\[([^\\]\\n]+)\\]\\(([^)]+)\\)/g, (m, label, url) => {\n    const normalizedUrl = normalizeAndValidateUrl(url);\n    if (!normalizedUrl) return escapeMarkdownV2(label);\n    const idx = placeholders.links.length;\n    const ph = `⟬L${idx}⟭`;\n    const safeLabel = escapeMarkdownV2(label);\n    const safeUrl = escapeForUrl(normalizedUrl);\n    placeholders.links.push(`[${safeLabel}](${safeUrl})`);\n    return ph;\n  });\n\n  // Bold\n  text = text.replace(/\\*([\\s\\S]+?)\\*/g, (m, inner) => {\n    const idx = placeholders.bolds.length;\n    const ph = `⟬B${idx}⟭`;\n    placeholders.bolds.push(`*${escapeMarkdownV2(inner)}*`);\n    return ph;\n  });\n\n  // Italic\n  text = text.replace(/_([\\s\\S]+?)_/g, (m, inner) => {\n    const idx = placeholders.italics.length;\n    const ph = `⟬I${idx}⟭`;\n    placeholders.italics.push(`_${escapeMarkdownV2(inner)}_`);\n    return ph;\n  });\n\n  // Spoilers\n  text = text.replace(/\\|\\|([\\s\\S]+?)\\|\\|/g, (m, inner) => {\n    const idx = placeholders.spoilers.length;\n    const ph = `⟬S${idx}⟭`;\n    placeholders.spoilers.push(`||${escapeMarkdownV2(inner)}||`);\n    return ph;\n  });\n\n  // Escape everything else\n  text = escapeMarkdownV2(text);\n\n  // Restore placeholders\n  placeholders.links.forEach((md, i) => { text = text.replace(`⟬L${i}⟭`, md); });\n  placeholders.bolds.forEach((md, i) => { text = text.replace(`⟬B${i}⟭`, md); });\n  placeholders.italics.forEach((md, i) => { text = text.replace(`⟬I${i}⟭`, md); });\n  placeholders.spoilers.forEach((md, i) => { text = text.replace(`⟬S${i}⟭`, md); });\n\n  return text;\n}\n\n// ============ Chunking helpers ============\n/**\n * Split text into Telegram-safe chunks <= maxLen.\n * Prefers paragraph boundaries, then sentence boundaries, then words.\n * Falls back to hard cuts only when unavoidable (e.g., extremely long URL).\n */\nfunction chunkForTelegram(text, maxLen = SAFE_BUDGET) {\n  if (!text || text.length <= maxLen) return [text || ''];\n\n  const parts = [];\n  let buffer = '';\n\n  const flush = () => {\n    if (buffer) {\n      parts.push(buffer);\n      buffer = '';\n    }\n  };\n\n  // 1) Paragraph-level packing\n  const paragraphs = text.split(/\\n{2,}/);\n  for (const pRaw of paragraphs) {\n    const p = pRaw; // keep paragraph as-is\n    const candidate = buffer ? buffer + '\\n\\n' + p : p;\n    if (candidate.length <= maxLen) {\n      buffer = candidate;\n      continue;\n    }\n    if (p.length <= maxLen) {\n      flush();\n      buffer = p;\n      continue;\n    }\n\n    // 2) Sentence-level packing (paragraph is still too big)\n    flush();\n    const sentences = p.split(/(?<=[.!?…])\\s+(?=[^\\s])/u);\n    let sBuf = '';\n    for (const s of sentences) {\n      const sCandidate = sBuf ? sBuf + ' ' + s : s;\n      if (sCandidate.length <= maxLen) {\n        sBuf = sCandidate;\n        continue;\n      }\n      if (s.length <= maxLen) {\n        if (sBuf) parts.push(sBuf);\n        sBuf = s;\n        continue;\n      }\n\n      // 3) Word-level packing (sentence is still too big)\n      if (sBuf) { parts.push(sBuf); sBuf = ''; }\n      let wBuf = '';\n      const words = s.split(/\\s+/);\n      for (const w of words) {\n        const wCandidate = wBuf ? wBuf + ' ' + w : w;\n        if (wCandidate.length <= maxLen) {\n          wBuf = wCandidate;\n          continue;\n        }\n        if (w.length <= maxLen) {\n          if (wBuf) parts.push(wBuf);\n          wBuf = w;\n          continue;\n        }\n        // 4) Hard split (extremely long token, e.g., massive URL)\n        if (wBuf) { parts.push(wBuf); wBuf = ''; }\n        const re = new RegExp(`.{1,${maxLen}}`, 'g');\n        const hardPieces = w.match(re) || [];\n        parts.push(...hardPieces);\n      }\n      if (wBuf) parts.push(wBuf);\n    }\n    if (sBuf) parts.push(sBuf);\n  }\n  if (buffer) parts.push(buffer);\n\n  // Final safety pass: trim chunks that might still exceed MAX_TELEGRAM\n  return parts.flatMap(part => {\n    if (part.length <= MAX_TELEGRAM) return [part];\n    const re = new RegExp(`.{1,${SAFE_BUDGET}}`, 'g');\n    return part.match(re) || [];\n  });\n}\n\n// ============ Main ============\nconst inputItems = $input.all();\nconst out = [];\n\nfor (const item of inputItems) {\n  const j = item.json || {};\n  const raw =\n    j.message ?? j.output ?? j.text ?? j.content ?? '';\n\n  const formatted = processMarkdownV2Safe(raw);\n  const chunks = chunkForTelegram(formatted, SAFE_BUDGET);\n\n  chunks.forEach((chunk, idx) => {\n    out.push({\n      json: {\n        ...j,\n        message: chunk,\n        message_part_index: idx + 1,\n        message_parts_total: chunks.length,\n      },\n      binary: item.binary,\n    });\n  });\n}\n\nreturn out;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "a4472248-e516-4645-95a6-4194fe4c1031",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        32,
        1568
      ],
      "parameters": {
        "color": 3,
        "width": 1728,
        "height": 1872,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "c1275528-8969-4c2e-99b8-46963fa75287",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2656,
        128
      ],
      "parameters": {
        "color": 6,
        "width": 816,
        "height": 496,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "06010307-cf02-4e59-a5c7-ac606027d5b4",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        32,
        -80
      ],
      "parameters": {
        "color": 7,
        "width": 576,
        "height": 240,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "88867952-99ff-4251-bec8-e8ef3aeef299",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        32,
        176
      ],
      "parameters": {
        "color": 4,
        "width": 1360,
        "height": 208,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "ea3678cd-a311-43fe-9c49-879aeba383de",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        32,
        432
      ],
      "parameters": {
        "color": 5,
        "width": 1504,
        "height": 1104,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "7a22b89a-1830-4312-9f8d-c589ca14583e",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1712,
        720
      ],
      "parameters": {
        "width": 1104,
        "height": 752,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "48637749-6c8f-49cf-b7d6-d10e73cf2b26",
      "name": "Postgres Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        2848,
        432
      ],
      "parameters": {
        "tableName": "chat_histories",
        "sessionKey": "={{ $json.chat_id }}",
        "sessionIdType": "customKey"
      },
      "credentials": {
        "postgres": {
          "id": "eQR2NFRag48wov9g",
          "name": "Postgres account"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "cf6e0d26-583a-4f3b-9288-1d613b56a895",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -608,
        -480
      ],
      "parameters": {
        "color": 7,
        "width": 608,
        "height": 528,
        "content": "### 灰色部分 – 数据库设置"
      },
      "typeVersion": 1
    },
    {
      "id": "8893e203-deb9-427c-97f0-2f0ddfdc2c76",
      "name": "便签7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -624,
        208
      ],
      "parameters": {
        "color": 4,
        "width": 608,
        "height": 384,
        "content": "### 绿色部分 – 媒体队列触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "2ddfd90a-47bd-416e-941e-dc3d85d58aa6",
      "name": "便签8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -608,
        800
      ],
      "parameters": {
        "color": 5,
        "width": 608,
        "height": 528,
        "content": "### 蓝色部分 – Telegram 触发器与消息类型处理"
      },
      "typeVersion": 1
    },
    {
      "id": "a2cc1113-08e9-4164-a8ee-274a41680cd4",
      "name": "### 替换 Airtable 连接",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -608,
        1568
      ],
      "parameters": {
        "color": 3,
        "width": 608,
        "height": 496,
        "content": "### 红色部分 – 文档处理"
      },
      "typeVersion": 1
    },
    {
      "id": "68b608aa-77ac-4b38-8d9a-305bc78f6c9d",
      "name": "便签10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1968,
        1504
      ],
      "parameters": {
        "width": 608,
        "height": 576,
        "content": "### 黄色部分 – 文件与字幕处理"
      },
      "typeVersion": 1
    },
    {
      "id": "55b87005-349d-496a-beec-f110b010c733",
      "name": "便签11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2880,
        656
      ],
      "parameters": {
        "color": 6,
        "width": 608,
        "height": 496,
        "content": "### 紫色部分 – AI 代理与输出格式化"
      },
      "typeVersion": 1
    },
    {
      "id": "35c32d3e-1627-48ab-90e2-9814606e5033",
      "name": "获取消息(多个文件)",
      "type": "n8n-nodes-base.set",
      "position": [
        992,
        224
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "b9c92d3b-db05-4d27-968e-3fc8b27d4d2b",
              "name": "message",
              "type": "string",
              "value": "={{ $json.unifiedMessage }}"
            },
            {
              "id": "812d7730-117c-4d1f-b18e-8c3561e86c5e",
              "name": "chat_id",
              "type": "number",
              "value": "={{ $('get_chat_id').first().json.chat_id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "9184a63a-8528-40db-a0ab-f1763528d5a0",
      "name": "便签12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        32,
        -368
      ],
      "parameters": {
        "color": 2,
        "width": 448,
        "height": 176,
        "content": "**🙏 特别感谢**"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Insert media_queue (Trigger)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Analyze document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text?": {
      "main": [
        [
          {
            "node": "Normalize PDF",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Download CSV",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download HTML",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download ICS",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download JSON",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download ODS",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download PDF",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download RTF",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download TEXT FILE",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download XML",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download XLSX",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "get_error_message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fix mime": {
      "main": [
        [
          {
            "node": "Analyze voice message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent1": {
      "main": [
        [
          {
            "node": "MarkdownV2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Normalize CSV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fix mime1": {
      "main": [
        [
          {
            "node": "Analyze video note",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fix mime4": {
      "main": [
        [
          {
            "node": "Analyze video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fix mime5": {
      "main": [
        [
          {
            "node": "Analyze image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fix mime6": {
      "main": [
        [
          {
            "node": "Analyze audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Typing…": {
      "main": [
        []
      ]
    },
    "Captions?1": {
      "main": [
        [
          {
            "node": "Media_group?2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Media_group?3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MarkdownV2": {
      "main": [
        [
          {
            "node": "Send a text message1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_chat_id": {
      "main": [
        [
          {
            "node": "Wait for all the files",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download CSV": {
      "main": [
        [
          {
            "node": "Extract from CSV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download ICS": {
      "main": [
        [
          {
            "node": "Extract from ICS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download ODS": {
      "main": [
        [
          {
            "node": "Extract from ODS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download PDF": {
      "main": [
        [
          {
            "node": "Extract from PDF",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Download RTF": {
      "main": [
        [
          {
            "node": "Extract from RTF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download XML": {
      "main": [
        [
          {
            "node": "Extract from XML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get ODS data": {
      "main": [
        [
          {
            "node": "Normalize ODS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get RTF data": {
      "main": [
        [
          {
            "node": "Normalize RTF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze audio": {
      "main": [
        [
          {
            "node": "get_message (Media  message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze image": {
      "main": [
        [
          {
            "node": "get_message (Media  message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze video": {
      "main": [
        [
          {
            "node": "get_message (Media  message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download HTML": {
      "main": [
        [
          {
            "node": "HTML Extract Generic1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download JSON": {
      "main": [
        [
          {
            "node": "Extract from JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download XLSX": {
      "main": [
        [
          {
            "node": "Extract from XLSX",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get RTF data1": {
      "main": [
        [
          {
            "node": "Normalize XLSX",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get_only_file": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Media_group?2": {
      "main": [
        [
          {
            "node": "Insert documents in media_group",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get_file_and_captions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Media_group?3": {
      "main": [
        [
          {
            "node": "Insert documents in media_group1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get_only_file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize CSV": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize ICS": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize ODS": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize PDF": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize RTF": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize XML": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download AUDIO": {
      "main": [
        [
          {
            "node": "Fix mime6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download IMAGE": {
      "main": [
        [
          {
            "node": "Fix mime5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download VIDEO": {
      "main": [
        [
          {
            "node": "Fix mime4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize HTML": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize JSON": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize XLSX": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze document": {
      "main": [
        [
          {
            "node": "Normalize PDF (AI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from CSV": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from ICS": {
      "main": [
        [
          {
            "node": "Normalize ICS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from ODS": {
      "main": [
        [
          {
            "node": "Get ODS data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from PDF": {
      "main": [
        [
          {
            "node": "Text?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from RTF": {
      "main": [
        [
          {
            "node": "Get RTF data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from XML": {
      "main": [
        [
          {
            "node": "Normalize XML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Typing…",
            "type": "main",
            "index": 0
          },
          {
            "node": "Input Message Router1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Normalize text file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from JSON": {
      "main": [
        [
          {
            "node": "Normalize JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from XLSX": {
      "main": [
        [
          {
            "node": "Get RTF data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_error_message": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "unified_variables": {
      "main": [
        [
          {
            "node": "Get_message (multiple files)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze video note": {
      "main": [
        [
          {
            "node": "get_message (Audio/Video message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download TEXT FILE": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize PDF (AI)": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_error_message1": {
      "main": [
        [
          {
            "node": "get_message (Media  message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_message (text)": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download VIDEO NOTE": {
      "main": [
        [
          {
            "node": "Fix mime1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Media_queue Trigger": {
      "main": [
        [
          {
            "node": "get_chat_id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize text file": {
      "main": [
        [
          {
            "node": "get_message (File message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Analyze voice message": {
      "main": [
        [
          {
            "node": "get_message (Audio/Video message)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get_file_and_captions": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Extract Generic1": {
      "main": [
        [
          {
            "node": "Normalize HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Input Message Router1": {
      "main": [
        [
          {
            "node": "get_message (text)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download Voice Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download VIDEO NOTE",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download IMAGE",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download AUDIO",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Download VIDEO",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Group Similar Documents",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "get_error_message1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Voice Message": {
      "main": [
        [
          {
            "node": "Fix mime",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for all the files": {
      "main": [
        [
          {
            "node": "Get all files from group_id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Group Similar Documents": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "get_message (File message)": {
      "main": [
        [
          {
            "node": "Captions?1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get all files from group_id": {
      "main": [
        [
          {
            "node": "unified_variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get_message (multiple files)": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_message (Media  message)": {
      "main": [
        [
          {
            "node": "Captions?1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert documents in media_group": {
      "main": [
        [
          {
            "node": "Insert media_queue with captions (Trigger)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert documents in media_group1": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_message (Audio/Video message)": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": " Create Tables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 客服机器人, 多模态 AI

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量100
分类2
节点类型19
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

外部链接
在 n8n.io 查看

分享此工作流