8
n8n 中文网amn8n.com

Facebook审核器Webhook和消息模板

高级

这是一个AI Chatbot, Multimodal AI领域的自动化工作流,包含 23 个节点。主要使用 If, Set, Code, Notion, Webhook 等节点。 Gemini驱动的Facebook评论与私信助手(集成Notion)

前置要求
  • Notion API Key
  • HTTP Webhook 端点(n8n 会自动生成)
  • 可能需要目标 API 的认证凭证
  • Facebook Graph API 凭证
  • Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "[YOUR_WORKFLOW_ID]",
  "meta": {
    "instanceId": "[YOUR_INSTANCE_ID]",
    "templateCredsSetupCompleted": false
  },
  "name": "Facebook审核器Webhook和消息模板",
  "tags": [],
  "nodes": [
    {
      "id": "d695c988-e0ad-4726-a446-f29c84ce343c",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        4288,
        560
      ],
      "parameters": {
        "text": "=You are a helpful customer support agent for [COMPANY_NAME], a [INDUSTRY_TYPE] company in [COUNTRY/REGION].  \nRead the customer's comment and output a JSON with 3 fields: reply, sentiment, dm_message.  \n\nGuidelines:\n- Write in [TARGET_LANGUAGE] ([LANGUAGE_DIALECT]), unisex, short, warm, natural.\n- Never use [REGIONAL_WORDS_TO_AVOID] or filler intros ([\"GREETING_1\"], [\"GREETING_2\"], etc).\n- Always start directly with the subject.\n\nRules:\n- For any **question, inquiry, complaints, or price/product request** → \n  reply: short public message like \"[STANDARD_DM_REDIRECT_MESSAGE] 🙏\" (variations allowed).  \n  dm_message: use the relevant answer from the database ({{ $('Arrange KB').item.json.databaseText }}).\n  sentiment: \"normal\" or \"price\".\n- For **compliments/positive only** → \n  reply: short thanks (e.g., \"[THANK_YOU_MESSAGE] 💙\").  \n  dm_message: \"\"  \n  sentiment: \"complement\".\n- For **complaints (no swears)** → \n  reply: short apology + mention DM (e.g., \"[APOLOGY_MESSAGE] 🙏 [DM_MENTION]\").  \n  dm_message: \"[COMPLAINT_RESPONSE_TEMPLATE]\" \n- For unclear or not understandable words/comments (e.g., \"hm\", \"ok\", \"??\") →\n  reply: \"[CLARIFICATION_REQUEST_MESSAGE] 🙏\"\n  dm_message: \"\". (empty)\n  sentiment: \"normal\".\n  sentiment: \"negative\".\n- For **offensive words, spam, or links** → \n  reply: \"\"  \n  dm_message: \"\"  \n  sentiment: \"negative\".\n\nOutput only valid JSON:  \n{\n  \"reply\": \"...\",\n  \"sentiment\": \"normal | price | negative | complement\",\n  \"dm_message\": \"...\"\n}\n\nCustomer comment: \"{{ $('Parse Comms').item.json.comment_message }}\"\n",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2.1
    },
    {
      "id": "d376462a-637e-41d4-a58f-144ca11285f7",
      "name": "Google Gemini 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        4192,
        784
      ],
      "parameters": {
        "options": {
          "temperature": 0.1
        }
      },
      "credentials": {
        "googlePalmApi": {
          "id": "[YOUR_GEMINI_API_CREDENTIAL_ID]",
          "name": "[YOUR_GEMINI_API_CREDENTIAL_NAME]"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e200441c-1757-4106-8727-e3a3ad130b6e",
      "name": "删除评论",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        5264,
        832
      ],
      "parameters": {
        "node": "={{ $('Webhook1').item.json.body.entry[0].changes[0].value.comment_id }}",
        "options": {
          "queryParameters": {
            "parameter": [
              {
                "name": "is_hidden",
                "value": "true"
              }
            ]
          }
        },
        "graphApiVersion": "v23.0",
        "httpRequestMethod": "POST"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "[YOUR_FACEBOOK_API_CREDENTIAL_ID]",
          "name": "[YOUR_FACEBOOK_API_CREDENTIAL_NAME]"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "7f5b68d5-070f-4573-ac83-50b8d12bb1f1",
      "name": "回复",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        4880,
        336
      ],
      "parameters": {
        "edge": "comments",
        "node": "={{ $('Webhook1').item.json.body.entry[0].changes[0].value.comment_id }}",
        "options": {
          "queryParameters": {
            "parameter": [
              {
                "name": "message",
                "value": "={{ $('Separate rep&sent').item.json.reply }}"
              }
            ]
          }
        },
        "graphApiVersion": "v23.0",
        "httpRequestMethod": "POST"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "[YOUR_FACEBOOK_API_CREDENTIAL_ID]",
          "name": "[YOUR_FACEBOOK_API_CREDENTIAL_NAME]"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "385719df-bd5f-40f7-ac86-5f3ad3170585",
      "name": "回复1",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        5104,
        832
      ],
      "parameters": {
        "edge": "comments",
        "node": "={{ $('Webhook1').item.json.body.entry[0].changes[0].value.comment_id }}",
        "options": {
          "queryParameters": {
            "parameter": [
              {
                "name": "message",
                "value": "={{ $('Separate rep&sent').item.json.reply }}"
              }
            ]
          }
        },
        "graphApiVersion": "v23.0",
        "httpRequestMethod": "POST"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "[YOUR_FACEBOOK_API_CREDENTIAL_ID]",
          "name": "[YOUR_FACEBOOK_API_CREDENTIAL_NAME]"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "cd5cb95d-3a21-42b5-a679-5fcac06759c2",
      "name": "Webhook1",
      "type": "n8n-nodes-base.webhook",
      "position": [
        2656,
        560
      ],
      "webhookId": "[YOUR_WEBHOOK_ID]",
      "parameters": {
        "path": "[YOUR_WEBHOOK_PATH]",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "b342831b-72e8-4749-8589-0bdf280e1018",
      "name": "解析评论",
      "type": "n8n-nodes-base.set",
      "position": [
        3040,
        544
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "c6332299-eda4-4602-a43a-a703574694cb",
              "name": "page_id",
              "type": "string",
              "value": "={{ $json.body.entry[0].id }}"
            },
            {
              "id": "55f0414b-399c-4bcd-bb40-782e84f844d8",
              "name": "post_id",
              "type": "string",
              "value": "={{ $json.body.entry[0].changes[0].value.post_id }}"
            },
            {
              "id": "52ff90c7-1c35-4755-a0fa-a2e7c3539e64",
              "name": "comment_id",
              "type": "string",
              "value": "={{ $json.body.entry[0].changes[0].value.comment_id }}"
            },
            {
              "id": "5ea9cb24-8e33-477d-b39d-9dd20faa6e89",
              "name": "comment_message",
              "type": "string",
              "value": "={{ $json.body.entry[0].changes[0].value.message }}"
            },
            {
              "id": "b0e64cf7-6b84-4efd-a8a0-a6a8a91ff245",
              "name": "parent_id",
              "type": "string",
              "value": "={{ $json.body.entry[0].changes[0].value.parent_id }}"
            },
            {
              "id": "57cc15a0-fe14-45c6-abc3-b65d033904d6",
              "name": "comm_time",
              "type": "string",
              "value": "={{ $json.body.entry[0].changes[0].value.created_time }}"
            },
            {
              "id": "ae4a2f1a-35f3-4b92-b8fc-3bab16338c8f",
              "name": "field",
              "type": "string",
              "value": "={{ $json.body.entry[0].changes[0].field }}"
            },
            {
              "id": "7492664e-bde3-4618-8f8a-4afc78db218a",
              "name": "sender_id",
              "type": "string",
              "value": "={{ $json.body.entry[0].changes[0].value.from.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "81631f15-f9b6-4bdb-a40b-a9705c88b159",
      "name": "检查数据库",
      "type": "n8n-nodes-base.notion",
      "position": [
        3440,
        544
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "key": "Comment ID|rich_text",
              "condition": "equals",
              "richTextValue": "={{ $json.comment_id }}"
            },
            {
              "key": "sender id|rich_text",
              "condition": "equals",
              "richTextValue": "[YOUR_PAGE_ID]"
            }
          ]
        },
        "options": {},
        "resource": "databasePage",
        "matchType": "allFilters",
        "operation": "getAll",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "[YOUR_PROCESSED_COMMENTS_DATABASE_ID]",
          "cachedResultUrl": "[YOUR_NOTION_DATABASE_URL]",
          "cachedResultName": "Processed Facebook Comments"
        },
        "filterType": "manual"
      },
      "credentials": {
        "notionApi": {
          "id": "[YOUR_NOTION_API_CREDENTIAL_ID]",
          "name": "[YOUR_NOTION_API_CREDENTIAL_NAME]"
        }
      },
      "typeVersion": 2.2,
      "alwaysOutputData": true
    },
    {
      "id": "6a13ad96-70da-4e42-a6ca-76cf4a74f785",
      "name": "获取知识库",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3584,
        544
      ],
      "parameters": {
        "url": "https://api.notion.com/v1/databases/[YOUR_KNOWLEDGE_BASE_DATABASE_ID]/query",
        "method": "POST",
        "options": {},
        "jsonBody": "{\n  \"page_size\": 100\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "notionApi"
      },
      "credentials": {
        "notionApi": {
          "id": "[YOUR_NOTION_API_CREDENTIAL_ID]",
          "name": "[YOUR_NOTION_API_CREDENTIAL_NAME]"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "6e798d06-ea8e-455f-9d68-0eae00051f51",
      "name": "整理知识库",
      "type": "n8n-nodes-base.code",
      "position": [
        3744,
        544
      ],
      "parameters": {
        "jsCode": "// Get the response from Notion API\nconst notionResponse = $input.first().json;\nconst pages = notionResponse.results || [];\n\n// Helper function to extract text from Notion properties\nfunction extractText(property) {\n  if (!property) return '';\n\n  switch (property.type) {\n    case 'title':\n      return property.title?.map(t => t.plain_text).join('\\n') || '';\n    case 'rich_text':\n      return property.rich_text?.map(t => t.plain_text).join('\\n') || '';\n    case 'select':\n      return property.select?.name || '';\n    case 'multi_select':\n      return property.multi_select?.map(item => item.name).join(', ') || '';\n    case 'number':\n      return property.number?.toString() || '';\n    case 'checkbox':\n      return property.checkbox ? '[YES_TEXT]' : '[NO_TEXT]';\n    case 'date':\n      return property.date?.start || '';\n    case 'email':\n      return property.email || '';\n    case 'phone_number':\n      return property.phone_number || '';\n    case 'url':\n      return property.url || '';\n    default:\n      return '';\n  }\n}\n\n// Process data into clean JSON\nconst database = pages.map(page => {\n  const item = {};\n  for (const [propName, propData] of Object.entries(page.properties)) {\n    item[propName] = extractText(propData);\n  }\n  return item;\n}).filter(item => Object.values(item).some(value => value.length > 0));\n\n// Build databaseText (preserve newlines inside values; do NOT collapse \\n)\nconst databaseText = database.map(item => {\n  return Object.entries(item)\n    .filter(([key, value]) => value && value.trim() !== '')\n    .map(([key, value]) => {\n      let clean = value\n        .replace(/[\\\"\"\"«»„]/g, '')   // remove quotes\n        .replace(/[ \\t]+/g, ' ')    // collapse spaces/tabs only; keep \\n\n        .replace(/\\r\\n/g, '\\n')     // normalize Windows newlines\n        .trim();\n      return `${key}: ${clean}`;\n    })\n    .join(' | ');\n}).join('\\n\\n');\n\n// Build databaseRaw (keeps full formatting for Messenger DMs)\nconst databaseRaw = database.map(item => {\n  return Object.entries(item)\n    .filter(([key, value]) => value && value.trim() !== '')\n    .map(([key, value]) => `${key}: ${value}`)\n    .join('\\n');\n}).join('\\n\\n');\n\n// Build databaseRawList (array per entry, verbatim)\nconst databaseRawList = database.map(item => {\n  return Object.entries(item)\n    .filter(([key, value]) => value && value.trim() !== '')\n    .map(([key, value]) => `${key}: ${value}`)\n    .join('\\n');\n});\n\n// Return multiple formats\nreturn [{\n  json: {\n    database,                                   // Original array (for processing)\n    databaseJSON: JSON.stringify(database, null, 2), // Pretty formatted JSON string\n    databaseText,                               // Cleaned & flattened text (for AI), keeps \\n\n    databaseRaw,                                // Raw text with formatting (for DM)\n    databaseRawList,                            // Array of verbatim entries\n    databaseString: JSON.stringify(database)    // Compact JSON string\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "81827b17-d190-46fa-9630-955b7476a7d2",
      "name": "谁在那里?",
      "type": "n8n-nodes-base.if",
      "position": [
        3904,
        544
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "3fe76f48-77f6-42fd-b62f-8e038aec355e",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('Parse Comms').item.json.sender_id }}",
              "rightValue": "[YOUR_PAGE_ID]"
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "34265ef0-ddb3-4e32-950e-e81899ceab57",
      "name": "评论",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        4112,
        560
      ],
      "parameters": {
        "edge": "comments",
        "node": "={{ $('Webhook1').item.json.body.entry[0].changes[0].value.comment_id }}",
        "options": {},
        "graphApiVersion": "v23.0"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "[YOUR_FACEBOOK_API_CREDENTIAL_ID]",
          "name": "[YOUR_FACEBOOK_API_CREDENTIAL_NAME]"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "be7ffc10-8ccb-4d87-88a7-668eb914f87c",
      "name": "是否合适?",
      "type": "n8n-nodes-base.if",
      "position": [
        4864,
        560
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "b5250fd7-6814-4ed9-9252-502ddfcfe3b0",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.sentiment }}",
              "rightValue": "normal"
            },
            {
              "id": "206c8aaf-5d2c-40ca-a528-d3fea28f7d6b",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.sentiment }}",
              "rightValue": "price"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "a7d9d1e3-de37-4e06-b0b6-de26914fbb0b",
      "name": "分离回复和句子",
      "type": "n8n-nodes-base.set",
      "position": [
        4592,
        560
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a66c9423-7860-447d-9770-a25f969e1188",
              "name": "=reply",
              "type": "string",
              "value": "={{ JSON.parse($json[\"output\"].replace(/```json|```/g, \"\").trim()).reply }}"
            },
            {
              "id": "f20c73de-ad95-40d0-8e52-23c335af9858",
              "name": "sentiment",
              "type": "string",
              "value": "={{ JSON.parse($json[\"output\"].replace(/```json|```/g, \"\").trim()).sentiment }}"
            },
            {
              "id": "c87acc41-657d-4009-8c39-38b13d73ccc0",
              "name": "dm_message",
              "type": "string",
              "value": "={{ JSON.parse($json[\"output\"].replace(/```json|```/g, \"\").trim()).dm_message }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "4675cd80-c5f4-41e6-b982-448cf9081d85",
      "name": "添加到数据库",
      "type": "n8n-nodes-base.notion",
      "position": [
        5040,
        336
      ],
      "parameters": {
        "options": {},
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "[YOUR_PROCESSED_COMMENTS_DATABASE_ID]",
          "cachedResultUrl": "[YOUR_NOTION_DATABASE_URL]",
          "cachedResultName": "Processed Facebook Comments"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Comment ID|rich_text",
              "textContent": "={{ $('Webhook1').item.json.body.entry[0].changes[0].value.comment_id }}"
            },
            {
              "key": "Response Status|status",
              "statusValue": "Done"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "id": "[YOUR_NOTION_API_CREDENTIAL_ID]",
          "name": "[YOUR_NOTION_API_CREDENTIAL_NAME]"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "124ff942-ca28-44a9-a7f1-a7eca1c7ec02",
      "name": "添加到数据库1",
      "type": "n8n-nodes-base.notion",
      "position": [
        5456,
        832
      ],
      "parameters": {
        "options": {},
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "[YOUR_PROCESSED_COMMENTS_DATABASE_ID]",
          "cachedResultUrl": "[YOUR_NOTION_DATABASE_URL]",
          "cachedResultName": "Processed Facebook Comments"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Comment ID|rich_text",
              "textContent": "={{ $('Webhook1').item.json.body.entry[0].changes[0].value.comment_id }}"
            },
            {
              "key": "Response Status|status",
              "statusValue": "Done"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "id": "[YOUR_NOTION_API_CREDENTIAL_ID]",
          "name": "[YOUR_NOTION_API_CREDENTIAL_NAME]"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "534e917b-f881-4fa2-904b-3c8a7bb67084",
      "name": "If2",
      "type": "n8n-nodes-base.if",
      "position": [
        2816,
        560
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "b73a48f5-cbc2-4885-9e4e-115b6a74f320",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.body.entry[0].changes[0].value.item }}",
              "rightValue": "comment"
            },
            {
              "id": "59f72c78-dd87-47f4-8c69-328013f52a4f",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.body.entry[0].changes[0].value.verb }}",
              "rightValue": "add"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "e808bf8f-d20d-4ed5-ac4a-fd7dd7576b60",
      "name": "条件3",
      "type": "n8n-nodes-base.if",
      "position": [
        4768,
        848
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "3e37d022-3aff-4906-8aa6-57b287222dac",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.reply }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "8fd26449-f990-43db-bf9e-7dfe0c306084",
      "name": "删除评论1",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        4784,
        1088
      ],
      "parameters": {
        "node": "={{ $('Webhook1').item.json.body.entry[0].changes[0].value.comment_id }}",
        "options": {
          "queryParameters": {
            "parameter": [
              {
                "name": "is_hidden",
                "value": "true"
              }
            ]
          }
        },
        "graphApiVersion": "v23.0",
        "httpRequestMethod": "POST"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "[YOUR_FACEBOOK_API_CREDENTIAL_ID]",
          "name": "[YOUR_FACEBOOK_API_CREDENTIAL_NAME]"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ebdc35ce-6f95-4bdd-91e7-89e5c5840e00",
      "name": "代码2",
      "type": "n8n-nodes-base.code",
      "position": [
        3248,
        544
      ],
      "parameters": {
        "jsCode": "const fullId = $json.comment_id;\nreturn [{\n  json: {\n    ...$json,\n    comment_id_raw: fullId.split('_').pop()  // keep only the last part\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "7dbbc96b-c5b7-4d78-9bac-7305436e27c6",
      "name": "消息",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        5520,
        352
      ],
      "parameters": {
        "url": "=https://graph.facebook.com/v23.0/{{ $('Parse Comms').item.json.page_id }}/messages",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "recipient.comment_id",
              "value": "={{ $('Parse Comms').item.json.comment_id }}"
            },
            {
              "name": "message.text",
              "value": "={{ $('Separate rep&sent').item.json.dm_message }}"
            }
          ]
        },
        "nodeCredentialType": "facebookGraphApi"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "[YOUR_FACEBOOK_MESSAGES_API_CREDENTIAL_ID]",
          "name": "[YOUR_FACEBOOK_MESSAGES_API_CREDENTIAL_NAME]"
        }
      },
      "typeVersion": 4.2,
      "alwaysOutputData": false
    },
    {
      "id": "8525ac2e-1ef7-44d0-97f1-bc9a1963f0be",
      "name": "消息1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        5648,
        832
      ],
      "parameters": {
        "url": "=https://graph.facebook.com/v23.0/{{ $('Parse Comms').item.json.page_id }}/messages",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"recipient\": {\n    \"comment_id\": \"{{ $('Parse Comms').item.json.comment_id }}\"\n  },\n  \"message\": {\n    \"text\": \"{{ $json.dm_message }}\"\n  }\n}\n ",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "facebookGraphApi"
      },
      "credentials": {
        "facebookGraphApi": {
          "id": "[YOUR_FACEBOOK_MESSAGES_API_CREDENTIAL_ID]",
          "name": "[YOUR_FACEBOOK_MESSAGES_API_CREDENTIAL_NAME]"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "6406e117-bcfe-46fc-8f4b-5b0774927387",
      "name": "条件判断4",
      "type": "n8n-nodes-base.if",
      "position": [
        5264,
        336
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "1195e00d-4cc8-45f5-8970-e6a79c169b03",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('Separate rep&sent').item.json.sentiment }}",
              "rightValue": "complement"
            }
          ]
        }
      },
      "typeVersion": 2.2
    }
  ],
  "active": false,
  "pinData": {
    "Webhook1": [
      {
        "json": {
          "body": {
            "entry": [
              {
                "id": "[YOUR_PAGE_ID]",
                "time": 1756308512,
                "changes": [
                  {
                    "field": "feed",
                    "value": {
                      "from": {
                        "id": "[SAMPLE_USER_ID]",
                        "name": "[SAMPLE_USER_NAME]"
                      },
                      "item": "comment",
                      "post": {
                        "id": "[SAMPLE_POST_ID]",
                        "status_type": "added_photos",
                        "is_published": true,
                        "updated_time": "2025-08-27T15:28:27+0000",
                        "permalink_url": "[SAMPLE_POST_URL]",
                        "promotion_status": "ineligible"
                      },
                      "verb": "add",
                      "message": "[SAMPLE_COMMENT_MESSAGE]",
                      "post_id": "[SAMPLE_POST_ID]",
                      "parent_id": "[SAMPLE_PARENT_ID]",
                      "comment_id": "[SAMPLE_COMMENT_ID]",
                      "created_time": 1756308507
                    }
                  }
                ]
              }
            ],
            "object": "page"
          },
          "query": {},
          "params": {},
          "headers": {
            "host": "[YOUR_WEBHOOK_HOST]",
            "accept": "*/*",
            "user-agent": "Webhooks/1.0 (https://fb.me/webhooks)",
            "content-type": "application/json",
            "content-length": "781",
            "accept-encoding": "gzip",
            "x-forwarded-for": "[IP_ADDRESS]",
            "x-hub-signature": "[WEBHOOK_SIGNATURE]",
            "x-forwarded-host": "[YOUR_WEBHOOK_HOST]",
            "x-forwarded-proto": "https",
            "x-hub-signature-256": "[WEBHOOK_SIGNATURE_256]"
          },
          "webhookUrl": "[YOUR_WEBHOOK_URL]",
          "executionMode": "production"
        }
      }
    ]
  },
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "[YOUR_VERSION_ID]",
  "connections": {
    "If2": {
      "main": [
        [
          {
            "node": "Parse Comms",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If3": {
      "main": [
        [
          {
            "node": "Reply1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Delete Comms1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If4": {
      "main": [
        [],
        [
          {
            "node": "Messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code2": {
      "main": [
        [
          {
            "node": "Check Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply": {
      "main": [
        [
          {
            "node": "Add to DB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply1": {
      "main": [
        [
          {
            "node": "Delete Comms",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Comment": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Separate rep&sent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch KB": {
      "main": [
        [
          {
            "node": "Arrange KB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Messages": {
      "main": [
        [],
        []
      ]
    },
    "Webhook1": {
      "main": [
        [
          {
            "node": "If2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add to DB": {
      "main": [
        [
          {
            "node": "If4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add to DB1": {
      "main": [
        [
          {
            "node": "Messages1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Arrange KB": {
      "main": [
        [
          {
            "node": "Who's there?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Comms": {
      "main": [
        [
          {
            "node": "Code2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Appropriate?": {
      "main": [
        [
          {
            "node": "Reply",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "If3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Comms": {
      "main": [
        [
          {
            "node": "Add to DB1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Who's there?": {
      "main": [
        [],
        [
          {
            "node": "Comment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Database": {
      "main": [
        [
          {
            "node": "Fetch KB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Separate rep&sent": {
      "main": [
        [
          {
            "node": "Appropriate?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

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

需要付费吗?

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

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

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

作者
Abdullah Alshiekh

Abdullah Alshiekh

@abdullah01

🚀 Automation pro building AI-powered workflows with n8n. 💼 Special focus on real use cases 🔧 Love clean, flexible, and business-ready automations.

外部链接
在 n8n.io 查看

分享此工作流