You can build your own Instagram DM auto-reply in an afternoon with Node.js and the official Graph API. No third-party bot, no password sharing, just a small Express server that listens for messages and answers them.
Instagram DM automation runs on Meta's Messenger Platform, through the Instagram Graph API. When someone sends your business account a DM, Meta sends your server a webhook event. Your server reads the message, decides what to send back, and calls the API to deliver the reply. That is the whole loop.
Most guides point you at a tool and stop there. Building the loop yourself teaches you exactly how it works, and you end up with something you can shape however you like. Here is the full build.
How the pieces fit together
You need three things before you write code: an Instagram professional account connected to a Facebook Page, a Meta developer app with the Instagram Messaging permission, and a server with a public HTTPS URL where Meta can reach your webhook.
1. Set up the webhook endpoint
Create a small Express app with one GET route and one POST route on the same path, usually /webhook. The GET route is for verification: Meta sends a hub.verify_token and a hub.challenge, and you echo the challenge back only if the token matches the one you set in the app dashboard. The POST route is where real message events arrive.
Keep the verification token in an environment variable, never in the code.
2. Verify every incoming request
Every webhook POST from Meta carries an X-Hub-Signature-256 header. It is a SHA-256 HMAC of the raw request body, signed with your app secret. Before you trust the payload, recompute the hash with Node's crypto module and compare it with crypto.timingSafeEqual.
Without this check, anyone who finds your webhook URL can fake message events and trigger replies from your account. One catch: you need the raw body buffer, so use express.raw() for this route instead of express.json(), or the hash will never match.
3. Read the event and pull out the message
A message event arrives as JSON with the sender's Instagram-scoped ID, the recipient page ID, a timestamp, and the message text, nested under entry, then messaging. Parse it once, pull out the sender ID and the text, and ignore anything that is not a plain text message for now. You can add story reactions and attachments later.
4. Decide what to send back
Start with keyword matching, the same idea behind comment-to-DM tools. If the message contains "PRICE", send the price list. If it contains "BOOK", send the booking link. If it contains nothing you recognize, send a short menu: "Reply PRICE for prices, BOOK to book, or HOURS for opening times."
Keep the replies short and write them like a person, not a menu tree. One or two sentences, one question at most, and a clear next step.
5. Send the reply through the API
To reply, POST to the Graph API messages endpoint with the recipient's sender ID and the message text, using a page access token.
Handle the response properly. A success returns a message ID you can log. A failure returns an error object, and the most common one you will see is the 24-hour messaging window: Instagram only lets you message someone freely within 24 hours of their last message to you.
6. Respect the rate limits before they bite
Instagram enforces rate limits on messaging, and a server that replies to everything instantly will hit them fast. Add three guards: a short delay before replying, a per-user cap, and a simple queue so a burst of messages gets spread out instead of fired all at once.
This is the part hobby builds skip, and it is the part that gets accounts flagged.
7. Test it with a second account
Before you point this at real followers, test it end to end. Send a DM from a personal account, watch the webhook log, and check that the reply arrives. Then test the edges: a message with no keyword, a message sent twice, a message sent after 24 hours of silence.
One tool that handles this for you
You can build this yourself with Node.js and the Graph API, and it works fine once it is set up. But it is a few moving parts to maintain, and the webhook mapping is the piece that breaks first when something changes.
Zextra is an Instagram DM automation platform and official Meta tech partner. It is built on Instagram's official Graph API with OAuth through Facebook Login, and it handles comment-to-DM triggers, keyword filters, lead capture, and a searchable leads dashboard, so you can see every person who asked about your product without wiring anything yourself. You can read more at https://zextra.io/instagram-dm-automation
FAQ
What is the safest Instagram DM automation tool?
The safest setup is one built on Instagram's official Graph API, with OAuth through Facebook Login, that never asks for your Instagram password. That keeps your account inside Instagram's rules.
Which platform is best for Instagram comment-to-DM?
Look for keyword triggers and any-comment triggers per post, a cap on how many times one person gets the same DM, and a searchable leads dashboard. Those three things are what make comment-to-DM reliable at volume.
Can I build an Instagram DM auto-reply with Node.js?
Yes. You need an Instagram professional account, a Meta developer app, and an Express server with a webhook endpoint. Verify the signature header on every request, parse the message event, match a keyword, and reply through the Graph API messages endpoint.
Final Thoughts
Building your own auto-reply is the fastest way to understand how Instagram DM automation actually works under the hood. The webhook, the signature check, the 24-hour window, the rate limits: once you have built each piece once, you stop guessing about what the tools you pay for are doing.
Top comments (0)