Skip to content

fix(flow): re-check instagram profile fields live in condition steps - #1579

Merged
sung17 merged 1 commit into
mainfrom
fix/instagram-condition-live-follow
Oct 29, 2026
Merged

sung17 merged 1 commit into
mainfrom
fix/instagram-condition-live-follow

Conversation

@sung17

@sung17 sung17 commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

A customer's Instagram comment-to-DM flow got stuck in a loop. The flow checks "Follows business on Instagram". If the contact isn't following yet, it asks them to follow and offers an "I'm Following" button that goes back to the same Condition. Even after the contact followed, the Condition kept taking the "not following" branch.

Cause: the Condition step matches against ContactInbox.followsBusiness, which is captured once when the contact is created. The background snapshot job also only fills empty columns. Only rendering the {{ig_follow_business}} variable re-fetched the value, and that result was cached for 5 minutes.

Fix: when a Condition reads an Instagram profile field (followsBusinessOnInstagram, businessFollowsUserOnInstagram, verifiedAccountOnInstagram, followerCountOnInstagram), it fetches the profile live and writes it to the contact inbox before matching.

  • packages/variables: new refreshContactProfileSnapshot. It drops the cached snapshot and reuses the existing resolveLiveProfileSnapshot, which fetches the profile and persists it through contactInboxService.refreshProfileSnapshot.
  • apps/worker handleCondition: calls it once per Condition run, only when a case uses one of those fields.

Behavior

  • Fetch fails (rate limit, expired token, network error): nothing is thrown, and the Condition matches against the stored value, as before.
  • Redis invalidation fails: the live fetch still runs.
  • Instagram omits a field (null): the stored value is kept, never turned into false (existing COALESCE behavior).
  • Unaffected: Conditions without these fields, non-Instagram channels, and broadcast audience filters (they still read the stored columns).
  • API calls: one Graph call per Condition run that uses these fields. The call has the HTTP client's 30s timeout, and instant flow loops are capped by MAX_NODE_EXECUTIONS.

Not changed: if a contact has several Instagram inboxes, the filter still matches when any inbox row matches. Only the current conversation's inbox is refreshed.

No schema change, no migration, no new public API operation (this is internal step behavior).

Test plan

  • condition-handler.test.ts: refresh runs once before matching when a case uses an Instagram profile field, and is skipped otherwise
  • refresh-profile-snapshot.test.ts: invalidates the cache before fetching and persists the result; skips unsupported channels; never throws on fetch or inbox-lookup failure; still fetches when cache invalidation fails
  • Full worker suite (4212 tests) and @chatbotx.io/variables suite (288 tests) pass
  • pnpm lint; typecheck passed in the pre-commit hook (64 packages)
  • Manual check on a real IG account: comment while not following → red branch; follow → tap "I'm Following" → green branch, and followsBusiness becomes true

🤖 Generated with Claude Code

The Condition step matched "follows business on Instagram" (and the other
Instagram profile filters) against the snapshot captured once at contact
creation, so a contact who followed after their first comment never reached
the "following" branch and looped back to the follow prompt.

When a condition reads one of those fields, fetch the profile live first and
write it through to the contact inbox before matching. A failed fetch keeps
the stored value, so routing never breaks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the bug Something isn't working as expected label Oct 29, 2026
@sung17
sung17 merged commit a4b4c61 into main Oct 29, 2026
15 checks passed
hello-jackytruong referenced this pull request in hello-jackytruong/ChatWorkAI Nov 22, 2026
…(#1579)

The Condition step matched "follows business on Instagram" (and the other
Instagram profile filters) against the snapshot captured once at contact
creation, so a contact who followed after their first comment never reached
the "following" branch and looped back to the follow prompt.

When a condition reads one of those fields, fetch the profile live first and
write it through to the contact inbox before matching. A failed fetch keeps
the stored value, so routing never breaks.

Co-authored-by: Deathgiver <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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