登录开始免费试用
easyCoexistence 官方 API

用 n8n 与 AI 回复 Instagram 评论和私信

n8n 工作流分三步,用 AI 回复 Instagram 评论和私信:Webhook 节点接收 easyCoexistence 转发的每条已签名评论或私信;AI Agent 节点撰写回复;再由 easyCoexistence 的 MCP 工具或 HTTP Request 节点,通过 Instagram 官方 API 以公开回复、私密回复或私信回复的形式发出。easyCoexistence 自动化也可以在没有工作流的情况下回复。

24 hours

Instagram 允许应用在大多数用户操作(如对方自己发送的消息)之后回复私信的时限。

1 message

评论后 7 天内,私密回复可发送给评论者的内容;对方回复后才能发送更多。

750 an hour

每个 Instagram 专业账户可对帖子和 Reels 评论发送的私密回复数量上限。

1,000 bytes

单条 Instagram 私信最多可承载的文本量(UTF-8 编码),重音字符和表情符号占用更多。

OAuth2

n8n 的 MCP Client Tool 所支持的一种身份验证方式,该节点让 AI Agent 可以调用远程 MCP 服务器的工具。

20 seconds

easyCoexistence 自动化中 call_webhook 步骤等待工作流返回回复的时长。

Instagram 评论和私信如何到达 n8n?

以 POST 请求的形式发送到 Webhook 节点。开启其 Raw Body 选项,发布工作流,然后复制 Production URL。使用 set_social_webhook_destination 将 Instagram 账户指向该地址,可以向 Claude 或 ChatGPT 发出请求,也可以通过 MCP Client 节点运行一次;或者在 Partner API 上调用 PUT /api/v1/channels/:id/webhook。账户的签名密钥只返回一次,请妥善保存,以便进行签名校验。

每个事件包含 platform、account_id、external_id 和 entry,即未经修改的网络原始事件。评论以 change 的形式到达,其 field 为 comments,包含评论的 id 和文本,作者位于 from 中,帖子位于 media 中;私信则位于 messaging 中,包含发送者的 ID 和文本。easyCoexistence 会等待 8 秒获取回复,且不会重试,因此请保持 Respond 为 Immediately。

A forwarded Instagram comment, trimmed
{
  "platform": "instagram",
  "account_id": "<ACCOUNT_ID>",
  "external_id": "<INSTAGRAM_ACCOUNT_ID>",
  "entry": {
    "id": "<INSTAGRAM_ACCOUNT_ID>",
    "time": 1793318400,
    "changes": [
      {
        "field": "comments",
        "value": {
          "id": "<COMMENT_ID>",
          "text": "Do you have this in green?",
          "from": { "id": "<INSTAGRAM_SCOPED_ID>", "username": "<USERNAME>" },
          "media": { "id": "<MEDIA_ID>", "media_product_type": "REELS" }
        }
      }
    ]
  }
}

工作流如何区分评论与私信,并跳过自己发出的内容?

先进行签名校验,然后使用一个 Code 节点。使用 Extract From File 节点将请求体读取为文本,按照 n8n 社交媒体指南所示,借助 Crypto 节点和 If 节点,比对 X-EC-Signature 与原始请求体的 HMAC-SHA256 值(计算内容为时间戳、一个点号和原始请求体),然后将事件继续传递。下方的 Code 节点会将每个事件转换为一条评论或私信对应一个项目,格式保持一致。

它会丢弃账户自己写的内容:其公开回复会以来自自身 ID 的评论形式返回,其私信则以 echo 形式返回。它同时从 entry.changes 读取评论,也会读取放在 entry 本身上的 field 和 value,正如 Meta 针对 Instagram Login 的示例所示。

Code node: one item per comment or DM, minus the account's own
// Run Once for All Items. Each input item holds the raw body as text in
// json.data, the Destination Output Field set in Extract From File.
const out = [];
for (const item of $input.all()) {
  const { account_id, external_id: me, entry } = JSON.parse(item.json.data);
  const changes = entry.changes ?? (entry.field ? [{ field: entry.field, value: entry.value }] : []);
  for (const { field, value } of changes) {
    if (field === "comments" && value.from?.id !== me) {
      out.push({ json: { kind: "comment", account_id, comment_id: value.id, post_id: value.media?.id,
        username: value.from?.username, text: value.text ?? "" } });
    }
  }
  for (const m of entry.messaging ?? []) {
    if (m.message?.text && !m.message.is_echo) {
      out.push({ json: { kind: "dm", account_id, recipient_id: m.sender.id, text: m.message.text } });
    }
  }
}
return out;

AI Agent 节点如何撰写并发送回复?

基于 System Message 和该项目。连接聊天模型,在 System Message 中写明客户可能询问的内容,例如价格、尺寸、营业时间和链接;并通过表达式将 Prompt 设置为该项目的 kind、account_id、ID 和文本。然后决定由哪个节点回复。

Agent 可以自行回复:添加一个 MCP Client Tool,端点填写 https://easycoexistence.com/api/mcp,传输方式选择 HTTP Streamable,身份验证选择 OAuth2;在 Tools to Include 中选择 Selected,并勾选下方列出的工具。或者由 Agent 只负责撰写,由固定节点负责回复:使用 MCP Client 节点运行 reply_to_comment 或 send_social_dm 并映射参数。第二种方式始终不让模型自行选择操作。

