Telegram富文本输出
高级
这是一个Other, Building Blocks, AI领域的自动化工作流,包含 19 个节点。主要使用 If, Code, Limit, Switch, SplitOut 等节点,结合人工智能技术实现智能自动化。 将LLM输出转换为富文本Telegram消息——自动媒体处理和智能分块
前置要求
- •Telegram Bot Token
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "6bKCRgltEQMKck0S",
"meta": {
"instanceId": "90ee57f28a1370a05d29c652ea0aff6dc92be284367a87ea83ea3eac2120d7eb"
},
"name": "TelegramRichOutput",
"tags": [],
"nodes": [
{
"id": "a25428d1-d34c-42f4-9a1a-713bef6dc1e9",
"name": "Send back an image",
"type": "n8n-nodes-base.telegram",
"position": [
-480,
720
],
"webhookId": "bc86ba8e-2a9b-4f48-acdb-0550c95494ef",
"parameters": {
"file": "={{ $json.url }}",
"chatId": "={{ $('When Executed by Another Workflow').item.json.chatId }}",
"operation": "sendPhoto",
"additionalFields": {
"parse_mode": "HTML"
}
},
"credentials": {
"telegramApi": {
"id": "FyjiLVRg007vuCnK",
"name": "Telegram account (SCP)"
}
},
"typeVersion": 1.1
},
{
"id": "052643fa-6319-43f3-a052-40ed0e255238",
"name": "Send back an audio",
"type": "n8n-nodes-base.telegram",
"position": [
-260,
720
],
"webhookId": "bc86ba8e-2a9b-4f48-acdb-0550c95494ef",
"parameters": {
"file": "={{ $json.url }}",
"chatId": "={{ $('When Executed by Another Workflow').item.json.chatId }}",
"operation": "sendAudio",
"additionalFields": {
"parse_mode": "HTML"
}
},
"credentials": {
"telegramApi": {
"id": "FyjiLVRg007vuCnK",
"name": "Telegram account (SCP)"
}
},
"typeVersion": 1.1
},
{
"id": "73dfb105-5ffe-4f8a-b96e-b0b556d73956",
"name": "Send back a video",
"type": "n8n-nodes-base.telegram",
"position": [
-60,
720
],
"webhookId": "bc86ba8e-2a9b-4f48-acdb-0550c95494ef",
"parameters": {
"file": "={{ $json.url }}",
"chatId": "={{ $('When Executed by Another Workflow').item.json.chatId }}",
"operation": "sendVideo",
"additionalFields": {
"parse_mode": "HTML"
}
},
"credentials": {
"telegramApi": {
"id": "FyjiLVRg007vuCnK",
"name": "Telegram account (SCP)"
}
},
"typeVersion": 1.1
},
{
"id": "e715f898-1bca-4e4e-a463-f30815664766",
"name": "Send Text",
"type": "n8n-nodes-base.telegram",
"position": [
140,
220
],
"webhookId": "c5c03eae-b148-4358-8792-d03d55bd0b48",
"parameters": {
"text": "={{ $('When Executed by Another Workflow').item.json.output }}",
"chatId": "={{ $('When Executed by Another Workflow').item.json.chatId }}",
"additionalFields": {
"parse_mode": "HTML",
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"id": "FyjiLVRg007vuCnK",
"name": "Telegram account (SCP)"
}
},
"typeVersion": 1.2
},
{
"id": "38f15fa8-f9a2-469b-9f30-fed46296bf1f",
"name": "If text too long",
"type": "n8n-nodes-base.if",
"position": [
-140,
60
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "a6365c72-9e4c-4b19-b725-9965fdb81e21",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $('When Executed by Another Workflow').item.json.output.length > 1000 }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "286d11cb-f94a-4143-8a27-34b5f4e14192",
"name": "当由另一个工作流执行时",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
-960,
-100
],
"parameters": {
"workflowInputs": {
"values": [
{
"name": "chatId",
"type": "number"
},
{
"name": "output"
}
]
}
},
"typeVersion": 1.1
},
{
"id": "dab1fb0c-970e-43f7-a335-c48639edaabe",
"name": "Loop Over Links",
"type": "n8n-nodes-base.splitInBatches",
"position": [
-580,
220
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "a1f73d92-b61e-41fa-a0c7-50e72078e096",
"name": "If no links",
"type": "n8n-nodes-base.if",
"position": [
-520,
-100
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "332d2f85-5f44-4d8b-a5c0-03bda9c3976d",
"operator": {
"type": "array",
"operation": "empty",
"singleValue": true
},
"leftValue": "={{ $json.files }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "bd57fe5e-940b-46f9-a76f-ba4d6bae5c7c",
"name": "Split Out the Links",
"type": "n8n-nodes-base.splitOut",
"position": [
-800,
220
],
"parameters": {
"options": {},
"fieldToSplitOut": "files"
},
"typeVersion": 1
},
{
"id": "8e14c1e6-ece0-4310-97c2-829a37074706",
"name": "Split large text by chunks",
"type": "n8n-nodes-base.code",
"position": [
140,
-120
],
"parameters": {
"jsCode": "const inputText = $('When Executed by Another Workflow').first().json.output || \"\";\nconst lines = inputText.split(\"\\n\");\n\nlet chunks = [];\nlet currentChunk = \"\";\n\nfor (const line of lines) {\n // Check if adding the line would exceed the 1000 character limit\n if ((currentChunk + line + \"\\n\").length > 1000) {\n // Push current chunk if not empty\n if (currentChunk) chunks.push(currentChunk.trim());\n // Start new chunk with current line\n currentChunk = line + \"\\n\";\n } else {\n // Add line to current chunk\n currentChunk += line + \"\\n\";\n }\n}\n\n// Push the final chunk if there’s remaining content\nif (currentChunk) chunks.push(currentChunk.trim());\n\n// Return each chunk as a separate item\nreturn { output:chunks.map(chunk => ({ chunk } ))};"
},
"typeVersion": 2
},
{
"id": "b08e8087-f155-4747-a5d8-8c9bb5511777",
"name": "Split Out the Chunks",
"type": "n8n-nodes-base.splitOut",
"position": [
360,
-120
],
"parameters": {
"options": {},
"fieldToSplitOut": "output"
},
"typeVersion": 1
},
{
"id": "94b015d0-a1b7-4e13-973a-5a25fe88c209",
"name": "Loop Over Text Chunks",
"type": "n8n-nodes-base.splitInBatches",
"position": [
560,
-120
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "51f2598e-4958-4139-ab00-3836b7a52ed5",
"name": "Send Text Chunk",
"type": "n8n-nodes-base.telegram",
"position": [
800,
-120
],
"webhookId": "c5c03eae-b148-4358-8792-d03d55bd0b48",
"parameters": {
"text": "={{ $json.chunk }}",
"chatId": "={{ $('When Executed by Another Workflow').item.json.chatId }}",
"additionalFields": {
"parse_mode": "HTML",
"appendAttribution": false
}
},
"credentials": {
"telegramApi": {
"id": "FyjiLVRg007vuCnK",
"name": "Telegram account (SCP)"
}
},
"typeVersion": 1.2
},
{
"id": "d7baaaff-a918-487d-970a-d2ef498504b3",
"name": "限制",
"type": "n8n-nodes-base.limit",
"position": [
-380,
220
],
"parameters": {},
"typeVersion": 1
},
{
"id": "5f724698-027f-4e88-8329-1abd00f8e6c7",
"name": "Extract Links",
"type": "n8n-nodes-base.code",
"position": [
-740,
-100
],
"parameters": {
"jsCode": "// free-text input\nconst text = $input.first().json.output ?? \"\";\n\n/* media extensions grouped by type */\nconst IMG = ['jpg','jpeg','png','gif','bmp','webp','tif','tiff'];\nconst AUD = ['mp3','wav','m4a','flac','ogg','aac','opus'];\nconst VID = ['mp4','mov','mkv','webm','avi','mpeg','mpg'];\n\n/* one regex that grabs any media URL (no lazy quantifier, so the whole link is kept) */\nconst re = /(https?:\\/\\/[^\\s\"'<>]+\\.(?<ext>[A-Za-z0-9]{2,5}))(?:\\?[^\\s\"'<>]*)?/gi;\n\nconst seen = new Set();\nconst files = [];\n\nfor (const m of text.matchAll(re)) {\n const url = m[1];\n if (seen.has(url)) continue; // de-dupe\n seen.add(url);\n\n const ext = (m.groups.ext || '').toLowerCase();\n\n let type = 'other';\n if (IMG.includes(ext)) type = 'image';\n else if (AUD.includes(ext)) type = 'audio';\n else if (VID.includes(ext)) type = 'video';\n\n files.push({ url, type });\n}\n\nreturn [{ json: { files } }];"
},
"typeVersion": 2
},
{
"id": "45e41a01-68a2-4b64-8830-e05916170a97",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-560,
420
],
"parameters": {
"color": 5,
"width": 660,
"height": 480,
"content": "## Send links\nSend links to chat as separate messages \nwith appropriate type (image, audio, video)"
},
"typeVersion": 1
},
{
"id": "bbeb6619-4a48-40f5-be75-e99e0c53462e",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
80,
-220
],
"parameters": {
"color": 6,
"width": 900,
"height": 300,
"content": "## Send a long message\nSeparate long message by chunks and send them one by one"
},
"typeVersion": 1
},
{
"id": "4dbf96c8-fb30-4c22-8fc9-c551cb9893c6",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
80,
120
],
"parameters": {
"width": 300,
"height": 260,
"content": "## Send a short message\nDeliver a short message (default flow)"
},
"typeVersion": 1
},
{
"id": "e13e63e9-331e-458b-8933-4ec608eab00a",
"name": "Check Link Type",
"type": "n8n-nodes-base.switch",
"position": [
-60,
480
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "image",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "10ec4538-b5cc-4562-954a-fc4ada846d78",
"operator": {
"type": "string",
"operation": "endsWith"
},
"leftValue": "={{ $json.type }}",
"rightValue": "image"
}
]
},
"renameOutput": true
},
{
"outputKey": "audio",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "9e0cee56-b281-4d01-9196-eb6495be9641",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.type }}",
"rightValue": "audio"
}
]
},
"renameOutput": true
},
{
"outputKey": "video",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "007d1c92-0cd0-4dd6-ab9b-8c869e20797d",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.type }}",
"rightValue": "video"
}
]
},
"renameOutput": true
}
]
},
"options": {}
},
"typeVersion": 3.2
}
],
"active": false,
"pinData": {
"Split Out the Chunks": [
{
"json": {
"chunk": "Here are the image prompts we have so far:\n\n1. A pile of ancient, golden and silver coins scattered on a worn wooden table. The coins have varied designs with ornate patterns and symbols, and reflect light with an unnatural shimmer. A dim light from an overhead lamp highlights their metallic surface against the dark surroundings of what appears to be an old study room with bookshelves in the background.\n\n2. Ancient golden and silver coins suspended in mid-air, forming a slowly rotating spiral pattern about 2 feet above a worn wooden table. Various coins spin on their edges while others twist and turn in different directions. A person's silhouette is visible in the background, approaching cautiously. The room appears colder with a slight blue tint, and tiny ice crystals have formed on the edges of the table near the floating coins."
}
},
{
"json": {
"chunk": "3. A researcher with a pained expression, looking pale and disoriented, stands beside a wooden table. Their hand is stretched out toward floating golden and silver coins, which are now partially transparent and fading at the edges. Some coins appear to be dissolving into tiny particles of light. Frost has formed on the researcher's outstretched fingers, and their breath is visible in the now freezing air of the study room.\n\n4. An empty wooden table where the coins once were, with only a few small patches of frost remaining as evidence. The researcher has stepped back, looking exhausted and confused. Their hand that reached for the coins appears slightly translucent, as if it partially disappeared with the coins. Scientific instruments scattered around the table show unusual readings with their displays glitching. The temperature in the room is returning to normal, shown by the frost slowly melting and the researcher's breath no longer visible."
}
},
{
"json": {
"chunk": "5. A secure containment chamber with reinforced glass walls displaying the SCP 45 coins back in their dormant state on a pedestal. Several monitoring devices surround the pedestal, including thermal cameras and motion sensors with digital readouts showing extremely low temperatures. A researcher in protective gear stands at a safe distance, taking notes on a tablet. Warning signs on the walls indicate \"NO PHYSICAL CONTACT\" and \"TEMPORAL ANOMALY.\" The lighting is clinical and stark, highlighting the controlled environment in contrast to the earlier study room."
}
},
{
"json": {
"chunk": "6. A classified SCP Foundation document page with aged photographs and handwritten notes about SCP 45's historical appearances. The document shows sketches of the coins from different time periods and locations, with red ink highlighting recurring witnesses who reported missing time. A black and white photograph from the 1920s shows identical coins in a museum display, with a blurred figure reaching toward them. The document is stamped \"LEVEL 4 CLEARANCE REQUIRED\" and includes marginalia noting correlation between coin appearances and local temporal anomalies. A coffee cup ring stains one corner of the document, giving it an authentic feel."
}
},
{
"json": {
"chunk": "7. An archaeological excavation site inside an ancient temple vault. Researchers in protective gear carefully work around a stone altar where the SCP 45 coins are embedded in a circular pattern. Specialized equipment with SCP Foundation logos monitors the area, with readings showing temporal distortions. One researcher points to strange hieroglyphs on the wall depicting people with missing limbs reaching for circular objects. Small temporal bubbles, visible as distortions in the air, surround parts of the coins. Light from headlamps creates dramatic shadows across the dusty chamber, highlighting the tense, cautious expressions of the recovery team members."
}
},
{
"json": {
"chunk": "8. A time-lapse montage showing a research subject affected by SCP 45. The image is split into four quadrants showing the same person at different stages: initially normal, then with a translucent arm, then with half their body faded, and finally just a ghost-like outline barely visible. Each quadrant shows a digital clock in the background with dramatically different times despite being taken minutes apart. The final quadrant shows researchers in hazmat suits responding to the emergency, their movements captured as motion blurs around the fading subject."
}
}
],
"When Executed by Another Workflow": [
{
"json": {
"chatId": 775716734,
"output": "I've generated a 15-second narration about SCP-096 and created the audio file. The narration is:\n\n\"There is a creature called SCP-096 that is very thin and pale. If someone sees its face, even by accident, it becomes extremely upset and will chase them anywhere to keep its face hidden.\"\n\nI've saved the narration text and audio to your project. The audio file has been generated and is available at:\nhttps://tktuvgvuoreixlzuubfz.supabase.co/storage/v1/object/hht/2025-05-14_044617_voice.mp3\n\nThe actual audio length is 23 seconds.\n\nWould you like me to proceed with creating image prompts for this SCP-096 video?"
}
}
]
},
"settings": {
"executionOrder": "v1"
},
"versionId": "1901c6ab-e8db-40ee-81a2-6dd7967d2dd8",
"connections": {
"Limit": {
"main": [
[
{
"node": "If text too long",
"type": "main",
"index": 0
}
]
]
},
"If no links": {
"main": [
[
{
"node": "If text too long",
"type": "main",
"index": 0
}
],
[
{
"node": "Split Out the Links",
"type": "main",
"index": 0
}
]
]
},
"Extract Links": {
"main": [
[
{
"node": "If no links",
"type": "main",
"index": 0
}
]
]
},
"Check Link Type": {
"main": [
[
{
"node": "Send back an image",
"type": "main",
"index": 0
}
],
[
{
"node": "Send back an audio",
"type": "main",
"index": 0
}
],
[
{
"node": "Send back a video",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Links": {
"main": [
[
{
"node": "Limit",
"type": "main",
"index": 0
}
],
[
{
"node": "Check Link Type",
"type": "main",
"index": 0
}
]
]
},
"Send Text Chunk": {
"main": [
[
{
"node": "Loop Over Text Chunks",
"type": "main",
"index": 0
}
]
]
},
"If text too long": {
"main": [
[
{
"node": "Split large text by chunks",
"type": "main",
"index": 0
}
],
[
{
"node": "Send Text",
"type": "main",
"index": 0
}
]
]
},
"Send back a video": {
"main": [
[
{
"node": "Loop Over Links",
"type": "main",
"index": 0
}
]
]
},
"Send back an audio": {
"main": [
[
{
"node": "Loop Over Links",
"type": "main",
"index": 0
}
]
]
},
"Send back an image": {
"main": [
[
{
"node": "Loop Over Links",
"type": "main",
"index": 0
}
]
]
},
"Split Out the Links": {
"main": [
[
{
"node": "Loop Over Links",
"type": "main",
"index": 0
}
]
]
},
"Split Out the Chunks": {
"main": [
[
{
"node": "Loop Over Text Chunks",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Text Chunks": {
"main": [
[],
[
{
"node": "Send Text Chunk",
"type": "main",
"index": 0
}
]
]
},
"Split large text by chunks": {
"main": [
[
{
"node": "Split Out the Chunks",
"type": "main",
"index": 0
}
]
]
},
"When Executed by Another Workflow": {
"main": [
[
{
"node": "Extract Links",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 其他, 构建模块, 人工智能
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
使用AI汇总Slack频道活动生成周报
使用AI汇总Slack频道活动生成周报
If
Set
Code
+13
47 节点Jimleuk
其他
[模板] AI宠物店 v8
🐶 AI宠物店助手 - 集成GPT-4o、Google日历和WhatsApp/Instagram/Facebook
If
N8n
Set
+38
244 节点Amanda Benks
销售
AI 代理餐厅 [模板]
🤖 WhatsApp、Instagram 和 Messenger 的 AI 餐厅助手
If
N8n
Set
+37
239 节点Amanda Benks
其他
个人 - 申请 TRM
通过 Telegram 机器人和 AI 日期识别获取哥伦比亚比索兑美元汇率
If
Set
Code
+16
31 节点Juan Sanchez
财务
(Duc)深度研究市场模板
集成PerplexityAI研究和OpenAI内容的多层级WordPress博客生成器
If
Set
Xml
+28
132 节点Daniel Ng
人工智能
⚡AI驱动的YouTube播放列表和视频摘要与分析v2
AI YouTube播放列表与视频分析聊天机器人
If
Set
Code
+20
72 节点dmr
其他