Sane DevsSend us a messageContact us
← All planning checklists

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

  1. 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.

  2. Clone the public repo

    Clone OpenReply
    git clone https://github.com/diwenne/openreply.git
    cd openreply

    If you choose Vercel, also fork OpenReply on GitHub so you can import your copy into your hosting projects.

  3. Use Claude Code or Codex to do the setup

    Open the cloned openreply folder 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.
  4. 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 .env

    In .env, set DATABASE_URL to the new Postgres connection string and REDIS_URL to the Redis connection string. Use addresses your machine can reach. Then run:

    Apply database migrations
    npm run db:generate
    npm run db:migrate

    For 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.

  5. Choose where to host it

    Use the names in .env.example. For either path, set these values privately:

    • NEXTAUTH_URL is the primary public HTTPS URL of your OpenReply app.
    • NEXTAUTH_SECRET, CRON_SECRET, and WEBHOOK_VERIFY_TOKEN each get a separate random value.
    • ENCRYPTION_KEY is a 64-character hex key. Use the same value on the web app and worker.
    • For Resend, set RESEND_API_KEY and EMAIL_FROM. For SMTP, set EMAIL_SERVER and EMAIL_FROM. Use a sender your email provider permits.
    • ALLOWED_EMAILS can limit sign-in to a comma-separated list of email addresses.
    Generate one random secret per run
    openssl rand -base64 32
    Generate the encryption key
    openssl rand -hex 32

    Path 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 its DATABASE_PUBLIC_URL and REDIS_PUBLIC_URL values for Vercel’s DATABASE_URL and REDIS_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-build

    Vercel 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:generate
    Worker start command
    npm run worker

    vercel.json schedules three daily jobs in UTC: token refresh at 05:00, next-reel attachment at 06:00, and follower snapshots at 07:00. Vercel uses CRON_SECRET to authorize those calls. The worker polls for missed comments every five minutes by default.

    Open /api/health on the production URL. Look for status: ok and worker.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 .env

    Fill in the shared settings above. Set NEXTAUTH_URL to your HTTPS domain. The app Compose file supplies the internal Postgres and Redis addresses. If you change the bundled database credentials, set DOCKER_DATABASE_URL to match. If you change the Redis connection, set DOCKER_REDIS_URL.

    Start the full Docker stack
    docker compose -f docker-compose.yml -f docker-compose.app.yml up -d --build

    The base Compose file starts Postgres and Redis. The app file adds the web app, worker, and a service running scripts/cron.sh. The script uses CRON_SECRET to 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/health on your HTTPS domain and look for status: ok and worker.healthy: true.

  6. 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_ID and INSTAGRAM_APP_SECRET from the Instagram product. Get FACEBOOK_APP_SECRET from App settings → Basic. OpenReply requests instagram_business_basic, instagram_business_manage_comments, instagram_business_manage_messages, and instagram_business_manage_insights.
    • Unified Login: Create a login configuration with instagram_basic, instagram_manage_comments, instagram_manage_messages, and instagram_manage_insights. In Facebook Login for Business → Configurations, edit that same configuration to add business_management. Set META_LOGIN_CONFIG_ID to the configuration ID, META_APP_ID to the App ID under App settings → Basic, and FACEBOOK_APP_SECRET to 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. Keep META_GRAPH_API_VERSION at 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/callback

    In the same API setup’s webhook settings, enter this callback URL with your hostname. Paste the same WEBHOOK_VERIFY_TOKEN you set in OpenReply. Verify and save, then subscribe to comments and messages.

    Webhook callback URL
    https://your-app.vercel.app/api/webhook

    Under 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 /terms pages. 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.

  7. Make your first keyword campaign and test it

    • Create a campaign in OpenReply. Select your connected account and an existing post or reel.
    • Set BORING as 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 BORING on 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/health on your app.
  8. Troubleshoot and secure your setup

    • No sign-in email. Check EMAIL_FROM against your verified Resend domain, or check the SMTP URL and sender. If you set ALLOWED_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_uri mismatch. Check the registered OAuth URL against NEXTAUTH_URL and /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 to comments.
    • 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, and ENCRYPTION_KEY.

    Keep credentials private. Keep .env out of Git. Enter secrets in your local file or hosting dashboard, and rotate any that leak. Back up ENCRYPTION_KEY securely. If you lose or change it, reconnect the Instagram accounts.

    See the official setup guide for more details.

Need a hand with setup? Contact us.