Repository navigation
fix(comment-automation): post flow-type public replies as comments, not DMs - #834
Merged
Merged
Conversation
…ot DMs 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.
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]>
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
postPublicCommentReply. Messages either landed silently as an unwanted DM or failed for commenters who'd never messaged the Page (same messaging-window rejection class as the private-reply-flow bug fixed in fix(comment-automation): deliver flow-type private replies via comment-anchored send #831).CommentAnchormechanism shipped in fix(comment-automation): deliver flow-type private replies via comment-anchored send #831 with areplyChannel: "public" | "private"discriminant instead of building a parallel mechanism — the propagation plumbing (flow.ts,flow-utils.ts,step.ts,condition.ts) already treats the anchor opaquely and needs no changes.comment.sendComment.Changes
packages/sdk/src/lib/shared/index.ts—CommentAnchornow carriesreplyChannel: "public" | "private"apps/worker/src/integration/handlers/comment-automation/index.ts—executePublicReply's flow branch setscommentAnchorwithreplyChannel: "public"(no channelType gate);executePrivateReply's flow branch updated toreplyChannel: "private"apps/worker/src/chat/handlers/send-flow-step.ts— branches oncommentAnchor.replyChannel:"public"builds the message row astype: "comment"withcontentAttributes.replyToCommentIdand routes throughsendMessageToChannel(reusing its existing comment-vs-message routing, sourceId persistence, and retry-suppression instead of a new path);"private"/absent keeps the existingsendFlowStepToChannelbehaviorapps/worker/src/chat/handlers/send-message.ts—sendMessageToChannelnow returns{ messageIds }instead ofvoidso the flow-step handler'smessage:sentanalytics/sourceId tracking works for both branchesintegrations/messenger/src/handlers/message/outgoing-message/index.ts— only honors the anchor forreplyChannel === "private"(defense-in-depth; a public anchor should never reach the DM channel handler)step.ts,follow-up.ts) updated to note the wait/followUp anchor-loss gap now applies to both public and privatecomment-automation.test.ts,flow.test.ts,send-flow-step.test.ts,send-message-handler.test.ts,send-flow-step-comment-anchor.test.tsfor the newreplyChannelfield and public-reply routingTest plan
pnpm --filter worker check-types,pnpm --filter @chatbotx.io/sdk check-types,pnpm --filter @chatbotx.io/worker-config check-types,pnpm --filter @chatbotx.io/integration-messenger check-types,pnpm --filter @chatbotx.io/integration-instagram-facebook check-types— all passpnpm --filter worker vitest run— 1171/1172 pass (1 pre-existing unrelated failure inwebhook-executor-payloads.test.ts, confirmed present onmainbefore this change)pnpm --filter @chatbotx.io/integration-messenger vitest run— 178/178 passpnpm lint— clean on all files touched by this change