Comment to DM Automation API: Build Instagram Auto-DMs in Code
Zernio's comment-to-DM automation lets developers build Instagram and Facebook auto-reply flows with a single API call. Get keyword triggers, auto-dedup, contact tracking, and real-time webhook processing.
Meta Business Partner
Zernio uses Meta's official Graph API for all comment-to-DM automations. No browser automation, no unofficial tools, no risk to your account.
Key Features
Keyword Triggers
Set exact or contains matching on comment text. Trigger on specific keywords like 'LINK', 'FREE', or 'PRICE', or leave keywords empty to trigger on any comment.
Instant Private Reply DM
When a keyword matches, Zernio sends a DM to the commenter via Meta's Private Reply API within 1-3 seconds. Include links, discount codes, lead magnets, or any text.
Optional Public Comment Reply
Automatically reply to the comment publicly (e.g. 'Check your DMs!') in addition to sending the private DM. Drives engagement and social proof on the post.
Built-in Deduplication
Won't DM the same person twice per automation. Tracks unique commenters automatically so you never spam a user who comments multiple times on the same post.
Automatic Contact Creation
Every commenter who triggers an automation is auto-added to your Zernio contact CRM with tags, custom fields, and cross-platform identity linking. Build your audience automatically.
Real-Time Webhook Processing
Zernio subscribes to Meta's comment webhooks and processes them in real-time. No polling, no delays. Comments are detected and DMs sent within seconds.
Stats and Logging
Track triggered count, DMs sent, DMs failed, and unique contacts per automation. View detailed logs for every trigger event to debug and optimize.
Instagram + Facebook
Comment-to-DM works on both Instagram and Facebook posts. Same API, same webhook flow, same automation object. Every competitor is Instagram-only.
How It Works
- 1.Create an automation via APIPOST to /api/v1/comment-automations with your account ID, keywords, DM message, and optional public reply. One API call, done in seconds.
- 2.User comments on your postWhen someone comments a matching keyword on any of your posts or Reels, Zernio's webhook listener detects it in real-time via Meta's Graph API.
- 3.DM sent automaticallyZernio sends a private DM to the commenter within 1-3 seconds, optionally posts a public reply, creates a contact in your CRM, and logs the event.
Why Developers Choose API Over No-Code
Embed in Your Own Product
ManyChat and Inro are end-user tools. With Zernio's API, you can build comment-to-DM as a feature inside your own SaaS, white-label it, and offer it to your customers.
Programmatic Control
Create, update, pause, and delete automations via API. No manual clicking through a GUI. Integrate with your CI/CD pipeline, cron jobs, or admin dashboard.
No Per-Contact Billing
ManyChat charges $0.025 per contact with unpredictable overages. One viral post can double your bill. Zernio charges per social account, so your costs stay flat.
Built-in Contact CRM
Every commenter becomes a contact with tags, custom fields, and cross-platform identity. Build segmented audiences automatically from comment engagement.
Works with Reels, Feed Posts, and Carousels
Instagram Reels are treated as posts by Meta's API. The same comment webhook and DM endpoints work for Reels, feed posts, carousels, and Stories.
Meta-Approved and Safe
Uses Meta's official Private Reply API, not browser automation or unofficial tools. Your account stays safe. Zernio is a Meta Business Partner.
Code Examples
One API call to set up a keyword-triggered comment-to-DM automation. When someone comments 'guide', 'free', or 'link' on any of your posts, they instantly receive a DM with your link.
const response = await fetch('https://zernio.com/api/v1/comment-automations', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
accountId: 'your-instagram-account-id',
name: 'Free Guide Giveaway',
keywords: ['guide', 'free', 'link'],
matchMode: 'contains',
dmMessage: 'Thanks for your interest! Here is your free guide: https://example.com/guide',
commentReply: 'Check your DMs!'
})
});
const automation = await response.json();
console.log(automation.id); // Use this ID to update, pause, or view logsFetch all your automations with their performance stats: total triggers, DMs sent, DMs failed, and unique contacts reached.
const response = await fetch('https://zernio.com/api/v1/comment-automations', {
headers: { 'Authorization': 'Bearer YOUR_API_KEY' }
});
const { data } = await response.json();
data.forEach(automation => {
console.log(automation.name);
console.log(' Triggered:', automation.stats.triggered);
console.log(' DMs sent:', automation.stats.dmsSent);
console.log(' Unique contacts:', automation.stats.uniqueContacts);
});If you prefer building directly on Meta's API, here is the webhook handler and Private Reply call. This is what Zernio abstracts away for you.
// 1. Webhook handler for incoming comments
app.post('/webhook/instagram', (req, res) => {
const { entry } = req.body;
for (const page of entry) {
for (const change of page.changes) {
if (change.field === 'comments') {
const comment = change.value;
const text = comment.text.toLowerCase();
// 2. Keyword matching
const keywords = ['guide', 'free', 'link'];
const matches = keywords.some(kw => text.includes(kw));
if (matches) {
// 3. Send DM via Private Reply API
await fetch(
`https://graph.facebook.com/v21.0/${PAGE_ID}/messages`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
recipient: { comment_id: comment.id },
message: { text: 'Here is your free guide: https://...' }
})
}
);
}
}
}
}
res.sendStatus(200);
});
// With Zernio: one API call replaces all of the aboveSupported Platforms
Comment-to-DM automation works on Instagram and Facebook via Meta's Graph API. Both platforms use the same webhook flow and Private Reply endpoint.
See it in action

Detect keywords in comments and trigger DM flows instantly.

Automated conversations that convert commenters into leads.
Common Questions About Comment-to-DM Automation
- What is comment-to-DM automation?
- └Comment-to-DM automation automatically sends a private DM to anyone who comments a specific keyword on your Instagram or Facebook post. It's commonly used for lead magnets, discount codes, and giveaways. Zernio lets you set this up with one API call.
- Does comment-to-DM work on Instagram Reels?
- └Yes. Instagram Reels are treated as posts by Meta's Graph API. The same comment webhooks and DM endpoints work for Reels, feed posts, carousels, and Stories.
- How is Zernio different from ManyChat for comment-to-DM?
- └ManyChat is a no-code tool for end users. Zernio's API is a ManyChat alternative that lets developers embed comment-to-DM as a feature inside their own applications with full programmatic control.
- How fast are DMs sent after a comment?
- └With webhook-based systems like Zernio, DMs are sent within 1-3 seconds of the comment being posted. Zernio subscribes to Meta's real-time webhooks, so there is no polling delay.
- Is comment-to-DM automation safe for my Instagram account?
- └Yes, when using Meta's official API (not browser automation or unofficial tools). Zernio is an official Meta Business Partners using the official Graph API. The Private Reply API is Meta's approved method for sending DMs in response to comments. Unofficial tools that scrape or automate the browser can get your account restricted.
- What is the difference between comment-to-DM and auto-reply to DMs?
- └Comment-to-DM triggers when someone comments on a post and sends them a DM. Auto-reply to DMs triggers when someone sends you a direct message and responds automatically. They are different automation types. Zernio supports both via separate API endpoints.
- How much does comment-to-DM automation cost?
- └Zernio's comment automation is bundled with every connected account (no add-on, no per-contact billing, no per-message fees). ManyChat charges per contact ($0.025/contact overage) which can get expensive with viral posts. Zernio charges per social account with predictable usage-based pricing (no per-message surprises).
Related
Add comment-to-DM to your app today
One API call to create an automation. Keyword triggers, auto-dedup, contact CRM, real-time webhooks. No drag-and-drop builder required.

