Repository navigation
feat(comment-automation): harden reply delivery and gate media steps per channel - #1121
Merged
Merged
Conversation
…per channel
Two threads over the same surface: comment replies that silently never
reached the customer, and media steps that a channel cannot deliver.
Reply delivery (worker + sdk + channels):
- Write the dedup row when *any* branch dispatched, not only when both did.
A public reply that went out while the private one threw used to leave no
row, so the contact's next comment posted the public reply a second time.
- Roll the dedup row back when an AI reply job bails out (agent missing, no
text, workspace outside active hours). It used to count as "replied", and
`replyOncePerUserPerPost` then blocked that contact on that post forever.
A thrown failure still keeps the row — BullMQ retries it.
- Skip a private reply once another automation on the same comment has spent
it: Meta allows exactly one comment_id-anchored DM per comment, so the
second call could only fail. Public replies of that automation still run.
- Skip a private reply for a comment older than Meta's 7-day window, delay
included, instead of letting the Send API reject it.
- Keep a claimed private anchor travelling as `spent: true` rather than
dropping it, so each channel's `sendFlowStep` can tell a comment-triggered
follow-up from a plain flow message. Message two onward now sends as a
normal DM inside the contact's 24-hour window and otherwise throws
`comment_private_reply_already_used`, which lands on the message row as a
`sendError` the inbox shows. Before, Meta rejected it and the error was
swallowed, so a two-message flow looked half-delivered with no reason.
- Log when the incoming comment's message row is missing: like, hide and
parent threading were being skipped with no trace.
Media steps (flow-config + builder + Instagram):
- `media-step-rules` / `media-step-validators` describe which media a channel
accepts, surfaced in the builder as a notice on the send-* step editors.
- Instagram comment replies are text-only (`POST /{ig-comment-id}/replies`
has no `attachment_url`), so both variants' `sendComment` now throw
`PAYLOAD_INVALID` instead of returning an empty result behind a warn.
- Instagram-via-Facebook collects a step's messages before sending so quick
replies land on the last one, and upload failures propagate to the inbox.
Co-authored-by: Claude Opus 5 <[email protected]>
hello-jackytruong
referenced
this pull request
in hello-jackytruong/ChatWorkAI
Nov 22, 2026
…per channel (#1121)
Two threads over the same surface: comment replies that silently never
reached the customer, and media steps that a channel cannot deliver.
Reply delivery (worker + sdk + channels):
- Write the dedup row when *any* branch dispatched, not only when both did.
A public reply that went out while the private one threw used to leave no
row, so the contact's next comment posted the public reply a second time.
- Roll the dedup row back when an AI reply job bails out (agent missing, no
text, workspace outside active hours). It used to count as "replied", and
`replyOncePerUserPerPost` then blocked that contact on that post forever.
A thrown failure still keeps the row — BullMQ retries it.
- Skip a private reply once another automation on the same comment has spent
it: Meta allows exactly one comment_id-anchored DM per comment, so the
second call could only fail. Public replies of that automation still run.
- Skip a private reply for a comment older than Meta's 7-day window, delay
included, instead of letting the Send API reject it.
- Keep a claimed private anchor travelling as `spent: true` rather than
dropping it, so each channel's `sendFlowStep` can tell a comment-triggered
follow-up from a plain flow message. Message two onward now sends as a
normal DM inside the contact's 24-hour window and otherwise throws
`comment_private_reply_already_used`, which lands on the message row as a
`sendError` the inbox shows. Before, Meta rejected it and the error was
swallowed, so a two-message flow looked half-delivered with no reason.
- Log when the incoming comment's message row is missing: like, hide and
parent threading were being skipped with no trace.
Media steps (flow-config + builder + Instagram):
- `media-step-rules` / `media-step-validators` describe which media a channel
accepts, surfaced in the builder as a notice on the send-* step editors.
- Instagram comment replies are text-only (`POST /{ig-comment-id}/replies`
has no `attachment_url`), so both variants' `sendComment` now throw
`PAYLOAD_INVALID` instead of returning an empty result behind a warn.
- Instagram-via-Facebook collects a step's messages before sending so quick
replies land on the last one, and upload failures propagate to the inbox.
Co-authored-by: Deathgiver <[email protected]>
Co-authored-by: Claude Opus 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
flow-configand surfaced in the builder, and Instagram's text-only comment replies now fail visibly instead of vanishing.Changes
Reply delivery
apps/worker/.../comment-automation/: dedup written when any branch dispatched; newdedup.tsholds the rollback helper;privateReplyClaimedshared across the loop; executors return whether they dispatched; warn when the incoming comment's message row is missingpackages/business/.../fb-comment-automation/service.ts:deleteDeduppackages/worker-config:commentDeduprides thecommentAIReplyjobpackages/sdk:CommentAnchor.spent,isWithinMetaResponseWindow,assertCommentPrivateReplyFollowUpDeliverableapps/worker/.../flow.ts: a claimed private anchor continues asspent: trueinstead of being droppedintegrations/{messenger,instagram,instagram-facebook}: guard every non-anchored send of a comment-triggered private run on the contact's 24-hour windowMedia steps
packages/flow-config:media-step-rules+media-step-validatorsapps/builder:media-step-noticeon the send-* step editors, keys in all 20 localesintegrations/instagram{,-facebook}:sendCommentthrowsPAYLOAD_INVALIDfor attachments; IG-FB collects a step's messages so quick replies land on the last oneTest plan
pnpm lintpnpm --filter worker check-types(+ sdk, business, worker-config, flow-config, builder, all three integrations)apps/worker: 2091 tests / 212 filesintegrations: messenger 264, instagram 79, instagram-facebook 53packages/flow-config: 476 tests