fix(instagram): correct story-reply message direction and contact profiles - #885
Merged
Merged
Conversation
…files
Meta echoes a genuine first-time customer message (story reply or plain
inbox DM) as `is_echo:true` with `sender.id` equal to the page's own IG
business account id. The worker treated that as page-authored:
- New contacts got no name/avatar, because profile lookup was
unconditionally skipped for any "outgoing" new-contact message
(skipProfileLookup was redundant since the getProfile call is already
try/caught, so removing it is safe).
- Story-reply automation never fired for a brand-new contact's first
story reply, since the message stayed classified as agent-sent
(senderType "user"), failing worker.ts's isFromContact gate.
Fix: always attempt profile lookup for new contacts, and flip a
new-contact's outgoing story-reply message back to incoming before
persisting (existing contacts are left untouched, since a real agent
reply-echo to a known contact must not be reinterpreted as inbound).
Also unifies the story-reply contentAttributes shape check
(`{ type: "story_reply", story }` vs. the legacy `{ storyReply }` still
present on historical rows) behind one shared `getStoryReply()` helper
in the SDK, used by both the worker routing and the direction
correction, instead of three independent ad hoc casts that had already
drifted from each other.
viethung0o0
pushed a commit
that referenced
this pull request
Sep 7, 2026
…files (#885) Meta echoes a genuine first-time customer message (story reply or plain inbox DM) as `is_echo:true` with `sender.id` equal to the page's own IG business account id. The worker treated that as page-authored: - New contacts got no name/avatar, because profile lookup was unconditionally skipped for any "outgoing" new-contact message (skipProfileLookup was redundant since the getProfile call is already try/caught, so removing it is safe). - Story-reply automation never fired for a brand-new contact's first story reply, since the message stayed classified as agent-sent (senderType "user"), failing worker.ts's isFromContact gate. Fix: always attempt profile lookup for new contacts, and flip a new-contact's outgoing story-reply message back to incoming before persisting (existing contacts are left untouched, since a real agent reply-echo to a known contact must not be reinterpreted as inbound). Also unifies the story-reply contentAttributes shape check (`{ type: "story_reply", story }` vs. the legacy `{ storyReply }` still present on historical rows) behind one shared `getStoryReply()` helper in the SDK, used by both the worker routing and the direction correction, instead of three independent ad hoc casts that had already drifted from each other. Co-authored-by: Deathgiver <anonymous@users.noreply.github.com>
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
is_echo:truewithsender.idequal to the page's own IG business account id, which the worker treated as page-authored.isFromContactgate.Changes
apps/worker/src/integration/handlers/received-message.ts— always attempt profile lookup for new contacts (the existing try/catch already makes a failed lookup safe); flip a new-contact's outgoing story-reply message back toincomingbefore persisting. Existing contacts are left untouched so a real agent reply-echo isn't reinterpreted as inbound.apps/worker/src/integration/worker.ts— routes story-reply automation using the shared shape check instead of an inline duplicate.packages/sdk/src/lib/shared/message.ts— newgetStoryReply()helper unifying the story-replycontentAttributesshape check (current{ type: "story_reply", story }vs. legacy{ storyReply }on historical rows), used by both the worker routing and the direction correction to prevent the two from drifting apart again.integrations/instagram/src/handlers/message/incomming-message.ts,integrations/instagram-facebook/src/handlers/message/incoming-message.ts— emit the current typed story-reply shape.apps/builder/src/features/messages/components/message-item.tsx+ locale files — render "Replied to your story" context in the inbox for story-reply messages.Test plan
pnpm lintpnpm --filter worker check-typespnpm --filter @chatbotx.io/sdk check-typespnpm --filter builder check-typespnpm --filter worker test(140 files / 1313 tests passing, including new regression tests for the story-reply direction correction)