8
n8n 中文网amn8n.com

AI 社交媒体自动回复插件(Instagram、Facebook 和 WhatsApp)

中级

这是一个Support Chatbot, AI Chatbot领域的自动化工作流,包含 12 个节点。主要使用 Code, Switch, Webhook, WhatsApp, HttpRequest 等节点。 基于 Llama 3.2 的 AI 社交媒体消息自动回复系统(Instagram、Facebook、WhatsApp)

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "CiNwrwKWPu3H2Je8",
  "meta": {
    "instanceId": "dd69efaf8212c74ad206700d104739d3329588a6f3f8381a46a481f34c9cc281"
  },
  "name": "AI 社交媒体自动回复插件(Instagram、Facebook 和 WhatsApp)",
  "tags": [],
  "nodes": [
    {
      "id": "a6f84e67-3376-41fe-9f84-79c20b9abd5e",
      "name": "WhatsApp 触发器",
      "type": "n8n-nodes-base.whatsAppTrigger",
      "position": [
        0,
        0
      ],
      "webhookId": "0d34f8e7-7cae-4aac-8b56-c1ea698bde5e",
      "parameters": {
        "options": {},
        "updates": [
          "messages"
        ]
      },
      "credentials": {
        "whatsAppTriggerApi": {
          "id": "jt1wbDtaEmlHpPFc",
          "name": "WhatsApp -test"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "03c454b3-c54a-4137-8f0b-70e77f04eb6a",
      "name": "Instagram Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        0,
        200
      ],
      "webhookId": "1366ec6d-04d2-4019-93d6-c3578fa106ba",
      "parameters": {
        "path": "1366ec6d-04d2-4019-93d6-c3578fa106ba",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "e7f9f0b3-62a1-4efb-b29f-a80a59e57781",
      "name": "Facebook Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        0,
        400
      ],
      "webhookId": "ead9ab3d-3c85-45bd-800c-85661b2d4c48",
      "parameters": {
        "path": "ead9ab3d-3c85-45bd-800c-85661b2d4c48",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "3f48de85-02f1-4227-b913-ef5fa501a9ff",
      "name": "消息处理器",
      "type": "n8n-nodes-base.code",
      "position": [
        220,
        200
      ],
      "parameters": {
        "jsCode": "const inputData = $input.first().json;\n\n// WhatsApp Message Processing - Based on your actual data structure\nif (inputData.messaging_product === 'whatsapp' && inputData.messages && inputData.messages[0]) {\n  return {\n    platform: 'whatsapp',\n    senderId: inputData.contacts[0].wa_id,\n    senderName: inputData.contacts[0].profile.name || 'User',\n    message: inputData.messages[0].text.body,\n    messageId: inputData.messages[0].id,\n    timestamp: inputData.messages[0].timestamp\n  };\n}\n\n// Instagram DM Processing\nif (inputData.object === 'instagram' && inputData.entry && inputData.entry[0]) {\n  const entry = inputData.entry[0];\n  const messaging = entry.messaging ? entry.messaging[0] : null;\n  \n  if (messaging) {\n    return {\n      platform: 'instagram',\n      senderId: messaging.sender.id,\n      senderName: 'Instagram User',\n      message: messaging.message.text,\n      messageId: messaging.message.mid,\n      timestamp: messaging.timestamp || Date.now()\n    };\n  }\n}\n\n// Facebook Messenger Processing\nif (inputData.object === 'page' && inputData.entry && inputData.entry[0]) {\n  const entry = inputData.entry[0];\n  const messaging = entry.messaging ? entry.messaging[0] : null;\n  \n  if (messaging) {\n    return {\n      platform: 'facebook',\n      senderId: messaging.sender.id,\n      senderName: 'Facebook User',\n      message: messaging.message.text,\n      messageId: messaging.message.mid,\n      timestamp: messaging.timestamp\n    };\n  }\n}\n\n// Default WhatsApp fallback based on your current data\nreturn {\n  platform: 'whatsapp',\n  senderId: inputData.contacts ? inputData.contacts[0].wa_id : 'unknown',\n  senderName: inputData.contacts ? (inputData.contacts[0].profile.name || 'User') : 'Unknown User',\n  message: inputData.messages ? inputData.messages[0].text.body : 'Hello',\n  messageId: inputData.messages ? inputData.messages[0].id : 'unknown',\n  timestamp: inputData.messages ? inputData.messages[0].timestamp : Date.now()\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "f7cbdab7-7712-4dbd-a384-2e93cec174ce",
      "name": "AI 旅行助手",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        440,
        200
      ],
      "parameters": {
        "text": "={{ $json.message }}",
        "options": {
          "systemMessage": "=You are {{ assistant\\_name }}, a professional, friendly, and smart virtual assistant for {{ business\\_name }}.\nYour role is to handle conversations across WhatsApp, Instagram DMs, and Facebook Messenger with clarity, relevance, and an engaging tone.\n\nYou can assist with:\n\n* Answering any type of message (questions, feedback, greetings, etc.)\n* Offering help, recommendations, or information based on user intent\n* Generating leads and qualifying users for follow-up\n* Providing support, updates, or guidance on services/products\n* Driving user engagement with helpful and human-like interactions\n\n---\n\n**Current Platform:** `{{ $json.platform }}`\n**User:** `{{ $json.senderName }}`\n\nAdapt your tone and message style to the platform:\n\n* **WhatsApp** → Friendly and professional\n* **Instagram** → Trendy, casual, and emoji-friendly 😄\n* **Facebook** → Warm and informative\n\nStart new conversations with a personalized greeting using their name when available.\n\n**Example Greetings:**\n\n* WhatsApp: `\"Hi {{ $json.senderName }}! 👋 I'm {{ assistant_name }} from {{ business_name }}. How can I assist you today?\"`\n* Instagram: `\"Hey {{ $json.senderName }}! 💬 I’m {{ assistant_name }} from {{ business_name }} — ready to help or chat! 😊\"`\n* Facebook: `\"Hello {{ $json.senderName }}! 👋 Welcome to {{ business_name }}. I'm {{ assistant_name }} — here to assist you with anything you need!\"`\n"
        },
        "promptType": "define"
      },
      "typeVersion": 1.9
    },
    {
      "id": "138d5a96-77df-4090-9638-f97fefb86077",
      "name": "平台记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        588,
        420
      ],
      "parameters": {
        "sessionKey": "={{ $json.platform }}_{{ $json.senderId }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 150
      },
      "typeVersion": 1.3
    },
    {
      "id": "2511ccf9-d304-4bf5-87c5-a9df08d349fd",
      "name": "Ollama 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "position": [
        400,
        420
      ],
      "parameters": {
        "model": "llama3.2-16000:latest",
        "options": {}
      },
      "credentials": {
        "ollamaApi": {
          "id": "7td3WzXCW2wNhraP",
          "name": "Ollama - test"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2768f9da-efd0-4b4a-9363-efca330bc365",
      "name": "响应路由器",
      "type": "n8n-nodes-base.switch",
      "position": [
        816,
        200
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "df1409ea-c9f3-49db-8211-09ebc3d6a4dc",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "rightType": "any"
                    },
                    "leftValue": "={{ $('Message Processor').item.json.platform }}",
                    "rightValue": "whatsapp"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "3abbb56f-b057-4fee-acbd-b668e8a82f7d",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "rightType": "any"
                    },
                    "leftValue": "={{ $('Message Processor').item.json.platform }}",
                    "rightValue": "instagram"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "fbbe45de-f30a-4fc1-8c97-36c13c4a55fa",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "rightType": "any"
                    },
                    "leftValue": "={{ $('Message Processor').item.json.platform }}",
                    "rightValue": "facebook"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "662582af-b7f0-4019-9aee-acb4d07d8f1e",
      "name": "Instagram 发送器",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1036,
        200
      ],
      "parameters": {
        "url": "=https://graph.facebook.com/v18.0/{{ $('Message Processor').item.json.senderId }}/messages",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {}
          ]
        },
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "Bearer YOUR_INSTAGRAM_ACCESS_TOKEN"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "KCqBydsOZHvzNKAI",
          "name": "Header Auth account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "ed99f2fc-74b7-441b-9811-b106203dd117",
      "name": "Facebook 发送器",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1036,
        400
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v18.0/me/messages",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {}
          ]
        },
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "Bearer YOUR_FACEBOOK_ACCESS_TOKEN"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "KCqBydsOZHvzNKAI",
          "name": "Header Auth account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "c2225425-78df-44da-a5b4-4113dfcfba8c",
      "name": "发送消息",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        1036,
        0
      ],
      "webhookId": "20a10490-a88a-4f19-b262-3e3055884ac5",
      "parameters": {
        "textBody": "={{ $json.output }}",
        "operation": "send",
        "phoneNumberId": "=550325331503475",
        "additionalFields": {},
        "recipientPhoneNumber": "={{ $('Message Processor').item.json.senderId }}"
      },
      "credentials": {
        "whatsAppApi": {
          "id": "b0PxTDPdWzznWnfG",
          "name": "WhatsApp-test "
        }
      },
      "typeVersion": 1
    },
    {
      "id": "fad91265-1b34-4e8a-b6e9-303a7bb9b154",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        -220
      ],
      "parameters": {
        "width": 780,
        "height": 280,
        "content": "## 目的:"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "03c4ca8e-da13-4c0c-84e1-8762522da61d",
  "connections": {
    "Send message": {
      "main": [
        []
      ]
    },
    "AI Travel Agent": {
      "main": [
        [
          {
            "node": "Response Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Facebook Sender": {
      "main": [
        []
      ]
    },
    "Platform Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Travel Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Response Router": {
      "main": [
        [
          {
            "node": "Send message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Instagram Sender",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Facebook Sender",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Facebook Webhook": {
      "main": [
        [
          {
            "node": "Message Processor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Instagram Sender": {
      "main": [
        []
      ]
    },
    "WhatsApp Trigger": {
      "main": [
        [
          {
            "node": "Message Processor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Instagram Webhook": {
      "main": [
        [
          {
            "node": "Message Processor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message Processor": {
      "main": [
        [
          {
            "node": "AI Travel Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ollama Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Travel Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 客服机器人, AI 聊天机器人

需要付费吗?

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

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

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

作者
Oneclick AI Squad

Oneclick AI Squad

@oneclick-ai

The AI Squad Initiative is a pioneering effort to build, automate and scale AI-powered workflows using n8n.io. Our mission is to help individuals and businesses integrate AI agents seamlessly into their daily operations from automating tasks and enhancing productivity to creating innovative, intelligent solutions. We design modular, reusable AI workflow templates that empower creators, developers and teams to supercharge their automation with minimal effort and maximum impact.

外部链接
在 n8n.io 查看

分享此工作流