8
n8n 中文网amn8n.com

使用OpenAI GPT-Image-1生成图像并通过Telegram分享

高级

这是一个Design, AI, Marketing领域的自动化工作流,包含 18 个节点。主要使用 Set, Switch, Telegram, FormTrigger, GoogleDrive 等节点,结合人工智能技术实现智能自动化。 使用OpenAI GPT-Image-1生成和编辑图像并通过Telegram分享

前置要求
  • Telegram Bot Token
  • Google Drive API 凭证
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "2fa7acc0cd134988fb8b40b8d8b56c9f29ee37789503fef505450e2733dc2bdf",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "0b66ad6f-d216-41f3-a6dc-61cf15a2044a",
      "name": "设置访问权限",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -2220,
        -1000
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "operation": "share",
        "permissionsUi": {
          "permissionsValues": {
            "role": "reader",
            "type": "anyone"
          }
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "id": "vM5RNejQ9XDoP6Ld",
          "name": "Google Sheets n8n dev service account"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "724b14c0-6763-47f5-87a1-ed0dde7e8a9e",
      "name": "编辑图片(OpenAI)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -3060,
        -1000
      ],
      "parameters": {
        "url": "https://api.openai.com/v1/images/edits",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "image",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "={{ $json[\"input image url\"].isEmpty()?\"input_image\":\"data\"}}"
            },
            {
              "name": "prompt",
              "value": "={{ $json.Promt }}"
            },
            {
              "name": "model",
              "value": "gpt-image-1"
            },
            {
              "name": "n",
              "value": "1"
            },
            {
              "name": "size",
              "value": "1024x1024"
            },
            {
              "name": "quality",
              "value": "={{ $json.quality }}"
            }
          ]
        },
        "nodeCredentialType": "openAiApi"
      },
      "credentials": {
        "openAiApi": {
          "id": "3ff0w5x5tfolokJ7",
          "name": "OpenAi account mingles new dev user"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "071f9711-3b73-411d-9962-b540f0b418c7",
      "name": "将JSON二进制转换为文件",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        -2740,
        -620
      ],
      "parameters": {
        "options": {
          "fileName": "={{ $now.format('yyyy-MM-dd_HHmmss')+\".png\" }}",
          "mimeType": "image/png"
        },
        "operation": "toBinary",
        "sourceProperty": "data[0].b64_json"
      },
      "typeVersion": 1.1
    },
    {
      "id": "e22377ef-1bbf-4288-a625-d07a97d5667d",
      "name": "将JSON二进制转换为最终文件",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        -2740,
        -1000
      ],
      "parameters": {
        "options": {
          "fileName": "={{ $now.format('yyyy-MM-dd_HHmmss')+\".png\" }}",
          "mimeType": "image/png"
        },
        "operation": "toBinary",
        "sourceProperty": "data[0].b64_json"
      },
      "typeVersion": 1.1
    },
    {
      "id": "5aabd61e-5407-4be7-b6c9-ab77c7cadad7",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3140,
        -780
      ],
      "parameters": {
        "color": 3,
        "width": 280,
        "height": 340,
        "content": "### 🎨 图像生成 (OpenAI)"
      },
      "typeVersion": 1
    },
    {
      "id": "93be8801-7fb4-42d7-af2d-1047b8c60d6e",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2840,
        -1200
      ],
      "parameters": {
        "color": 5,
        "width": 300,
        "height": 760,
        "content": "### 🧾 将 base64 转换为文件"
      },
      "typeVersion": 1
    },
    {
      "id": "aeafd971-28ad-4c5c-8d26-0d81f82fac01",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3140,
        -1200
      ],
      "parameters": {
        "color": 3,
        "width": 280,
        "height": 360,
        "content": "### ✏️ 图像到图像生成 (OpenAI)"
      },
      "typeVersion": 1
    },
    {
      "id": "930bba79-34c4-40da-b22f-4f42b9894705",
      "name": "表单提交时",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -3860,
        -840
      ],
      "webhookId": "e3e1e092-d5fb-4e15-911e-3bc98e916c9f",
      "parameters": {
        "options": {},
        "formTitle": "GPT image to image",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Promt",
              "requiredField": true
            },
            {
              "fieldType": "dropdown",
              "fieldLabel": "quality",
              "fieldOptions": {
                "values": [
                  {
                    "option": "low"
                  },
                  {
                    "option": "medium"
                  },
                  {
                    "option": "high"
                  }
                ]
              },
              "requiredField": true
            },
            {
              "fieldType": "file",
              "fieldLabel": "input image",
              "multipleFiles": false,
              "acceptFileTypes": ".png,.jpg,.jpeg"
            },
            {
              "fieldLabel": "input image url"
            }
          ]
        },
        "responseMode": "lastNode",
        "authentication": "basicAuth"
      },
      "credentials": {
        "httpBasicAuth": {
          "id": "EzEYGeSYuNmHnrQn",
          "name": "reels maker auth"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "abb8a008-0dcb-427c-a00a-7c850790cf4f",
      "name": "将结果图像上传到 imgbb",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -2220,
        -640
      ],
      "parameters": {
        "url": "https://api.imgbb.com/1/upload",
        "method": "POST",
        "options": {
          "redirect": {
            "redirect": {}
          }
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "name": "image",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "data"
            },
            {
              "name": "key",
              "value": "={{ $json.IMGBB_API_KEY }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "ec0fc073-15f9-4cdf-a2f4-19de2c2b3261",
      "name": "将结果图像上传到 Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -2440,
        -1000
      ],
      "parameters": {
        "name": "={{ $input.item.binary.data.fileName }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive",
          "cachedResultUrl": "https://drive.google.com/drive/my-drive",
          "cachedResultName": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root",
          "cachedResultUrl": "https://drive.google.com/drive",
          "cachedResultName": "/ (Root folder)"
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "id": "vM5RNejQ9XDoP6Ld",
          "name": "Google Sheets n8n dev service account"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "7487229b-5e94-48d4-b84c-a5725e529e23",
      "name": "文件链接",
      "type": "n8n-nodes-base.set",
      "position": [
        -2020,
        -1000
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "df673a7d-7ff2-4c7e-835f-7c65e58c5ad4",
              "name": "ViewLink",
              "type": "string",
              "value": "={{ $('Upload Result Image to Google Drive').item.json.webViewLink }}"
            },
            {
              "id": "c3447718-d652-45d7-9c6f-6a1d4f29a68d",
              "name": "ContentLink",
              "type": "string",
              "value": "={{ $('Upload Result Image to Google Drive').item.json.webContentLink }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "f4f2a07d-4a5e-45d9-96d6-0f5eb1359d6f",
      "name": "通过 URL 获取输入图像",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -3360,
        -840
      ],
      "parameters": {
        "url": "={{ $json['input image url'] }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "613aa7b5-8f63-490f-9026-de4971619e41",
      "name": "设置 API 密钥",
      "type": "n8n-nodes-base.set",
      "position": [
        -2440,
        -640
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "f0df22ed-6c69-4204-8cfb-8dae51ea8fd4",
              "name": "IMGBB_API_KEY",
              "type": "string",
              "value": "IMGBB_API_KEY"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "5e276d4c-05c0-4aa2-9f3c-88669c2d259a",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2500,
        -1200
      ],
      "parameters": {
        "color": 6,
        "width": 640,
        "height": 760,
        "content": "## 将结果文件上传到 Google Drive 或 [imgbb](https://api.imgbb.com/)"
      },
      "typeVersion": 1
    },
    {
      "id": "38760191-c39a-4a62-a222-324e5cd83590",
      "name": "图像生成",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -3060,
        -620
      ],
      "parameters": {
        "url": "https://api.openai.com/v1/images/generations",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "gpt-image-1"
            },
            {
              "name": "prompt",
              "value": "={{ $json.Promt }}"
            },
            {
              "name": "n",
              "value": "={{Number(1)}}"
            },
            {
              "name": "size",
              "value": "1024x1024"
            },
            {
              "name": "moderation",
              "value": "low"
            },
            {
              "name": "background",
              "value": "auto"
            },
            {
              "name": "quality",
              "value": "={{ $json.quality }}"
            }
          ]
        },
        "nodeCredentialType": "openAiApi"
      },
      "credentials": {
        "openAiApi": {
          "id": "3ff0w5x5tfolokJ7",
          "name": "OpenAi account mingles new dev user"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "6abaccab-b49b-41ab-86cd-8bf562472f9d",
      "name": "文件链接1",
      "type": "n8n-nodes-base.set",
      "position": [
        -2000,
        -640
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "df673a7d-7ff2-4c7e-835f-7c65e58c5ad4",
              "name": "ViewLink",
              "type": "string",
              "value": "={{ $json.data.url }}"
            },
            {
              "id": "c3447718-d652-45d7-9c6f-6a1d4f29a68d",
              "name": "ContentLink",
              "type": "string",
              "value": "={{ $json.data.image.url }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "7443a6f2-3d0c-4fef-9dbe-56948ea8c17c",
      "name": "发送到 Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -1740,
        -840
      ],
      "webhookId": "150d64ce-d278-4459-b9b9-5d0dfb3afbd1",
      "parameters": {
        "file": "={{ $json.ContentLink }}",
        "chatId": "YOUR_CHAT_ID",
        "operation": "sendPhoto",
        "additionalFields": {
          "caption": "={{ $('On form submission').item.json.Promt }}\n{{ $('On form submission').item.json.quality }}\n\n[Result]({{ $json.ViewLink }})",
          "parse_mode": "MarkdownV2"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "ar7qqwMS6eFB8SaY",
          "name": "NyroSikAIbot"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "efe008a1-1dea-41f8-8778-1556cf0bbbea",
      "name": "切换模式",
      "type": "n8n-nodes-base.switch",
      "position": [
        -3640,
        -840
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "file",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "6c2e2793-96f4-4d15-af76-926d1fdcee71",
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json['input image'] !== null && $json['input image url'].isNotEmpty() }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "file_url",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "9d464a07-f5fe-48af-b524-6ca60479fda6",
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json['input image url'] !== null && $json['input image url'].isNotEmpty() }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "typeVersion": 3.2
    }
  ],
  "pinData": {},
  "connections": {
    "File Link": {
      "main": [
        [
          {
            "node": "Send to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File Link1": {
      "main": [
        [
          {
            "node": "Send to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch Mode": {
      "main": [
        [
          {
            "node": "Edit Image (OpenAI)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Input Image by URL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Image Generation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SETUP API KEY": {
      "main": [
        [
          {
            "node": "Upload Result Image to imgbb",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Image Generation": {
      "main": [
        [
          {
            "node": "Convert json binary to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "Switch Mode",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Image (OpenAI)": {
      "main": [
        [
          {
            "node": "Convert json binary to File final",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Input Image by URL": {
      "main": [
        [
          {
            "node": "Edit Image (OpenAI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Access Permissions": {
      "main": [
        [
          {
            "node": "File Link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert json binary to File": {
      "main": [
        [
          {
            "node": "SETUP API KEY",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Result Image to imgbb": {
      "main": [
        [
          {
            "node": "File Link1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert json binary to File final": {
      "main": [
        [
          {
            "node": "Upload Result Image to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Result Image to Google Drive": {
      "main": [
        [
          {
            "node": "Set Access Permissions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 设计, 人工智能, 营销

需要付费吗?

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

工作流信息
难度等级
高级
节点数量18
分类3
节点类型8
难度说明

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

外部链接
在 n8n.io 查看

分享此工作流