8
n8n 中文网amn8n.com

基于 GPT-4.1 的对话式 Meta 广告报告与管理

高级

这是一个AI Chatbot, Multimodal AI领域的自动化工作流,包含 17 个节点。主要使用 Set, Code, Merge, Switch, Agent 等节点。 基于 GPT-4.1 的对话式 Meta 广告报告与管理

前置要求
  • Facebook Graph API 凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "7eb33f3b90daa426f859ca3ba78306e8f7bedb062192407b5811dc8aa23756f7",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "881efba9-1edc-4ec6-ab4e-5ac67ddb27fc",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -224,
        -96
      ],
      "webhookId": "71ca0160-ea8f-4037-a9a0-c83a3391d0bf",
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "a8e434db-570a-40e0-9b9f-dbca06e6fd76",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        120,
        -96
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 2.2
    },
    {
      "id": "bd6f4433-634a-4313-a4fc-f76290eedab2",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        0,
        128
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1",
          "cachedResultName": "gpt-4.1"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "79I2aysjviBIV4Aj",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f46356dc-c1c8-4798-aacc-f059dbc85b23",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        128,
        128
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "d88a8ce8-4d31-4cdc-ad84-20d7162aaa34",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -224,
        424
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "command"
            },
            {
              "name": "id"
            },
            {
              "name": "since"
            },
            {
              "name": "until"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "8e7b6270-e895-448c-83fa-f00d2f4f7f54",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        0,
        424
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "list_accounts",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "6890448a-74f3-497b-8996-0edc456ef140",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.command }}",
                    "rightValue": "list_accounts"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "account",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "e8c7ff7a-abae-4a60-996f-b57322c513f2",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.command }}",
                    "rightValue": "account"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "49b75fbb-06e6-4451-b4a2-31410d03bbbf",
      "name": "list accounts",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        256,
        128
      ],
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "UXdblREvbkvy3WSs",
          "cachedResultName": "MCP: Meta Ads"
        },
        "description": "List ad accounts",
        "workflowInputs": {
          "value": {
            "command": "list_accounts"
          },
          "schema": [
            {
              "id": "command",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "command",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "command"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "3f322a2e-324d-42e3-a657-2880cd893aea",
      "name": "account details",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        384,
        128
      ],
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "UXdblREvbkvy3WSs",
          "cachedResultName": "MCP: Meta Ads"
        },
        "description": "List ad accounts",
        "workflowInputs": {
          "value": {
            "id": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('id', ``, 'string') }}",
            "since": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('since', ``, 'string') }}",
            "until": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('until', ``, 'string') }}",
            "command": "account"
          },
          "schema": [
            {
              "id": "command",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "command",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "since",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "since",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "until",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "until",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "command"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "ffa7f3ac-b8f7-4b5b-9764-11319699bb0d",
      "name": "graph: adaccounts",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        224,
        328
      ],
      "parameters": {
        "edge": "adaccounts",
        "node": "me",
        "options": {
          "fields": {
            "field": [
              {
                "name": "name"
              }
            ]
          }
        },
        "graphApiVersion": "v23.0"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "tCCZIaLWLX5MspPG",
          "name": "Facebook Graph account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5e63ad12-607f-4d54-859e-d57d8688057e",
      "name": "account: campaigns",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        672,
        232
      ],
      "parameters": {
        "edge": "campaigns",
        "node": "={{ $json.id }}",
        "options": {
          "fields": {
            "field": [
              {
                "name": "id,name,status"
              }
            ]
          },
          "queryParameters": {
            "parameter": [
              {
                "name": "effective_status",
                "value": "=[\"ACTIVE\"]"
              }
            ]
          }
        },
        "graphApiVersion": "v23.0"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "tCCZIaLWLX5MspPG",
          "name": "Facebook Graph account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5252e239-fb20-43a4-8a41-7b4cf1c9ab01",
      "name": "account: adsets",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        672,
        424
      ],
      "parameters": {
        "edge": "adsets",
        "node": "={{ $json.id }}",
        "options": {
          "fields": {
            "field": [
              {
                "name": "id,name,status,campaign"
              }
            ]
          },
          "queryParameters": {
            "parameter": [
              {
                "name": "effective_status",
                "value": "=[\"ACTIVE\"]"
              }
            ]
          }
        },
        "graphApiVersion": "v23.0"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "tCCZIaLWLX5MspPG",
          "name": "Facebook Graph account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "798a573c-707e-4a6b-9093-7b9f8aa61cb0",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        896,
        584
      ],
      "parameters": {
        "mode": "combine",
        "options": {
          "includeUnpaired": true
        },
        "combineBy": "combineByPosition",
        "numberInputs": 4
      },
      "typeVersion": 3.2
    },
    {
      "id": "01f68eb7-c747-4134-971e-bf18822d6009",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        1120,
        616
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "return {\n  campaigns: $('account: campaigns').item.json.data,\n  adsets: $('account: adsets').item.json.data,\n  ads:   $('account: ads').item.json.data,\n  account_insights: $('account: ads1').item.json.data\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "2da3e999-12e7-4370-ac21-3f447b6b3289",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        448,
        520
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "fb4d9260-92bb-45cf-9055-a746f1aace7b",
      "name": "account: ads",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        672,
        616
      ],
      "parameters": {
        "edge": "ads",
        "node": "={{ $json.id }}",
        "options": {
          "fields": {
            "field": [
              {
                "name": "id,name,status,campaign{id,name},adset{id,name}"
              }
            ]
          },
          "queryParameters": {
            "parameter": [
              {
                "name": "effective_status",
                "value": "=[\"ACTIVE\"]"
              }
            ]
          }
        },
        "graphApiVersion": "v23.0"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "tCCZIaLWLX5MspPG",
          "name": "Facebook Graph account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d3ed3c25-a702-44e5-be77-3303960ed0fb",
      "name": "Edit Fields1",
      "type": "n8n-nodes-base.set",
      "position": [
        224,
        520
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "481319e1-d562-415d-aa04-4063421bc9b1",
              "name": "id",
              "type": "string",
              "value": "={{ $json.id.startsWith('act') ? $json.id : 'act_'+$json.id }}"
            },
            {
              "id": "ff699971-c2bb-4e24-96c1-a246cdd3f87b",
              "name": "since",
              "type": "string",
              "value": "={{ $json.since ?? $today.startOf('month') }}"
            },
            {
              "id": "76e8ddf3-e35c-4f4a-bcd6-db751d4443e2",
              "name": "until",
              "type": "string",
              "value": "={{ $json.until ?? $today.endOf('month') }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "629df03e-4091-487a-b0ec-32e366b9b008",
      "name": "account: ads1",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        672,
        808
      ],
      "parameters": {
        "edge": "insights",
        "node": "={{ $json.id }}",
        "options": {
          "fields": {
            "field": [
              {
                "name": "attribution_setting,conversion_values,conversions,cost_per_conversion,cpc,cpm,ctr,frequency,impressions,inline_post_engagement,purchase_roas,reach,result_rate,results,spend"
              }
            ]
          },
          "queryParameters": {
            "parameter": [
              {
                "name": "time_range[since]",
                "value": "={{ $json.since.replace(/T.*/,'') }}"
              },
              {
                "name": "time_range[until]",
                "value": "={{ $json.until.replace(/T.*/,'') }}"
              }
            ]
          }
        },
        "graphApiVersion": "v23.0"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "tCCZIaLWLX5MspPG",
          "name": "Facebook Graph account"
        }
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "798a573c-707e-4a6b-9093-7b9f8aa61cb0": {
      "main": [
        [
          {
            "node": "01f68eb7-c747-4134-971e-bf18822d6009",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "8e7b6270-e895-448c-83fa-f00d2f4f7f54": {
      "main": [
        [
          {
            "node": "ffa7f3ac-b8f7-4b5b-9764-11319699bb0d",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "d3ed3c25-a702-44e5-be77-3303960ed0fb",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "d3ed3c25-a702-44e5-be77-3303960ed0fb": {
      "main": [
        [
          {
            "node": "2da3e999-12e7-4370-ac21-3f447b6b3289",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "fb4d9260-92bb-45cf-9055-a746f1aace7b": {
      "main": [
        [
          {
            "node": "798a573c-707e-4a6b-9093-7b9f8aa61cb0",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "f46356dc-c1c8-4798-aacc-f059dbc85b23": {
      "ai_memory": [
        [
          {
            "node": "a8e434db-570a-40e0-9b9f-dbca06e6fd76",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "629df03e-4091-487a-b0ec-32e366b9b008": {
      "main": [
        [
          {
            "node": "798a573c-707e-4a6b-9093-7b9f8aa61cb0",
            "type": "main",
            "index": 3
          }
        ]
      ]
    },
    "49b75fbb-06e6-4451-b4a2-31410d03bbbf": {
      "ai_tool": [
        [
          {
            "node": "a8e434db-570a-40e0-9b9f-dbca06e6fd76",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "3f322a2e-324d-42e3-a657-2880cd893aea": {
      "ai_tool": [
        [
          {
            "node": "a8e434db-570a-40e0-9b9f-dbca06e6fd76",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "5252e239-fb20-43a4-8a41-7b4cf1c9ab01": {
      "main": [
        [
          {
            "node": "798a573c-707e-4a6b-9093-7b9f8aa61cb0",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "bd6f4433-634a-4313-a4fc-f76290eedab2": {
      "ai_languageModel": [
        [
          {
            "node": "a8e434db-570a-40e0-9b9f-dbca06e6fd76",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "ffa7f3ac-b8f7-4b5b-9764-11319699bb0d": {
      "main": [
        []
      ]
    },
    "5e63ad12-607f-4d54-859e-d57d8688057e": {
      "main": [
        [
          {
            "node": "798a573c-707e-4a6b-9093-7b9f8aa61cb0",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "2da3e999-12e7-4370-ac21-3f447b6b3289": {
      "main": [
        [
          {
            "node": "5e63ad12-607f-4d54-859e-d57d8688057e",
            "type": "main",
            "index": 0
          },
          {
            "node": "5252e239-fb20-43a4-8a41-7b4cf1c9ab01",
            "type": "main",
            "index": 0
          },
          {
            "node": "fb4d9260-92bb-45cf-9055-a746f1aace7b",
            "type": "main",
            "index": 0
          },
          {
            "node": "629df03e-4091-487a-b0ec-32e366b9b008",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "881efba9-1edc-4ec6-ab4e-5ac67ddb27fc": {
      "main": [
        [
          {
            "node": "a8e434db-570a-40e0-9b9f-dbca06e6fd76",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "d88a8ce8-4d31-4cdc-ad84-20d7162aaa34": {
      "main": [
        [
          {
            "node": "8e7b6270-e895-448c-83fa-f00d2f4f7f54",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - AI 聊天机器人, 多模态 AI

需要付费吗?

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

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

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

作者
Konrad Roziewski

Konrad Roziewski

@kroziewski

Using self-hosted n8n since 2022. Specializing in AI, ETL, marketing and product management workflows.

外部链接
在 n8n.io 查看

分享此工作流

分类

分类: 34