智能 Telegram 机器人:GPT-4V-NVIDIA Vila 文本↔图像转换,邮件发送结果

中级

这是一个Content Creation、Multimodal AI领域的自动化工作流,包含 13 个节点。主要使用 Code、Gmail、Merge、Switch、Telegram 等节点。 Telegram 机器人:使用 GPT-4o-Mini/NVIDIA Vila 分析图像,Stable Diffusion 3 生成图像

前置要求
  • Google 账号和 Gmail API 凭证
  • Telegram Bot Token
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "zeql9BTOvMW9EP5c",
  "meta": {
    "instanceId": "b91e510ebae4127f953fd2f5f8d40d58ca1e71c746d4500c12ae86aad04c1502",
    "templateCredsSetupCompleted": true
  },
  "name": "智能 Telegram 机器人:通过 GPT-4V-NVIDIA Vila 实现文本↔图像转换,邮件发送结果",
  "tags": [],
  "nodes": [
    {
      "id": "1e0660c6-9518-49d7-aa32-4228d94b8338",
      "name": "📱 Telegram 触发器",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -832,
        -80
      ],
      "webhookId": "60b5e1db-88b3-4b16-a706-2f22f0ec1f6c",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "mYO3O1232v1KxESH",
          "name": "Telegram account 2"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "69846c8f-72b2-45e2-b32b-6b53716ee5f7",
      "name": "📋 提取消息数据",
      "type": "n8n-nodes-base.code",
      "position": [
        -656,
        -80
      ],
      "parameters": {
        "jsCode": "// Extract and prepare message data\nconst item = $input.item.json;\nconst messageData = {\n  text: item.message?.text || item.message?.caption || '',\n  from: item.message?.from?.username || 'unknown',\n  chatId: item.message?.chat?.id,\n  messageId: item.message?.message_id,\n  timestamp: new Date().toISOString(),\n  hasPhoto: !!item.message?.photo,\n  hasDocument: !!item.message?.document,\n  hasAudio: !!item.message?.audio,\n  hasVoice: !!item.message?.voice,\n  photoFileId: item.message?.photo?.[item.message.photo.length - 1]?.file_id || null,\n  audioFileId: item.message?.audio?.file_id || null,\n  voiceFileId: item.message?.voice?.file_id || null\n};\n\n// Determine content type\nif (messageData.hasPhoto) {\n  messageData.contentType = 'image';\n} else if (messageData.hasAudio) {\n  messageData.contentType = 'audio';\n} else if (messageData.hasVoice) {\n  messageData.contentType = 'voice';\n} else if (messageData.hasDocument) {\n  messageData.contentType = 'document';\n} else {\n  messageData.contentType = 'text';\n}\n\nconsole.log('📥 Processing message:', messageData);\nreturn { json: messageData };"
      },
      "typeVersion": 2
    },
    {
      "id": "46a6c0fe-4788-49e5-9476-e0e6adb9b505",
      "name": "NVIDIA API NVIDIA Stable Diffusion 3",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -96,
        112
      ],
      "parameters": {
        "url": "https://ai.api.nvidia.com/v1/genai/stabilityai/stable-diffusion-3-medium",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "prompt",
              "value": "={{ $json.result.text }}"
            },
            {
              "name": "cfg_scale",
              "value": "5"
            },
            {
              "name": "aspect_ratio",
              "value": "16:9"
            },
            {
              "name": "seed",
              "value": "0"
            },
            {
              "name": "steps",
              "value": "50"
            },
            {
              "name": "negative_prompt"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            },
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpBearerAuth": {
          "id": "GAceFQsN6dFbFwnb",
          "name": "NVIDIA Stable Diffusion 3"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "a6e5eaa6-1996-477f-8856-304b5ae427a3",
      "name": "HTTP Nvidia Vila",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -48,
        -272
      ],
      "parameters": {
        "url": "https://ai.api.nvidia.com/v1/vlm/nvidia/vila",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": \"Describe this image {{ $json.result.file_id }}    >\"\n    }\n  ],\n  \"max_tokens\": 1024,\n  \"temperature\": 0.20,\n  \"top_p\": 0.70,\n  \"stream\": false,\n  \"model\": \"nvidia/vila\"\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType"
      },
      "credentials": {
        "httpBearerAuth": {
          "id": "iZ3zqzBmfMzDRXGW",
          "name": "Nvidia Vila"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "5391f189-99fb-4dd7-bbae-86edb1cb8cd4",
      "name": "🔀 合并 AI 结果",
      "type": "n8n-nodes-base.merge",
      "position": [
        176,
        -176
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "joinMode": "keepEverything",
        "fieldsToMatchString": "choices[0].message.content, content"
      },
      "typeVersion": 3
    },
    {
      "id": "65a4515d-97f2-4660-963b-d63d315640b5",
      "name": "发送图像转文本结果消息",
      "type": "n8n-nodes-base.gmail",
      "position": [
        336,
        -176
      ],
      "webhookId": "0dede3cd-dbda-4fdd-af06-1fe3d1340ee0",
      "parameters": {
        "sendTo": " ",
        "message": "=Hi Sir/Mdm,\n{{ $json.choices[0].message.content }}\n ",
        "options": {},
        "subject": "Results"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "TbUa3sBo9ouHTYFh",
          "name": "Gmail account 3"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "5dc968b3-ad4f-41ca-a8ef-90945bddd604",
      "name": "发送文本转图像结果消息",
      "type": "n8n-nodes-base.gmail",
      "position": [
        304,
        112
      ],
      "webhookId": "eab0c2b4-7612-462a-8d2e-219569bad508",
      "parameters": {
        "sendTo": " ",
        "message": "=Hi Sir/Mdm,\nPls see the attached file based on your input.\n ",
        "options": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {}
            ]
          }
        },
        "subject": "Results"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "zkm2omCjmdLquZGT",
          "name": "Gmail account 2"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "77d75186-4dfa-4b87-af2b-7144079569f3",
      "name": "转换为二进制文件",
      "type": "n8n-nodes-base.code",
      "position": [
        128,
        112
      ],
      "parameters": {
        "jsCode": "// Process NVIDIA API response and convert base64 to binary\nconst items = $input.all();\n\nreturn items.map(item => {\n  // NVIDIA API returns base64 image in 'image' field\n  let base64Image;\n  \n  // Check different possible response formats\n  if (item.json.image) {\n    base64Image = item.json.image;\n  } else if (item.json.artifacts && item.json.artifacts[0]) {\n    base64Image = item.json.artifacts[0].base64;\n  } else if (item.json.data && item.json.data[0]) {\n    base64Image = item.json.data[0].b64_json;\n  }\n  \n  // Clean base64 string (remove data URL prefix if present)\n  const base64Clean = base64Image.replace(/^data:image\\/\\w+;base64,/, '');\n  \n  // Convert to buffer\n  const buffer = Buffer.from(base64Clean, 'base64');\n  \n  return {\n    json: {\n      fileName: 'generated-image.png',\n      mimeType: 'image/png',\n      prompt: item.json.prompt || 'Generated image'\n    },\n    binary: {\n      data: {\n        data: buffer.toString('base64'),\n        mimeType: 'image/png',\n        fileName: 'generated-image.png'\n      }\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "2ffd5359-3dbe-407f-8933-ff320c8a1bd1",
      "name": "使用 GPT-4O-Mini 分析图像",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -48,
        -80
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "GPT-4O-MINI"
        },
        "options": {},
        "resource": "image",
        "inputType": "base64",
        "operation": "analyze"
      },
      "credentials": {
        "openAiApi": {
          "id": "OGYj7DgYv5GFLFZk",
          "name": "OpenAi account 2"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "8cd4cdf1-0f3e-4eec-89d0-3a6f743ab985",
      "name": "🔀 按内容类型路由 - 图像或文本",
      "type": "n8n-nodes-base.switch",
      "position": [
        -496,
        -80
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "image",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "192c9420-66ef-4732-b27d-a9cbdde74210",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.contentType }}",
                    "rightValue": "image"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "text",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "fb219757-9c3f-4ce6-a339-c2ba6918c92c",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.contentType }}",
                    "rightValue": "text"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "fallbackOutput": 2
        }
      },
      "typeVersion": 3.2
    },
    {
      "id": "407b4d3b-eebd-443a-9b62-f43fa8b92668",
      "name": "从 Telegram 获取文本",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -272,
        112
      ],
      "webhookId": "624ffc50-f1e7-4bed-9d81-4db5690e88a7",
      "parameters": {
        "text": "=💬 **Text Message Received**\n\nI received your text message. For advanced AI processing, please send an image with your question or request.\n\n**Your message:** {{ $json.text }}\n\nPls check your email",
        "chatId": "={{ $json.chatId }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "mYO3O1232v1KxESH",
          "name": "Telegram account 2"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ae9d115e-c443-4fc1-baf7-b5e687430475",
      "name": "📸 从 Telegram 获取图像文件",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -272,
        -176
      ],
      "webhookId": "61aa9370-a297-4863-b93a-63459fd221ef",
      "parameters": {
        "fileId": "={{ $json.photoFileId }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "mYO3O1232v1KxESH",
          "name": "Telegram account 2"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f3e451f4-c75d-4fc5-b8a4-acb7a3ff31f5",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        496,
        -704
      ],
      "parameters": {
        "width": 656,
        "height": 1040,
        "content": "## 简介"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "185d529d-b861-4c3a-b4af-fe30a79e7093",
  "connections": {
    "HTTP Nvidia Vila": {
      "main": [
        [
          {
            "node": "🔀 Merge AI Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "📱 Telegram Trigger": {
      "main": [
        [
          {
            "node": "📋 Extract Message Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "🔀 Merge AI Results": {
      "main": [
        [
          {
            "node": "Send a message of image-to-text results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to Binary File": {
      "main": [
        [
          {
            "node": "Send a message of text-to-image results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Text from Telegram": {
      "main": [
        [
          {
            "node": "NVIDIA API NVIDIA Stable Diffusion 3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "📋 Extract Message Data": {
      "main": [
        [
          {
            "node": "🔀 Route by Content Type - Image or Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze image using GPT-4O-Mini": {
      "main": [
        [
          {
            "node": "🔀 Merge AI Results",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "📸 Get Image file from Telegram": {
      "main": [
        [
          {
            "node": "Analyze image using GPT-4O-Mini",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP Nvidia Vila",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NVIDIA API NVIDIA Stable Diffusion 3": {
      "main": [
        [
          {
            "node": "Convert to Binary File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "🔀 Route by Content Type - Image or Text": {
      "main": [
        [
          {
            "node": "📸 Get Image file from Telegram",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Text from Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

这是一个中级难度的工作流,适用于Content Creation、Multimodal AI等场景。适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

需要付费吗?

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

工作流信息
难度等级
中级
节点数量13
分类2
节点类型9
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Cheng Siong Chin

Cheng Siong Chin

@cschin

Prof. Cheng Siong CHIN serves as Chair Professor in Intelligent Systems Modelling and Simulation in Newcastle University, Singapore. His academic credentials include an M.Sc. in Advanced Control and Systems Engineering from The University of Manchester and a Ph.D. in Robotics from Nanyang Technological University.

外部链接
在 n8n.io 上查看 →

分享此工作流