Repository navigation
fix(comment-automation): deliver flow-type private replies via comment-anchored send - #831
Merged
Merged
Conversation
…t-anchored send
Private reply configured as "text" already worked because it calls
sendPrivateReply, which uses Facebook's comment_id-anchored Send API
(bypasses the messaging-window rule). Private reply configured as
"flow" only enqueued a generic sendFlow job, which delivers via the
normal PSID-based Send API — rejected by Facebook for contacts who
only commented and never messaged the Page. The rejection was also
silently swallowed after the outgoing message row was optimistically
marked as sent, so the job reported success with nothing delivered.
Threads an optional commentAnchor { commentId } through the flow
engine (flow.ts, flow-utils.ts, step.ts, condition.ts) and the chat
queue plumbing, forwarded across every re-enqueued sendFlow job until
claimed by the first message-producing step. The Messenger channel
handler then sends that first message through the new
sendPrivateReplyMessage API (comment_id-anchored, any payload type,
not just text) instead of the normal Send API; later messages in the
same flow fall back to the normal path once the private reply has
opened a standard messaging window.
sendPrivateReplyMessage also stamps message.metadata and persona_id
so the message_echo webhook still recognizes our own sends and
persona configuration is respected on the anchored path, matching
every other Messenger send path. sendPrivateReply now delegates to it
to remove the duplicated request construction.
Known gap (documented inline, not fixed here): a private-reply flow
with a wait/followUp/questionnaire step before its first message step
loses the anchor across the scheduled delay, since
ContactOnSmartDelay has no column to carry it — needs a schema change.
4 of 5 tasks
sung17
added a commit
that referenced
this pull request
Jul 25, 2026
…ot DMs (#834) publicReply.type === "flow" only enqueued a generic sendFlow job, which always routed its outgoing messages through the private "message" channel (a normal DM Send API call). It never posted a public comment reply, unlike "text" and "AIAgent", both of which correctly call postPublicCommentReply. The flow's messages either landed silently as a DM the user never asked for, or failed outright for commenters who had never messaged the Page (same messaging-window rejection class as the earlier private-reply-flow bug, PR #831). Extends the commentAnchor mechanism from that earlier fix with a replyChannel: "public" | "private" discriminant instead of adding a parallel mechanism, since the propagation plumbing (flow.ts, flow-utils.ts, step.ts, condition.ts) already treats the anchor opaquely and needs no changes. - executePublicReply's flow branch now sets commentAnchor with replyChannel: "public" — unlike private reply, this is NOT gated to Messenger, since both Messenger and Instagram implement comment.sendComment. - send-flow-step.ts branches on replyChannel: "public" builds the message row as type:"comment" with contentAttributes.replyToCommentId and routes through sendMessageToChannel (reusing its existing isComment routing, sourceId persistence, and retry-suppression logic instead of inventing a new path); "private" (or absent) keeps the existing sendFlowStepToChannel/comment-anchored-DM behavior. - sendMessageToChannel now returns { messageIds } instead of void so the flow-step handler's message:sent analytics/sourceId tracking works identically for both branches. - Messenger's outgoing-message handler only honors the anchor for replyChannel: "private" (defense-in-depth — a public anchor should never reach the DM channel handler). Known gap (documented inline, unchanged from PR #831): a reply flow with a wait/followUp/questionnaire step before its first message step still loses the anchor across the scheduled delay, for both public and private now — ContactOnSmartDelay has no column to carry it. Co-authored-by: Deathgiver <[email protected]>
realcodesiman
pushed a commit
that referenced
this pull request
Aug 23, 2026
Both `docs/fb-comment-automation.md` and the `fb-comment-automation` skill still
claimed Instagram comment automation was unimplemented ("the builder always stores
`type = "messenger"`", "IG private-DM text is out of scope"), which has been wrong
since #874 shipped the `ig-comments` builder feature and the `instagram` /
`instagramFacebook` channel types. #831 and #1018 then moved flow-based private
replies onto Meta's comment_id-anchored Send API. None of those PRs touched the
docs, so the guidance actively told readers (and AI agents) not to work on IG.
Rewrite the scope banner, the `type` option row, the reply-type table, the known-gap
bullet and skill trap 6 to describe the three `CommentAutomationChannelType` values,
and record the real per-channel limits: comment liking is messenger +
instagramFacebook only, and the hide image/video attachment lookup is messenger only.
Claude-Session: https://claude.ai/code/session_01Jr3BRqH3woCzbcePEBPira
Co-authored-by: Claude Opus 5 <[email protected]>
viethung0o0
pushed a commit
that referenced
this pull request
Sep 7, 2026
…t-anchored send (#831) Private reply configured as "text" already worked because it calls sendPrivateReply, which uses Facebook's comment_id-anchored Send API (bypasses the messaging-window rule). Private reply configured as "flow" only enqueued a generic sendFlow job, which delivers via the normal PSID-based Send API — rejected by Facebook for contacts who only commented and never messaged the Page. The rejection was also silently swallowed after the outgoing message row was optimistically marked as sent, so the job reported success with nothing delivered. Threads an optional commentAnchor { commentId } through the flow engine (flow.ts, flow-utils.ts, step.ts, condition.ts) and the chat queue plumbing, forwarded across every re-enqueued sendFlow job until claimed by the first message-producing step. The Messenger channel handler then sends that first message through the new sendPrivateReplyMessage API (comment_id-anchored, any payload type, not just text) instead of the normal Send API; later messages in the same flow fall back to the normal path once the private reply has opened a standard messaging window. sendPrivateReplyMessage also stamps message.metadata and persona_id so the message_echo webhook still recognizes our own sends and persona configuration is respected on the anchored path, matching every other Messenger send path. sendPrivateReply now delegates to it to remove the duplicated request construction. Known gap (documented inline, not fixed here): a private-reply flow with a wait/followUp/questionnaire step before its first message step loses the anchor across the scheduled delay, since ContactOnSmartDelay has no column to carry it — needs a schema change. Co-authored-by: Deathgiver <[email protected]>
viethung0o0
pushed a commit
that referenced
this pull request
Sep 7, 2026
…ot DMs (#834) publicReply.type === "flow" only enqueued a generic sendFlow job, which always routed its outgoing messages through the private "message" channel (a normal DM Send API call). It never posted a public comment reply, unlike "text" and "AIAgent", both of which correctly call postPublicCommentReply. The flow's messages either landed silently as a DM the user never asked for, or failed outright for commenters who had never messaged the Page (same messaging-window rejection class as the earlier private-reply-flow bug, PR #831). Extends the commentAnchor mechanism from that earlier fix with a replyChannel: "public" | "private" discriminant instead of adding a parallel mechanism, since the propagation plumbing (flow.ts, flow-utils.ts, step.ts, condition.ts) already treats the anchor opaquely and needs no changes. - executePublicReply's flow branch now sets commentAnchor with replyChannel: "public" — unlike private reply, this is NOT gated to Messenger, since both Messenger and Instagram implement comment.sendComment. - send-flow-step.ts branches on replyChannel: "public" builds the message row as type:"comment" with contentAttributes.replyToCommentId and routes through sendMessageToChannel (reusing its existing isComment routing, sourceId persistence, and retry-suppression logic instead of inventing a new path); "private" (or absent) keeps the existing sendFlowStepToChannel/comment-anchored-DM behavior. - sendMessageToChannel now returns { messageIds } instead of void so the flow-step handler's message:sent analytics/sourceId tracking works identically for both branches. - Messenger's outgoing-message handler only honors the anchor for replyChannel: "private" (defense-in-depth — a public anchor should never reach the DM channel handler). Known gap (documented inline, unchanged from PR #831): a reply flow with a wait/followUp/questionnaire step before its first message step still loses the anchor across the scheduled delay, for both public and private now — ContactOnSmartDelay has no column to carry it. Co-authored-by: Deathgiver <[email protected]>
viethung0o0
pushed a commit
that referenced
this pull request
Sep 7, 2026
Both `docs/fb-comment-automation.md` and the `fb-comment-automation` skill still
claimed Instagram comment automation was unimplemented ("the builder always stores
`type = "messenger"`", "IG private-DM text is out of scope"), which has been wrong
since #874 shipped the `ig-comments` builder feature and the `instagram` /
`instagramFacebook` channel types. #831 and #1018 then moved flow-based private
replies onto Meta's comment_id-anchored Send API. None of those PRs touched the
docs, so the guidance actively told readers (and AI agents) not to work on IG.
Rewrite the scope banner, the `type` option row, the reply-type table, the known-gap
bullet and skill trap 6 to describe the three `CommentAutomationChannelType` values,
and record the real per-channel limits: comment liking is messenger +
instagramFacebook only, and the hide image/video attachment lookup is messenger only.
Claude-Session: https://claude.ai/code/session_01Jr3BRqH3woCzbcePEBPira
Co-authored-by: Claude Opus 5 <[email protected]>
This branch was previously deployed
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
sendPrivateReply). The rejection was also swallowed after the outgoing message row was optimistically marked as sent, so the job reported success with nothing delivered.commentAnchor { commentId }through the flow engine (flow.ts,flow-utils.ts,step.ts,condition.ts) and the chat queue plumbing, forwarded across every re-enqueuedsendFlowjob until claimed by the first message-producing step. The Messenger channel handler then sends that first message via the newsendPrivateReplyMessageAPI (comment_id-anchored, any payload type) instead of the normal Send API; later messages in the same flow fall back to the normal path once the private reply has opened a standard messaging window.sendPrivateReplyMessagealso stampsmessage.metadataandpersona_idso the message_echo webhook recognizes our own sends and persona configuration is respected, matching every other Messenger send path;sendPrivateReplynow delegates to it to remove duplicated request construction.Changes
apps/worker/src/integration/handlers/comment-automation/index.ts— createscommentAnchorfor messenger flow-type private repliesapps/worker/src/integration/handlers/{flow.ts,flow-utils.ts,step.ts,condition.ts}— propagate + consume-oncecommentAnchorthrough the flow engineapps/worker/src/chat/handlers/{send-flow-step.ts,send-message.ts}— forwardcommentAnchorthrough the chat-queue send path (Messenger-only, defense-in-depth channel check)integrations/messenger/src/apis/comment.ts— newsendPrivateReplyMessage(arbitrary payload, comment_id-anchored, stamps metadata/persona_id);sendPrivateReplynow delegates to itintegrations/messenger/src/handlers/message/outgoing-message/index.ts— uses the comment-anchored send for the first Facebook message of a run whencommentAnchoris presentpackages/sdk/src/lib/shared/index.ts— new sharedCommentAnchortype (removes duplicated inline type across sdk/worker-config/worker)comment-automation.test.ts,flow.test.ts,send-flow-step.test.ts; newsend-flow-step-comment-anchor.test.tsandsend-private-reply.test.tsinintegrations/messengerKnown gap (documented inline, not fixed here): a private-reply flow with a
wait/followUp/questionnairestep before its first message step loses the anchor across the scheduled delay, sinceContactOnSmartDelayhas no column to carry it — would need a schema change.Test plan
pnpm --filter worker check-types,pnpm --filter @chatbotx.io/integration-messenger check-types,pnpm --filter @chatbotx.io/sdk check-types,pnpm --filter @chatbotx.io/worker-config check-types— all passpnpm --filter worker vitest run— 1098/1098 passpnpm --filter @chatbotx.io/integration-messenger vitest run— 177/177 passpnpm lint— clean