reply_to_commentA public reply under the comment; with private true, the one DM Meta allows per comment
send_social_dmA DM reply to someone who wrote in the last 24 hours, by their sender ID
hide_commentHides a comment on the account's post, or shows it again
list_social_commentsThe other comments on the post, as context

Instagram 的规则对 AI 回复意味着什么?

与人工输入回复时的规则相同,因此工作流,或 Agent 的指令,必须遵守这些规则:

  • 私信:回复须在对方最后一条消息后 24 小时内发出。Meta 另行设有 7 天的 Human Agent 窗口,仅适用于真人撰写的回复。
  • 私密回复:每条评论只能发送一条消息,且须在评论后 7 天内发出;若评论者未关注该账户,消息会进入 Requests。对方回复后方可发送更多。
  • 频率:每个账户每小时最多可对帖子和 Reels 的评论发送 750 条私密回复。
  • 长度:每条私信最多 1,000 字节的 UTF-8 文本,因此请让模型生成简短的回复。
  • 访问权限:账户需在 Instagram 应用中开启 Allow Access to Messages,路径为 Messages and story replies、Message controls、Connected Tools。

什么情况下 easyCoexistence 自动化无需 n8n 即可完成这些操作?

当一条直线式的步骤足够时。在 Instagram 账户上的自动化可在以下情况启动:收到私信(任意私信、按关键词触发、首条消息,或营业时间外),或收到评论(任意评论、按关键词触发,针对某一条帖子或全部帖子)。其 ai_reply 步骤使用您自己的 Anthropic、OpenAI 或 OpenRouter 密钥撰写回复。它会检查 24 小时窗口,每条评论只发送一条私密回复,默认每个聊天每小时最多 10 条 AI 回复,并将每次运行的日志保留 30 天;test_automation 则会在不发送的情况下进行测试。

对于评论,ai_reply 以私信方式回复,即作为评论的私密回复,而 reply_comment 则会公开发布固定文本。若要在评论下公开发布 AI 回复,或需要分支逻辑,请使用 n8n;call_webhook 步骤也可以将消息交给 n8n 的 Webhook 节点,并发送其返回的回复。

n8n workfloweasyCoexistence automation
Starts onA forwarded comment or DM, signedA DM or comment trigger, with or without a keyword
Writes the replyAn AI Agent node with your chat modelai_reply with your Anthropic, OpenAI or OpenRouter key
AI reply in publicYes, with reply_to_commentFixed text only, with reply_comment
LogicBranches, lookups and other appsUp to 12 steps in a straight line
Runs onYour n8n instanceeasyCoexistence, with no workflow to host

设置方法

  1. Connect the Instagram accountSign in with Instagram in the easyCoexistence dashboard, and allow access to messages in the Instagram app.
  2. Send its events to n8nPublish a workflow that starts with a Webhook node, then point set_social_webhook_destination at its Production URL.
  3. Add the AI AgentGive it a chat model, your business facts as the System Message and an MCP Client Tool with the reply tools.

常见错误

  • 将账户指向 Webhook 节点的 Test URL。n8n 仅在您测试时监听该地址;工作流发布后注册的是 Production URL。
  • 向 Agent 开放整个服务器。在 Tools to Include 中选择 Selected,并只勾选回复类工具,这样即使模型误读评论,也无法发布、删除或修改自动化。
  • 对同一条评论发送第二条私密回复。Meta 规定在对方回复之前,每条评论只能发送一条消息,因此后续问题请在该评论下公开回复。
  • 在需要 account_id 的工具参数中传入了 external_id。MCP 工具接收事件中的 account_id;external_id 是该账户在 Instagram 上自己的 ID。
使用 EasyCoexistence 完成这些操作

easyCoexistence 为您 n8n 工作流中的 AI Agent 提供触达 Instagram、Facebook、TikTok 及更多渠道客户的能力,每个渠道均通过其官方 API 接入:为 Webhook 节点提供已签名的评论和私信事件,为 AI Agent 节点提供 35 多个 MCP 工具,并提供无需工作流即可回复的自动化,所有连接全程监控。每个连接每月 US$ 9 起,最低降至 US$ 0.75,连接越多越便宜,并提供 3 天免费试用。

常见问题

n8n 中的 Agent 可以使用哪种 AI 模型?

由您连接到 AI Agent 节点的聊天模型提供,费用由其提供商按您自己的密钥计费。easyCoexistence 不按每条回复收取费用;回复通过其工具或 Instagram API 发出。

同一个工作流能否回复 Facebook 评论和 Messenger 消息?

可以。Facebook 主页以相同的信封格式转发评论和 Messenger 消息:评论以 feed 变更到达,其 item 为 comment,同样的工具可以回复它们。TikTok 评论同样会到达,对其的回复均为公开回复。

easyCoexistence 会保存评论和私信吗?

转发的事件会被直接传递,不留副本。若账户设有自动化,消息文本保留 7 天,自动化运行日志保留 30 天。

在 n8n 中为一个 Instagram 账户使用 easyCoexistence 需要多少费用?

每个连接每月 US$ 9 起,最低降至 US$ 0.75,连接越多越便宜,各网络收费相同。MCP 服务器、转发事件和自动化均包含在内,并提供 3 天免费试用。

继续阅读

两分钟连接您的第一个渠道。

无需等待平台审核。连接 WhatsApp、Instagram、TikTok 或其他渠道,然后让您的 AI 发布、回复或生成报告,看它如何运作。

  • 免费试用 3 天
  • 随时取消
  • 仅使用官方 API
  • 全天候 24/7 监控

验证时间