Repository navigation
feat(comment-automation): delivery stats, miss tracking, tag counters, and multi-text replies - #1171
Merged
Merged
Conversation
…livery stats Record delivery lifecycle events for comment automation replies and surface them as Sent/Delivered/Seen/Clicked/Failed columns on the fb-comments and ig-comments tables, reusing the broadcast/sequence stats vocabulary so the contacts dialog and bulk-tag pipeline stay a single implementation. - add lifetime counters on FBCommentAutomation plus the event columns and indexes behind them (migration 20260911081114) - increment counters from the message/flow listeners via the anchor resolver - add the shared stats cell, stat columns, and contacts dialog components - extend the analytics repository/service with the contacts listing query Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…lti-text public replies
Builds on the delivery-stat columns with the three things they could not
answer on their own: which comments the automation declined, how many tags a
commenter has accumulated, and replies made of more than one message.
- FBCommentAutomationMiss: every filter decline now records a reason, so the
Misses column reports a real denominator instead of silence. Misses go to
their own table because FBCommentAutomationEvent purges failed rows nightly.
- Comment tag counters behind {{total_tagged}} / {{total_new_tagged}}.
- Multi-text public reply (ReplyTextsField), posted as separate comment
replies but counted as one reply.
- Per-automation analytics: replies chart, error logs, day/month bucketing.
Fixes found while verifying the stats end to end, each of which showed up as a
silent zero rather than an error:
- Delivered/Seen stayed at zero for a text private reply: markDelivered ran
before recordReplyEvent inserted the row, so the UPDATE matched nothing. The
row is now born delivered.
- Clicked could never increment: the private flow reply passed only
commentAnchor, while every button encoder reads metadata.commentAutomationId.
- A flow/AIAgent reply was enqueued before its analytics row existed, so with
no replyAfter the job could settle a row that was not there yet. Dispatch is
now deferred until after the row is written.
- Messenger image/video steps with buttons dropped metadata entirely, losing
comment-automation, broadcast and sequence attribution alike.
- markClicked could double-count concurrent clicks; markSeen accepted a read
receipt older than the reply; settleEvent never cleared failedAt on the way
back to sent; getContacts paged without a tiebreaker and counted contacts
the list did not show.
The click path was silent end to end, so two warns and three opt-in
diagnostics now cover it. logDiagnostic calls isLevelEnabled through an
optional call so the repo's hand-rolled logger doubles in tests opt out
instead of throwing.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Both snapshots were generated before main dropped AIAssistant/AITrigger and added the ErrorLog columns, so after the rebase they forked the chain at an older tip and still described tables that no longer exist. drizzle-kit reported a non-commutative chain: two branches each adding sentCount. Neither migration.sql changed — the SQL was always correct. What changed is the snapshots' lineage and content: - 20260911081114_add_comment_automation_delivery_stats is renamed to 20260913042025_... so folder order matches prevIds order; it used to sort between two of main's own migrations while claiming to follow the older tip. - Both snapshots are rebuilt as "main's tip + this branch's own entities", dropping the AIAssistant/AITrigger entries they should never have carried. normalizeReplyTexts moves into fbCommentAutomationService, where main's #1098 refactor put every write to this table. It was applied per call site before, which left the template installer out — and a row whose `value` disagrees with its `values` sends the wrong text with no error. Verified with drizzle-kit check ("Everything's fine") and db:check-drift. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
sung17
force-pushed
the
feat/comment-automation-delivery-stats
branch
from
September 13, 2026 15:35
f3f23b5 to
46074e8
Compare
hello-jackytruong
referenced
this pull request
in hello-jackytruong/ChatWorkAI
Nov 22, 2026
…, and multi-text replies (#1171) * feat(comment-automation): track sent/delivered/seen/clicked/failed delivery stats Record delivery lifecycle events for comment automation replies and surface them as Sent/Delivered/Seen/Clicked/Failed columns on the fb-comments and ig-comments tables, reusing the broadcast/sequence stats vocabulary so the contacts dialog and bulk-tag pipeline stay a single implementation. - add lifetime counters on FBCommentAutomation plus the event columns and indexes behind them (migration 20260911081114) - increment counters from the message/flow listeners via the anchor resolver - add the shared stats cell, stat columns, and contacts dialog components - extend the analytics repository/service with the contacts listing query Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * feat(comment-automation): track missed comments, tag counters, and multi-text public replies Builds on the delivery-stat columns with the three things they could not answer on their own: which comments the automation declined, how many tags a commenter has accumulated, and replies made of more than one message. - FBCommentAutomationMiss: every filter decline now records a reason, so the Misses column reports a real denominator instead of silence. Misses go to their own table because FBCommentAutomationEvent purges failed rows nightly. - Comment tag counters behind {{total_tagged}} / {{total_new_tagged}}. - Multi-text public reply (ReplyTextsField), posted as separate comment replies but counted as one reply. - Per-automation analytics: replies chart, error logs, day/month bucketing. Fixes found while verifying the stats end to end, each of which showed up as a silent zero rather than an error: - Delivered/Seen stayed at zero for a text private reply: markDelivered ran before recordReplyEvent inserted the row, so the UPDATE matched nothing. The row is now born delivered. - Clicked could never increment: the private flow reply passed only commentAnchor, while every button encoder reads metadata.commentAutomationId. - A flow/AIAgent reply was enqueued before its analytics row existed, so with no replyAfter the job could settle a row that was not there yet. Dispatch is now deferred until after the row is written. - Messenger image/video steps with buttons dropped metadata entirely, losing comment-automation, broadcast and sequence attribution alike. - markClicked could double-count concurrent clicks; markSeen accepted a read receipt older than the reply; settleEvent never cleared failedAt on the way back to sent; getContacts paged without a tiebreaker and counted contacts the list did not show. The click path was silent end to end, so two warns and three opt-in diagnostics now cover it. logDiagnostic calls isLevelEnabled through an optional call so the repo's hand-rolled logger doubles in tests opt out instead of throwing. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * fix(database): relink comment automation migrations onto main's chain Both snapshots were generated before main dropped AIAssistant/AITrigger and added the ErrorLog columns, so after the rebase they forked the chain at an older tip and still described tables that no longer exist. drizzle-kit reported a non-commutative chain: two branches each adding sentCount. Neither migration.sql changed — the SQL was always correct. What changed is the snapshots' lineage and content: - 20260911081114_add_comment_automation_delivery_stats is renamed to 20260913042025_... so folder order matches prevIds order; it used to sort between two of main's own migrations while claiming to follow the older tip. - Both snapshots are rebuilt as "main's tip + this branch's own entities", dropping the AIAssistant/AITrigger entries they should never have carried. normalizeReplyTexts moves into fbCommentAutomationService, where main's #1098 refactor put every write to this table. It was applied per call site before, which left the template installer out — and a row whose `value` disagrees with its `values` sends the wrong text with no error. Verified with drizzle-kit check ("Everything's fine") and db:check-drift. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: Deathgiver <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[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
FBCommentAutomationMisstable, so a filter decline is recorded with a reason instead of vanishing.{{total_tagged}}/{{total_new_tagged}}) and multi-text public replies (several comment replies that still count as one reply).Changes
New capability
packages/database—FBCommentAutomationMisstable + migration; misses live apart fromFBCommentAutomationEventbecause that table purges failed rows nightly, which would walk the denominator down every night.apps/worker/src/integration/handlers/comment-automation/— miss collection on every filter decline, comment tag counters, multi-text public reply dispatch.apps/builder+packages/analytics-nextjs— stat columns, drill-down dialog, replies chart, error logs, day/month bucketing. NewReplyTextsField; all strings viauseTranslations()across all 20 locales.Fixes
textprivate reply:markDeliveredran beforerecordReplyEventinserted the row, so the UPDATE matched nothing — and Seen requiresdeliveredAt IS NOT NULL. The row is now born delivered.commentAnchor, while every button encoder readsmetadata.commentAutomationId.flow/AIAgentreply was enqueued before its analytics row existed; with noreplyAfterthe job could settle a row that was not there yet. Dispatch is deferred until after the row is written.metadataentirely — losing comment-automation, broadcast and sequence attribution alike.markClickedcould double-count concurrent clicks;markSeenaccepted a read receipt older than the reply;settleEventnever clearedfailedAton the way back tosent;getContactspaged without a tiebreaker and counted contacts the list did not show.Observability
warns (click with no attribution, click matching no row) plus threeLOG_DEBUG-gated diagnostics now cover encode → tap → lookup → count.logDiagnosticcallsisLevelEnabledthrough an optional call, so the repo's hand-rolled logger doubles in tests opt out instead of throwing.Test plan
pnpm lint(includes i18n-check and the drizzle drift guard)pnpm --filter worker check-types,--filter builder,--filter @chatbotx.io/analytics,--filter @chatbotx.io/integration-messengerpnpm --filter worker test— 2295 passedpnpm --filter builder test— 3591 passedpnpm --filter @chatbotx.io/analytics test— 215 passedpnpm --filter @chatbotx.io/integration-messenger test— 281 passedpnpm --filter @chatbotx.io/database test— 706 passeddb:migrateon staging — not run here, needs explicit approval per repo rulesreplyAfter(delay 0, the race condition) → Delivered rises, tapping raises Clicked----across the funnel, while its own analytics page still shows data🤖 Generated with Claude Code