用 n8n 以 AI 回覆 Instagram 留言與私訊
n8n 工作流程分三步以 AI 回覆 Instagram 留言與私訊:Webhook 節點接收 easyCoexistence 轉發的每則留言或私訊(附簽名);AI Agent 節點撰寫回覆;再由 easyCoexistence 的 MCP 工具或 HTTP Request 節點,透過 Instagram 官方 API 發出回覆,可以是公開回覆、私人回覆或私訊回覆。easyCoexistence 自動化亦可在不使用工作流程的情況下回覆。
Instagram 允許應用程式在大多數用戶操作(例如對方自己發出的訊息)之後,回覆私訊的時限。
在留言後 7 天內,私人回覆可向留言者發送的內容;超過此期限,須對方先回覆才可再發送。
Meta 每個 Instagram 專業帳戶允許對帖文和 Reels 留言發出的私人回覆數量。
一則 Instagram 私訊最多可承載的文字量(以 UTF-8 計),因此重音字母和表情符號會佔用更多空間。
n8n 的 MCP Client Tool 節點的一種認證方式;該節點讓 AI Agent 使用遠端 MCP 伺服器的工具。
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,其中 entry 為網絡原樣傳來的事件。留言以 change 形式傳來,其 field 為 comments,並包含留言的 id 與文字、from 中的作者,以及 media 中的帖文;私訊則以 messaging 傳來,包含發送者的 ID 與文字。easyCoexistence 會等候 8 秒以取得回應,且不會重試,因此請保持 Respond on Immediately。
{
"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 所示範的格式。
// 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 設為該項目的類型、account_id、ID 與文字。然後決定由哪個節點發出回覆。
AI 代理可以自行回覆:加入 MCP Client Tool,端點設為 https://easycoexistence.com/api/mcp,傳輸方式選 HTTP Streamable,認證選 OAuth2;在 Tools to Include 中選擇 Selected,並勾選以下工具。或者由代理只負責撰寫,再由固定節點發出回覆:使用 MCP Client 節點執行 reply_to_comment 或 send_social_dm 並對應好參數。第二種方式讓模型不能自行選擇動作。
Instagram 的規則對 AI 回覆有何影響?
與人手輸入回覆時相同,因此工作流程或代理的指示必須遵守這些規則:
- 私訊:回覆須在對方最後一則訊息後 24 小時內發出。Meta 另設的 7 天 Human Agent 期限,只適用於真人撰寫的回覆。
- 私人回覆:每則留言只能發一則訊息,須在留言後 7 天內發出;若留言者未追蹤該帳戶,訊息會進入「訊息要求」;之後的私人回覆須待對方回覆後才可發出。
- 數量:每個帳戶每小時最多 750 則,用於對帖文與 Reels 留言的私人回覆。
- 長度:每則私訊最多 1,000 位元組的 UTF-8 文字,因此應要求模型撰寫簡短回覆。
- 存取權:帳戶須在 Instagram 應用程式中開啟「允許存取訊息」,路徑為「訊息和限時動態回覆」、「訊息控制」、「已連結的工具」。
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 workflow | easyCoexistence automation | |
|---|---|---|
| Starts on | A forwarded comment or DM, signed | A DM or comment trigger, with or without a keyword |
| Writes the reply | An AI Agent node with your chat model | ai_reply with your Anthropic, OpenAI or OpenRouter key |
| AI reply in public | Yes, with reply_to_comment | Fixed text only, with reply_comment |
| Logic | Branches, lookups and other apps | Up to 12 steps in a straight line |
| Runs on | Your n8n instance | easyCoexistence, with no workflow to host |
設定方法
- Connect the Instagram accountSign in with Instagram in the easyCoexistence dashboard, and allow access to messages in the Instagram app.
- Send its events to n8nPublish a workflow that starts with a Webhook node, then point set_social_webhook_destination at its Production URL.
- 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 只在您測試時監聽該網址;正式網址才是工作流程發布時向 n8n 登記的網址。
- 讓代理存取整個伺服器。在 Tools to Include 中選擇 Selected,並只勾選回覆工具,這樣即使模型誤判留言,也無法發布、刪除或更改自動化。
- 對同一則留言發送第二則私人回覆。Meta 規定每則留言只能發一則訊息,直到對方回覆為止;因此之後的問題應在留言下以公開方式回覆。
- 在工具需要 account_id 的地方傳入 external_id。MCP 工具應使用事件的 account_id;external_id 是該帳戶在 Instagram 上自己的 ID。
easyCoexistence 為您 n8n 工作流程中的 AI 代理提供觸及 Instagram、Facebook、TikTok 等更多渠道客戶的能力,每個渠道均透過其官方 API:為 Webhook 節點提供已簽署的留言與私訊事件,為 AI Agent 節點提供 35 多個 MCP 工具,並提供無需工作流程即可回覆的自動化,所有連接均全天候 24 小時監察。每個連接每月 US$ 9 起,隨連接增加而降至 US$ 0.75,首 3 天免費試用。
常見問題
n8n 代理可以使用哪個 AI 模型?
您連接到 AI Agent 節點的聊天模型,由其供應商按您自己的金鑰計費。easyCoexistence 不對每則回覆收費;回覆透過其工具或 Instagram 的 API 發出。
同一個工作流程能否回覆 Facebook 留言與 Messenger 訊息?
可以。Facebook 專頁以相同的封裝格式轉發留言與 Messenger 訊息,留言以 feed 的 change 形式傳來,其 item 為 comment,同樣的工具可回覆。TikTok 留言也會傳來,回覆則為公開回覆。
easyCoexistence 會保存留言與私訊嗎?
轉發的事件會原樣傳遞,不作副本。若帳戶設有自動化,訊息文字會保留 7 天,自動化執行記錄則保留 30 天。
在 n8n 中為一個 Instagram 帳戶使用 easyCoexistence 要花多少錢?
每個連接每月 US$ 9 起,隨連接增加而降至 US$ 0.75,各網絡收費相同。MCP 伺服器、轉發事件與自動化均包含在內,首 3 天免費試用。
繼續閱讀
兩分鐘內連接您的第一個頻道。
無需等待平台審核。連接 WhatsApp、Instagram、TikTok 或其他頻道,然後請您的 AI 發佈貼文、回覆訊息或匯報數據,並看着它運作。
- 免費試用 3 天
- 隨時取消
- 只用官方 API
- 24/7 監察
驗證日期