How Instagram comment-to-DM works: build the flow yourself
The short version
You comment one word under a reel and a DM with a link shows up. Nobody read your comment. Instagram passed it to a server the creator owns, and that server answered. Tools like ManyChat set this up for you. This page is the same flow, built by hand on a free developer app, on an Instagram account you own.
The one rule that shapes everything: a comment alone does not give the account permission to see who you are. It can send exactly one private reply. Only when you reply or tap a button does the account get a 24-hour window to message you and a field that says whether you follow it.
| Step | What happens | Where it lives in the API |
|---|---|---|
| 1. Comment | Instagram sends the new comment to your server | comments webhook field |
| 2. Private reply | Your server sends one message tied to that comment, within 7 days | POST /<IG_ID>/messages with recipient: {comment_id} |
| 3. Your tap or reply | Opens a 24-hour window and gives consent | messages / messaging_postbacks webhook |
| 4. Follow check | Server reads one field on you | GET /<IGSID>?fields=is_user_follow_business |
| 5a. True | Server sends the link | Send API, text message |
| 5b. False | Server asks you to follow, then checks the same field again | Send API, then step 4 again |
What you need first
- An Instagram professional account (business or creator). A personal account will not work.
- A free developer app with Instagram login added as a product.
- Standard Access (the default) is enough for an account you own or manage. Advanced Access (app review plus business verification) is only for serving other people's accounts.
- A public HTTPS address for your webhook (a small server, or a serverless function).
Permissions to request, in the app dashboard:
| Permission | Why |
|---|---|
instagram_business_basic |
Read the account, needed for the comments webhook |
instagram_business_manage_comments |
Receive comment events |
instagram_business_manage_messages |
Send private replies and DMs, receive message events |
The limits to design around
| Limit | Number |
|---|---|
| Private replies per comment | exactly 1 |
| Time to send a private reply | within 7 days of the comment |
| Follow-up messages | only after the user replies or taps, within 24 hours of that |
| Private replies per hour, per account (posts and reels) | 750 |
| Send API calls for text | 100 per second |
Checklist
- Convert the Instagram account to professional.
- Create the developer app, add Instagram login, request the three permissions above.
- Stand up a public HTTPS endpoint. Answer the webhook verification handshake, and check the signature on every event.
- Subscribe the account to
comments,messagesandmessaging_postbacks. - On a comment containing your keyword, store the
comment_idand send the private reply. - Make that private reply carry one button, for example "Send me the link". The tap comes back as a postback and opens your 24-hour window.
- On the postback, read
is_user_follow_businessfor that user. - True: send the link. False: send a message with two buttons ("Visit profile", "I'm following"), and run step 7 again when they tap the second one.
- Fallback if a button tap ever does not count as consent for you: ask the user to reply with any word, and treat that reply as the opener.
Or skip the code: self-host OpenReply
OpenReply is an open-source (MIT) ManyChat alternative that already does every step above, follow gate included: the DM asks the commenter to follow, and on their tap it checks is_user_follow_business and re-asks until they do. It runs on the official Instagram API with Instagram login, no password and no scraping. About 3.3k stars on GitHub, last updated 2026-10-29.
| Piece | What you run |
|---|---|
Web app (dashboard, /api/webhook, /api/instagram/callback) |
Vercel |
Worker (npm run worker, always on) |
Railway or any always-on host |
| Database + queue | PostgreSQL and Redis (Redis must support blocking commands) |
| Login emails | Resend |
Setup, start to finish
- Fork and clone
github.com/diwenne/openreply. Locally:docker-compose up -d, thennpm run db:generate,npm run db:migrate,npm run devandnpm run worker. - Create the developer app: type Business, use case "Manage messaging and content on Instagram" (not the Facebook login or marketing products).
- Add your Instagram account as a tester under App roles, then accept the invite in Instagram: Edit profile → Apps and websites.
- Set the OAuth redirect to
https://<your-domain>/api/instagram/callback. - Fill the environment variables from
.env.example:DATABASE_URL,REDIS_URL,NEXTAUTH_URL,NEXTAUTH_SECRET,CRON_SECRET,ENCRYPTION_KEY(64 hex characters, the same on web and worker),RESEND_API_KEY,EMAIL_FROM,INSTAGRAM_APP_ID,INSTAGRAM_APP_SECRET,FACEBOOK_APP_SECRET,WEBHOOK_VERIFY_TOKEN. SetALLOWED_EMAILSto your own email, or anyone can sign up to your copy. - Deploy: web app to Vercel, worker + Postgres + Redis to Railway.
- Webhook: callback
https://<your-domain>/api/webhookwith your verify token; subscribe tocommentsandmessages. - Switch the app to Live. In development mode only the console's Test button sends events.
- Sign in to your dashboard, connect Instagram, create an automation: keyword, the reel, the follow-gate message and the link.
- Test it from a second account: comment the keyword, tap the button, check the follow gate both ways.
| Gotcha | Fix |
|---|---|
| Button taps fail with "not the thread owner" | An old DM tool (ManyChat or similar) is still connected: remove it from the account's partner apps |
| Comments missed while the server was down | The worker sweeps for missed comments every 5 minutes |
| A spike of comments | It queues over the 750-an-hour private reply cap instead of dropping them |
| Running it for client accounts | Needs Advanced Access (app review + business verification); your own account never does |
Other open-source options: ZernFlow (visual flow builder, many platforms), openinstadm (small comment-to-DM only), InstaAuto (comments, DMs, story replies).
Copy these prompts
Paste them into Claude Code (or any AI that can see your project).
1. Scaffold the webhook
Build a small HTTPS server (Node, no framework beyond what is needed) that handles the Instagram webhook handshake (GET with hub.challenge and verify token) and receives POST events. Verify the X-Hub-Signature-256 header with my app secret before doing anything. Log the `comments`, `messages` and `messaging_postbacks` events and respond 200 fast. Keep secrets in environment variables.
2. Send the one private reply
When a comment event contains the keyword in COMMENT_KEYWORD, call POST /<IG_ID>/messages on graph.instagram.com with recipient {comment_id} and a message that has one button "Send me the link". Remember that only one private reply is allowed per comment, so keep a table of comment_ids already answered and never send twice. Handle the case where the comment is older than 7 days.
3. The follow gate
On the postback from that button, call GET graph.instagram.com/<IGSID>?fields=is_user_follow_business and branch: if true send the link as a text message; if false send a message with two buttons, "Visit profile" and "I'm following", and when "I'm following" comes back, run the check again. Stop after three rounds so it can never loop forever.
If you are building…
- A creator giveaway or lead magnet: keep the keyword list short and put the link in a config file, not in code.
- Something for clients: you will need Advanced Access, which means app review and business verification. Start that early, it takes the longest.
- Something high volume: queue your sends. 750 private replies an hour is a hard ceiling, and a spike of comments will hit it.
Run this on your codebase
Review my Instagram comment-to-DM code against these rules: one private reply per comment_id, private reply sent within 7 days, follow-up messages only inside the 24-hour window after the user's reply or tap, the follow check done only after consent, webhook signatures verified, secrets only in environment variables, sends rate limited under 750 private replies per hour. List each rule as pass or fail with the file and line, and the smallest fix for every fail.
Facts on this page were checked against the Instagram platform developer docs (private replies, messaging API, user profile API and webhook fields) on 2026-11-17.