Reply to Instagram comments and DMs with AI in n8n
An n8n workflow replies to Instagram comments and DMs with AI in three steps: a Webhook node receives each comment or DM that easyCoexistence forwards, signed; an AI Agent node writes the reply; and easyCoexistence's MCP tools or an HTTP Request node deliver it through Instagram's official API, as a public reply, a private reply or a DM reply. easyCoexistence automations can also reply without a workflow.
How long Instagram lets an app reply to a DM after most user actions, such as the person's own message.
What a private reply can send a commenter, within 7 days of the comment; more only once they respond.
Private replies Meta allows per Instagram professional account to comments on posts and Reels.
The most text one Instagram DM carries, in UTF-8, so accents and emoji use more of it.
An authentication method of n8n's MCP Client Tool, the node that gives an AI Agent a remote MCP server's tools.
How long an easyCoexistence automation's call_webhook step waits for the reply your workflow returns.
How do Instagram comments and DMs reach n8n?
As POST requests to a Webhook node. Turn on its Raw Body option, publish the workflow and copy the Production URL. Point the Instagram account at it with set_social_webhook_destination, asked of Claude or ChatGPT or run once from an MCP Client node, or with PUT /api/v1/channels/:id/webhook on the Partner API. The account's signing secret comes back once, so store it for the signature check.
Each event carries platform, account_id, external_id and entry, the network's event unchanged. A comment comes as a change whose field is comments, with the comment's id and text, the author in from and the post in media; a DM comes in messaging, with the sender's ID and the text. easyCoexistence waits 8 seconds for an answer and does not retry, so leave 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" }
}
}
]
}
}How does the workflow sort comments from DMs and skip its own?
With a signature check, then one Code node. Read the body as text with an Extract From File node, compare X-EC-Signature, an HMAC-SHA256 of the timestamp, a dot and the raw body, using a Crypto node and an If node, as the n8n social media guide shows, and pass the event on. The Code node below turns each event into one item per comment or DM, in the same shape.
It drops what the account wrote itself: its public replies come back as comments from its own ID, and its DMs come back as echoes. It reads comments from entry.changes and also from a field and value placed on the entry itself, as Meta's example for Instagram Login shows them.
// 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;How does the AI Agent node write and send the reply?
From a System Message and the item. Connect a chat model, put what customers ask about in the System Message, such as prices, sizes, hours and links, and set the Prompt by expression to the item's kind, account_id, ID and text. Then decide which node replies.
The agent can reply by itself: attach an MCP Client Tool with https://easycoexistence.com/api/mcp as the endpoint, HTTP Streamable and OAuth2, and under Tools to Include choose Selected and tick the tools below. Or the agent only writes and a fixed node replies: an MCP Client node running reply_to_comment or send_social_dm with the arguments mapped. The second way never lets the model pick the action.
What do Instagram's rules mean for AI replies?
The same as for a person typing, so the workflow, or the agent's instructions, has to keep to them:
- DMs: a reply goes out within 24 hours of the person's last message. Meta's separate 7-day Human Agent window is meant for replies a person writes.
- Private replies: one message per comment, within 7 days of it, landing in Requests when the commenter does not follow the account; more only after they respond.
- Volume: up to 750 private replies an hour per account to comments on posts and Reels.
- Length: at most 1,000 bytes of UTF-8 text per DM, so ask the model for short replies.
- Access: the account turns on Allow Access to Messages in the Instagram app, under Messages and story replies, Message controls, Connected Tools.
When can easyCoexistence automations do this without n8n?
When a straight line of steps is enough. An automation on the Instagram account starts on a DM, any or by keyword, a first message or outside your hours, or on a comment, any or by keyword, on one post or all of them. Its ai_reply step writes the reply with your own Anthropic, OpenAI or OpenRouter key. It checks the 24-hour window, sends one private reply per comment, holds AI replies to 10 per chat an hour by default and keeps each run's log for 30 days, and test_automation tries it without sending.
On a comment, ai_reply replies by DM, as the comment's private reply, while reply_comment posts fixed text in public. For an AI reply posted under the comment, or for branches, use n8n; a call_webhook step can also hand the message to an n8n Webhook node and send the reply it returns.
| 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 |
How to set it up
- 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.
Common mistakes
- Pointing the account at the Webhook node's Test URL. n8n listens there only while you test; the Production URL is the one it registers when the workflow is published.
- Exposing the whole server to the agent. Under Tools to Include, choose Selected and tick only the reply tools, so a model that misreads a comment cannot publish, delete or change automations.
- Sending a second private reply to the same comment. Meta allows one message per comment until the person writes back, so reply to further questions in public under the comment.
- Passing external_id where a tool expects account_id. The MCP tools take the event's account_id; external_id is the account's own ID on Instagram.
easyCoexistence gives the AI agents in your n8n workflows reach to customers on Instagram, Facebook, TikTok and more channels, each through its official API: signed comment and DM events for a Webhook node, 35+ MCP tools for an AI Agent node, and automations that reply with no workflow at all, with every connection monitored 24/7. US$ 9 to US$ 0.75 per connection per month, falling as you add connections, with the first 3 days free.
easyCoexistence is a multichannel API and MCP server that connects AI agents such as Claude and ChatGPT to WhatsApp, Instagram, TikTok, Facebook and more. On WhatsApp it uses Coexistence: the business keeps using its number in the WhatsApp Business app while the AI works through Meta's official API.
Frequently asked questions
Which AI model can the n8n agent use?
The chat model you connect to the AI Agent node, billed by its provider to your own key. easyCoexistence charges no fee per reply; the replies go out through its tools or Instagram's API.
Can the same workflow reply to Facebook comments and Messenger messages?
Yes. A Facebook Page forwards comments and Messenger messages in the same envelope, a comment arriving as a feed change with item comment, and the same tools reply to them. TikTok comments arrive too, and replies to them are public.
Does easyCoexistence keep the comments and DMs?
Forwarded events are passed on without a copy. With an automation on the account, message text is kept for 7 days and automation run logs for 30 days.
How much does easyCoexistence cost for an Instagram account in n8n?
US$ 9 to US$ 0.75 per connection per month, falling as you add connections, the same on each network. The MCP server, the forwarded events and the automations are included, with the first 3 days free.
Keep reading
Connect your first channel in two minutes.
No platform reviews to wait for. Connect WhatsApp, Instagram, TikTok or another channel, then ask your AI to post, reply or report, and watch it work.
- 3 days free
- Cancel any time
- Official APIs only
- Monitored 24/7
Verified on