Set up Instagram comment-to-DM with OpenReply
If you commented BORING on the learning reel, here’s how to set up the same kind of reply. You’ll connect your Instagram account, choose a keyword, and test that a comment sends the link you promised.
OpenReply is a free, MIT-licensed open-source project built and maintained by Diwen Huang.
Start the setup checklist ↓Setup checklist
-
Gather what you need
- Git and a GitHub account so you can clone the repo and fork it for Vercel. For the Node-based steps, use a supported version such as Node.js 22.12 or later in the 22.x series.
- Instagram and Meta with an Instagram Business or Creator account and a Facebook account to create your own Meta developer app. Have a second Instagram account ready for the test comment.
- PostgreSQL and Redis for data and the DM queue. For hosted services, Neon is one Postgres option and Redis needs a TCP connection that supports blocking commands. The full Docker stack includes both.
- Login email through Resend with a verified sender domain, or your own SMTP server. OpenReply sends a sign-in link by email.
- A public HTTPS URL and an always-on worker. You can use Vercel for the web app with a worker hosted elsewhere, or run everything on a VM.
OpenReply itself is free. Hosting, a domain, and email or database services can cost money depending on what you choose. This checklist uses your own Meta app.
-
Clone the public repo
Clone OpenReply git clone https://github.com/diwenne/openreply.git cd openreplyIf you choose Vercel, also fork OpenReply on GitHub so you can import your copy into your hosting projects.
-
Use Claude Code or Codex to do the setup
Open the cloned
openreplyfolder in either agent and paste its prompt. If you’re setting it up by hand, continue to step 4.Claude Code prompt
Claude Code prompt Help me self-host the public OpenReply repo using my own Meta app. Read README.md, docs/setup.md, docs/stack.md, and .env.example first. Check the Docker files and docs/deploy-dokploy.md if I choose a VM. Ask which hosting path I want and which login setup Meta offers. Install dependencies for the chosen path. Use .env.example to prepare .env or the host's environment settings. Tell me which values to enter privately. Never ask for secrets in chat, print them, or commit them. Generate the Prisma client and run the documented migrations against my OpenReply database. Start the web app and the always-on worker, and check /api/health for status: ok and worker.healthy: true. Help me connect Instagram, then have me comment BORING from a second account. Confirm the DM arrives and DM Logs shows SENT. Tell me which checks are still pending.Codex prompt
Codex prompt Help me self-host the public OpenReply repo using my own Meta app. Read README.md, docs/setup.md, docs/stack.md, and .env.example first. Check the Docker files and docs/deploy-dokploy.md if I choose a VM. Ask which hosting path I want and which login setup Meta offers. Install dependencies for the chosen path. Use .env.example to prepare .env or the host's environment settings. Tell me which values to enter privately. Never ask for secrets in chat, print them, or commit them. Generate the Prisma client and run the documented migrations against my OpenReply database. Start the web app and the always-on worker, and check /api/health for status: ok and worker.healthy: true. Help me connect Instagram, then have me comment BORING from a second account. Confirm the DM arrives and DM Logs shows SENT. Tell me which checks are still pending. -
Create the Postgres database and apply migrations
For Vercel: Create a fresh Postgres database, for example by creating a Neon project and copying its connection string. Provision Redis too. From the cloned folder, run the following on the first setup.
Install and prepare the environment npm install cp .env.example .envIn
.env, setDATABASE_URLto the new Postgres connection string andREDIS_URLto the Redis connection string. Use addresses your machine can reach. Then run:Apply database migrations npm run db:generate npm run db:migrateFor the all-in-one VM: Continue to Path B. Compose creates the Postgres database on first startup, and the web container applies the migrations before starting the app.
-
Choose where to host it
Use the names in
.env.example. For either path, set these values privately:NEXTAUTH_URLis the primary public HTTPS URL of your OpenReply app.NEXTAUTH_SECRET,CRON_SECRET, andWEBHOOK_VERIFY_TOKENeach get a separate random value.ENCRYPTION_KEYis a 64-character hex key. Use the same value on the web app and worker.- For Resend, set
RESEND_API_KEYandEMAIL_FROM. For SMTP, setEMAIL_SERVERandEMAIL_FROM. Use a sender your email provider permits. ALLOWED_EMAILScan limit sign-in to a comma-separated list of email addresses.
Generate one random secret per run openssl rand -base64 32Generate the encryption key openssl rand -hex 32Path A · Vercel web app and separate worker
Import your GitHub fork into Vercel as a Next.js project. Use the production HTTPS URL for
NEXTAUTH_URL. Set the environment variables in Vercel and on the worker, with both pointing at the same Postgres and Redis services. If Railway hosts those services, use itsDATABASE_PUBLIC_URLandREDIS_PUBLIC_URLvalues for Vercel’sDATABASE_URLandREDIS_URL. A worker inside Railway can use the private addresses.Set this as the Vercel build command and deploy. It generates the Prisma client, runs the migrations, and builds the web app.
Vercel build command npm run vercel-buildVercel serves the dashboard, OAuth callback, and webhook. The OpenReply worker is a continuous Node process that sends DMs and checks for missed comments. Give it its own always-on service. For example, add a Railway service from your GitHub fork and set these build and start commands.
Worker build command npm run db:generateWorker start command npm run workervercel.jsonschedules three daily jobs in UTC: token refresh at 05:00, next-reel attachment at 06:00, and follower snapshots at 07:00. Vercel usesCRON_SECRETto authorize those calls. The worker polls for missed comments every five minutes by default.Open
/api/healthon the production URL. Look forstatus: okandworker.healthy: true.Path B · Run the full stack on a VM
Create an always-on Ubuntu VM with a public IP. Connect over SSH, install Git, Docker Engine and the Compose plugin, then repeat the clone commands from step 2 on the VM.
Point your subdomain’s DNS A record at the VM. Allow public web traffic on ports 80 and 443, and restrict SSH to your own access. Block public access to ports 3000, 5432, and 6379 in the VM provider’s firewall. The Compose files publish those ports on the host.
Create the VM environment file cp .env.example .envFill in the shared settings above. Set
NEXTAUTH_URLto your HTTPS domain. The app Compose file supplies the internal Postgres and Redis addresses. If you change the bundled database credentials, setDOCKER_DATABASE_URLto match. If you change the Redis connection, setDOCKER_REDIS_URL.Start the full Docker stack docker compose -f docker-compose.yml -f docker-compose.app.yml up -d --buildThe base Compose file starts Postgres and Redis. The app file adds the web app, worker, and a service running
scripts/cron.sh. The script usesCRON_SECRETto call the web app, checks for next reels every five minutes, and runs token refresh and follower snapshots daily.Set up a reverse proxy with HTTPS, for example Caddy. Use your subdomain as the site address and forward traffic to
127.0.0.1:3000. Open/api/healthon your HTTPS domain and look forstatus: okandworker.healthy: true. -
Connect Meta and Instagram
Create a Business app in the Meta developer dashboard. Choose Manage messaging and content on Instagram. Check which API setup the app offers.
- Instagram Login: Copy
INSTAGRAM_APP_IDandINSTAGRAM_APP_SECRETfrom the Instagram product. GetFACEBOOK_APP_SECRETfrom App settings → Basic. OpenReply requestsinstagram_business_basic,instagram_business_manage_comments,instagram_business_manage_messages, andinstagram_business_manage_insights. - Unified Login: Create a login configuration with
instagram_basic,instagram_manage_comments,instagram_manage_messages, andinstagram_manage_insights. In Facebook Login for Business → Configurations, edit that same configuration to addbusiness_management. SetMETA_LOGIN_CONFIG_IDto the configuration ID,META_APP_IDto the App ID under App settings → Basic, andFACEBOOK_APP_SECRETto the secret there. Check the token expiry date in OpenReply Settings and reconnect before that date if one is shown. See OpenReply’s Unified Login walkthrough.
Apply the Meta variables on the web app and worker, or in the VM’s
.env. KeepMETA_GRAPH_API_VERSIONat the value in the cloned.env.example. Redeploy on Vercel and restart the worker, or rerun the VM’s Compose command to apply the changes.Register the OAuth redirect in the Instagram business login settings or in your Unified Login configuration. Replace the example hostname with your primary HTTPS hostname. Keep the path exact, with no trailing slash.
OAuth redirect URL https://your-app.vercel.app/api/instagram/callbackIn the same API setup’s webhook settings, enter this callback URL with your hostname. Paste the same
WEBHOOK_VERIFY_TOKENyou set in OpenReply. Verify and save, then subscribe tocommentsandmessages.Webhook callback URL https://your-app.vercel.app/api/webhookUnder App roles, invite the Instagram account you’ll connect as an Instagram tester. On that account, open Instagram → Settings and activity → Apps and websites → Tester invites, and accept.
In Meta’s Publish section, register your app’s
/privacy,/data-deletion, and/termspages. Publish the app for real comment webhooks. Standard Access covers accounts with an app role. To connect accounts without an app role, request Advanced Access through Meta App Review. Meta may require business verification.Sign in to OpenReply with your email link. Open Settings → Connect Instagram, authorize the account, and check that it appears in Settings.
- Instagram Login: Copy
-
Make your first keyword campaign and test it
- Create a campaign in OpenReply. Select your connected account and an existing post or reel.
- Set
BORINGas the comment keyword. Write a short DM that includes the link you promised. Save the campaign and make sure it’s active. - From a second Instagram account, comment
BORINGon that exact post. OpenReply ignores comments from the connected account itself. - Check that the second account received the DM and that DM Logs shows
SENT. If the DM is missing, check the log reason and open/api/healthon your app.
-
Troubleshoot and secure your setup
- No sign-in email. Check
EMAIL_FROMagainst your verified Resend domain, or check the SMTP URL and sender. If you setALLOWED_EMAILS, make sure your address is on it. - Insufficient Developer Role. Invite the exact Instagram username and accept the invite in Instagram. Repeat this when connecting another account under Standard Access.
redirect_urimismatch. Check the registered OAuth URL againstNEXTAUTH_URLand/api/instagram/callback, including the hostname and trailing slash.- Meta’s test works but real comments don’t. Check that the app is Live, subscribed to
comments, and using the primary HTTPS hostname. To confirm Meta can reach the endpoint, choose Test → Send to My Server next tocomments. - Comments arrive but DMs stay queued. Check
/api/health. If the worker is unhealthy, check that it’s running and can reach Redis over TCP. Check that the web app and worker share the same database, Redis, andENCRYPTION_KEY.
Keep credentials private. Keep
.envout of Git. Enter secrets in your local file or hosting dashboard, and rotate any that leak. Back upENCRYPTION_KEYsecurely. If you lose or change it, reconnect the Instagram accounts.See the official setup guide for more details.
- No sign-in email. Check
Need a hand with setup? Contact us.