Skip to content

fix(comment-automation): post flow-type public replies as comments, not DMs - #834

Merged
sung17 merged 1 commit into
mainfrom
fix/comment-automation-public-reply-flow
Jul 25, 2026
Merged

sung17 merged 1 commit into
mainfrom
fix/comment-automation-public-reply-flow

Conversation

@sung17

@sung17 sung17 commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Facebook comment automation's public reply configured as "flow" never posted a public comment reply — it enqueued a generic flow job that always routed outgoing messages through the private DM channel, unlike "text"/"AIAgent" which correctly call 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).
  • Extends the CommentAnchor mechanism shipped in fix(comment-automation): deliver flow-type private replies via comment-anchored send #831 with a replyChannel: "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.
  • Public reply is not gated to Messenger-only (unlike private reply): both Messenger and Instagram implement comment.sendComment.

Changes

  • packages/sdk/src/lib/shared/index.ts — CommentAnchor now carries replyChannel: "public" | "private"
  • apps/worker/src/integration/handlers/comment-automation/index.ts — executePublicReply's flow branch sets commentAnchor with replyChannel: "public" (no channelType gate); executePrivateReply's flow branch updated to replyChannel: "private"
  • apps/worker/src/chat/handlers/send-flow-step.ts — branches on commentAnchor.replyChannel: "public" builds the message row as type: "comment" with contentAttributes.replyToCommentId and routes through sendMessageToChannel (reusing its existing comment-vs-message routing, sourceId persistence, and retry-suppression instead of a new path); "private"/absent keeps the existing sendFlowStepToChannel behavior
  • apps/worker/src/chat/handlers/send-message.ts — sendMessageToChannel now returns { messageIds } instead of void so the flow-step handler's message:sent analytics/sourceId tracking works for both branches
  • integrations/messenger/src/handlers/message/outgoing-message/index.ts — only honors the anchor for replyChannel === "private" (defense-in-depth; a public anchor should never reach the DM channel handler)
  • Known-gap comments (step.ts, follow-up.ts) updated to note the wait/followUp anchor-loss gap now applies to both public and private
  • Tests: extended comment-automation.test.ts, flow.test.ts, send-flow-step.test.ts, send-message-handler.test.ts, send-flow-step-comment-anchor.test.ts for the new replyChannel field and public-reply routing

Test 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 pass
  • pnpm --filter worker vitest run — 1171/1172 pass (1 pre-existing unrelated failure in webhook-executor-payloads.test.ts, confirmed present on main before this change)
  • pnpm --filter @chatbotx.io/integration-messenger vitest run — 178/178 pass
  • pnpm lint — clean on all files touched by this change
  • Manual: configure a comment automation with public reply = flow on a real connected Page, comment with an account that has never messaged the Page, confirm the reply actually appears publicly under the comment (not just in the internal inbox)

…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.
@github-actions github-actions Bot added the bug Something isn't working as expected label Jul 25, 2026
@sung17
sung17 merged commit eceff2f into main Jul 25, 2026
7 checks passed
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

1 inactive deployment
dev — 2810eac4 Deployed Jul 25, 2026 by sung17 via Build builder #2111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant