Fb Comment Automation
Apps & Automationfb-comment-automationFb Comment Automation is an Agent Skill for apps & automation published in the ChatbotXIO/ChatbotX repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Work on Facebook/Messenger comment automation — the feature that auto-replies to, likes, or hides comments on Facebook Page posts. Use when changing the comment webhook path, the automation matching/filter logic, reply dispatch (text/flow/AI agent), hide rules, post targeting, or the fb-comments builder feature. Read this BEFORE editing anything under comment-automation to avoid the silent-failure traps.
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Inspect the Agent Skill at https://github.com/ChatbotXIO/ChatbotX/blob/HEAD/.agents/skills/fb-comment-automation/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/fb-comment-automation, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
Facebook Comment Automation
Full reference: docs/fb-comment-automation.md.
Read it before non-trivial changes. This skill is the quick map + the traps.
Where things live
| Concern | Path |
|---|---|
| Automation loop, filters, dispatch | apps/worker/src/integration/handlers/comment-automation/index.ts |
| AI-agent reply (generate + deliver) | apps/worker/src/integration/handlers/comment-automation/ai-reply.ts |
| Attachment info (image/video for hide) | apps/worker/src/integration/handlers/comment-automation/comment-attachment.ts |
| Receive comment + enqueue automation | apps/worker/src/integration/handlers/received-message.ts (receiveComment) |
| Webhook parse + enqueue | integrations/messenger/src/handlers/webhook.ts |
| Webhook value schema | integrations/messenger/src/schema.ts (messengerFeedCommentValueSchema) |
| DB queries (match/dedup/schedule) | packages/business/src/fb-comment-automation/service.ts |
| Schema + option/reply Zod partials | packages/database/src/schema/fb-comment-automation.ts, .../partials/fb-comment-automation.ts |
| Dedup ledger | packages/database/src/schema/fb-comment-automation-reply.ts |
| Job types | packages/worker-config/src/queues/integration/index.ts |
| Builder feature (form, actions) | apps/builder/src/features/fb-comments/ |
| Tests | apps/worker/__tests__/comment-automation.test.ts |
Data-flow in one line
feed webhook (verb "add") → incomingComment → receiveComment → processCommentAutomation → (AIAgent) commentAIReply.
The traps (read before editing)
-
parent_idis ALWAYS present and equalspost_idfor top-level comments. A truthyparentIddoes NOT mean "reply." UseisCommentReply(parentId, postId)(parentId !== postId). Breaking this + defaultignoreCommentReplies: truesilently drops every top-level comment. -
Post ids are composite
{pageId}_{storyId}; the picker stores 3 different formats (published/ads composite, reels bare id, manual free-text). Always compare throughnormalizePostId(trailing story id). Neverpost.value.includes(rawPostId). -
Every skip must log. The loop uses
logAutomationSkipped(..., reason)before eachcontinue.processCommentAutomationreturnsvoid→ BullMQ always logsreturnValue: null, so a skip with no log is undebuggable in production. Add a skip log for any new filter. -
AIAgent reply ≠ DM auto-responder.
publicReply/privateReplyof typeAIAgentstore the selected agent id invalue. Generation usesgenerateAIReplyText(tools + rich OFF, returns text only); the comment handler routes public → public comment reply (type:"comment"+replyToCommentId), private → DM. Do NOT route throughprocessAutomatedResponse— it uses the workspace default agent and always sends a DM. -
Dedup ledger is dual-purpose.
fbCommentAutomationReplyModelrows (automationId, contactId, postId) are written after every successful reply and read by bothreplyOncePerUserPerPost(same post) andreplyToUsersWhoCommentedOnOtherPosts(other post). The unique indexFBCommentAutomationReply_dedup_idxalready serves(automationId, contactId)+postId != ?queries — no new index needed; use aLIMIT 1existence check, not$count. -
Instagram is not implemented. Builder never sets
type, so it defaults tomessenger. Don't add IG-only behavior expecting it to run. IG private-DM text is out of scope. -
options.trackUserTagsis a no-op (defined, not implemented). Every other option (includingreplyToUsersWhoCommentedOnOtherPosts) IS enforced — see the option table in the docs.
Adding a new filter option (recipe)
- Add the field to
fbCommentOptionsSchema(partials) + DB default in the schema file (jsonbdefault string). - If it needs a DB lookup, add a method to
fbCommentAutomationService(reuse the dedup table + its index where possible; preferLIMIT 1existence checks). - Add the guard inside the loop in
processCommentAutomation, with alogAutomationSkipped(..., reason)beforecontinue. - Surface the toggle in
apps/builder/src/features/fb-comments/components/fb-comment-form.tsxand add i18n keys toapps/builder/messages/en.json+vi.json. - Extend
apps/worker/__tests__/comment-automation.test.ts.
Adding a new reply type (recipe)
- Extend
fbCommentReplySchema.type(partials). - Handle it in BOTH
executePublicReplyandexecutePrivateReply(index.ts). Public = messagetype:"comment"+replyToCommentIdviasendChannelMessage; private =sendPrivateReply(messenger only). - Update
willSendReplyso dedup/repliesCountonly count when a reply is actually dispatchable (e.g. requirevalue). - If it needs async work (like AIAgent), add a dedicated job in worker-config, a handler,
and a
caseinapps/worker/src/integration/worker.ts(theneverexhaustiveness guard forces this — type + dispatch + handler land together).
Verify
pnpm --filter worker vitest run __tests__/comment-automation.test.ts
pnpm --filter worker check-types
pnpm lint
Production sanity after deploy: comment on (a) a normal post, (b) a reel, (c) a comment with a bare-domain link + hide-link on, (d) an automation with reply = AI Agent — and confirm each fires or logs a clear skip reason.