---
name: deploy-openreply-comment-to-dm
description: Use when replacing ManyChat with a self-hosted Instagram comment-to-DM bot: deploy OpenReply on Railway and Vercel and wire Meta webhooks.
---
## What this does
Deploys OpenReply, an open-source Instagram comment-to-DM tool: anyone who comments your keyword gets an automatic DM with your link. Self-hosted replacement for ManyChat's core feature, no contact cap.
## When to use
- The user wants comment-keyword → DM automation on Instagram without a subscription.
- The user can open a terminal and click through the Meta developer dashboard.
Confirm prerequisites: Facebook account (required for Meta dev registration); Instagram Business or Creator account; **Resend account with a verified sender domain** (login is email magic links only — without it nobody can sign in); **Vercel** for the web app; **Railway** for the worker, Postgres and Redis. No domain purchase needed — the free `your-app.vercel.app` URL is what everything points at.
## How to run it
Deploy order matters — Railway first, because Vercel needs the database URLs Railway generates.
1. **Railway first.** Create a project. Add PostgreSQL. Add Redis. Add the worker by connecting your fork of the repo. In worker settings set Build Command to `npm run db:generate` and Start Command to `npm run worker` (do not leave the default build). Give the worker the **internal** database and Redis URLs, the `*.railway.internal` ones.
2. **Migrate the production database** once, from your own machine, with the **public** Postgres URL: `DATABASE_URL="postgresql://...proxy.rlwy.net.../railway" npm run db:migrate`
3. **Vercel.** Import your fork, add every environment variable, deploy. Vercel gets the **public** Railway URLs; internal ones hang outside Railway's network. Variables: `NEXTAUTH_URL` (your Vercel URL), `NEXTAUTH_SECRET`, `CRON_SECRET` (generate both), `ENCRYPTION_KEY` (32-byte hex, exactly 64 hex characters), `DATABASE_URL` (public Railway Postgres), `REDIS_URL` (public Railway Redis), `RESEND_API_KEY`, `EMAIL_FROM` (on your verified Resend domain), `META_GRAPH_API_VERSION`, `INSTAGRAM_APP_ID` and `INSTAGRAM_APP_SECRET` (Instagram product page, not Basic settings), `FACEBOOK_APP_SECRET` (App settings, Basic), `WEBHOOK_VERIFY_TOKEN` (any string you invent).
4. **Create the Meta app** at developers.facebook.com/apps: type **Business**, use case **Manage messaging and content on Instagram**. Do not pick Facebook Login (breaks OAuth later with a mismatched-client error) or the Marketing API (review requirements heavy enough to block publishing).
5. **Collect the three secrets.** The Instagram app ID is deliberately not the same number as the Facebook app ID on the Basic page; the app verifies webhook signatures against both secrets.
6. **Tester invite, both halves.** In the Meta dashboard under App roles add your Instagram username as an Instagram tester. Then open the Instagram app **as that account** → Settings and activity → Apps and websites → Tester invites → accept.
7. **OAuth redirect.** In the Instagram product's business login settings register exactly `https://your-app.vercel.app/api/instagram/callback`. No trailing slash.
8. **Webhook.** Callback URL `https://your-app.vercel.app/api/webhook`, verify token matching your environment value, subscribe to the `comments` field. If Verify greys out, re-paste the token. Test with the console's Test → Send to My Server; the first click only previews.
9. **Publish the app.** Set privacy, terms and data-deletion URLs (OpenReply serves `/privacy`, `/terms`, `/data-deletion`), then publish.
10. **Test end to end.** Settings → Connect Instagram. Create a campaign with a keyword. Comment that keyword **from a different account**; your own comments are ignored by design.
The repo ships a ready-made prompt in its "Set it up with an AI assistant" section: clone the repo, open it in Claude Code, paste the prompt, and it drives the deploy while asking for values. It needs real secrets — only paste those into tools you trust, and rotate them after.
## Seven steps that fail silently
None throw a useful error; the deploy succeeds and nothing happens.
1. App still in **Development mode** — real comment webhooks are never delivered; only the console test works.
2. Tester invite only half accepted → "Insufficient Developer Role."
3. `ENCRYPTION_KEY` not identical on Vercel and Railway — the app encrypts the token, the worker decrypts it; every send fails while everything else looks healthy.
4. Vercel given internal Railway URLs — worker wants internal, Vercel wants public.
5. Resend key but no verified sender domain — no email means no login for anyone.
6. Trailing slash on the OAuth redirect — redirect_uri mismatch.
7. Tested from your own account — your comments are ignored by design.
## Troubleshooting
- Webhooks arrive but no DM sends → check `/api/health`; `worker.healthy: false` means the worker is down. Otherwise confirm `ENCRYPTION_KEY` matches on both services.
- Console test works, real comments do nothing → publish the app.
- Verify button greys out → re-paste the verify token.
- Vercel requests hang → swap internal Railway URLs for public.
- Railway build fails → build `npm run db:generate`, start `npm run worker`.
## Output
Hand back a deployment checklist: each step, the exact value or command to enter, and the signal that it worked. Close with the step 10 end-to-end test and a `/api/health` reading.
## Credit
Based on public content by heystevetan, packaged by Orbit.