In this guide
Overview · Step 1
How it works
Every comment-the-keyword post has the same problem: answer hundreds of comments by hand, or pay ManyChat every month. This setup replaces both.
Comment
Someone comments your keyword under a reel. Instagram sends it to your server through a webhook.
Keyword match
Your server checks the keyword. On a match it sends one private reply: a DM card with a picture and a button.
YouTube
There are no DMs on YouTube, so your server checks for new comments every 5 minutes and posts a public reply with the link.
Tracked link
Every link is tracked: clicks, signups and paying customers per keyword, in your own dashboard.
Meta · Step 2
Instagram setup
About 20 minutes at Meta. Do these once, in this order.
- 1
Go to developers.facebook.com and create an app with the use case Manage messaging & content on Instagram. New apps get Unified Login, which gives you a system user token that never expires.
- 2
Create a configuration: token type system user token, expires never, pick your Instagram account and skip the ad account.
- 3
Copy the configuration ID and add your redirect URL.
- 4
Request the permissions
instagram_basic,instagram_manage_commentsandinstagram_manage_messages. For your own business, "Ready for testing" is enough, so there is no App Review. - 5
Fill in the app settings: privacy policy URL, terms URL, data deletion URL, app icon and category.
- 6
Set the environment variables: App ID, App secret, configuration ID and a verify token from
openssl rand -hex 32. - 7
After your code is deployed, set the webhook callback URL and the verify token, then subscribe to the comments field.
- 8
Switch the app to Live.
- 9
Connect your Instagram account in your admin tool.
Google · Step 3
YouTube setup
YouTube is simpler: no webhook, only OAuth for your own channel.
- 1
Create a new project in the Google Cloud console.
- 2
Enable the YouTube Data API v3.
- 3
Consent screen: choose Internal if your channel belongs to your Google Workspace (no verification), otherwise External and click Publish. Never leave it in Testing: access expires after 7 days.
- 4
Data Access: add only the scope
youtube.force-ssl. - 5
Create a Web client and add your redirect URI.
- 6
Put the client ID and client secret into your environment variables.
- 7
Connect your channel once. The 5-minute check starts collecting comments.
Claude · Step 4
Let Claude build it
Paste this prompt into Claude Code inside your own web app. It builds the webhook with signature checks, the YouTube poller, keyword matching, tracked links and an admin page with your numbers.
Build a comment automation for my own Instagram and YouTube channels, without ManyChat, inside my existing web app with a database and an admin area.
1. Instagram via the Meta "Instagram API with Unified Login" (graph.facebook.com): connect through Facebook Login for Business with my configuration ID (system user token, never expires), store accounts from /me/assigned_instagram_accounts. Webhook route for the "comments" field: GET handshake with a verify token, POST with an X-Hub-Signature-256 check (HMAC with the app secret, constant time, reject without a secret). On a keyword match send a private reply via POST /<IG_ID>/messages with recipient.comment_id, as a card (generic template: image, title, button) with a text fallback. Optional public reply under the comment.
2. YouTube: a separate Google OAuth client only for my channel, scope youtube.force-ssl, store the refresh token. A cron every 5 minutes: commentThreads.list with allThreadsRelatedToChannelId, order=time, textFormat=plainText, 60 minutes overlap. Reply with comments.insert (parentId). At most 25 per run, 150 per day, only comments from the last 48 hours automatically.
3. Keyword matching: ignore case, punctuation and emoji, ignore spaces between words ("small town" = "smalltown"). Keywords of 4+ letters also match the start of a word ("small" hits "smalltown"), shorter ones only whole words ("ai" never hits "said"). One reply per person per automation. Ignore my own comments.
4. No double replies: claim each comment ("sending") before sending. On an unclear result (timeout, 5xx) never resend automatically, only by hand.
5. A "Reply to older comments" button per video: reads the video's comments, skips every comment my channel already answered (check part=snippet,replies), replies to at most 40 a day, oldest first, and also picks up comments that arrived before the automation existed.
6. Tracked link: every reply gets a short link on my domain that counts clicks (skip bots like facebookexternalhit) and redirects with utm_source=instagram|youtube, utm_medium=dm|comment, utm_campaign=<automation>. Redirect only to my own domain.
7. An admin page "Comment automations": connect channels, create automations (channel, post/video or all, keywords, text, link, up to 3 rotating public replies), on/off, sortable. Per automation: matched, sent, failed, clicks, signups, paying customers, revenue. A comment log with status.
8. Never send tokens to the browser or log them. Database tables readable server-side only.
Work in steps: show the plan first, then database + connect + webhook/poller, then replies + tracked link, then the admin page. At each step tell me which URLs to enter at Meta and Google.Limits · Step 5
Rules that matter
The prompt already encodes these. Know them so you can set your own limits.
Tip: Instagram allows exactly one private reply per comment, within 7 days of the comment.
Tip: YouTube allows about 200 replies a day. Rotate up to 3 reply texts so your replies do not look identical.
Tip: Disclose that the reply is automated. Germany requires it.
Tip: Never re-answer comments you already answered by hand. The older-comments button must skip them.
Results · Step 6
Our results after one week
Real numbers from our own channels.
5
DMs sent
4
Clicks
1
Signup
Our rule now: every how-to video that says "comment the keyword" gets its automation the moment it is posted. Make the videos people want to comment on with aicut.

