Skip to content

fix(instagram-facebook): send private reply via page node, not igId - #875

Merged
sung17 merged 1 commit into
mainfrom
fix/instagram-facebook-private-reply-endpoint
Jul 31, 2026
Merged

sung17 merged 1 commit into
mainfrom
fix/instagram-facebook-private-reply-endpoint

Conversation

@sung17

@sung17 sung17 commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Instagram comment automation's private reply (DM) was silently broken for accounts connected via Facebook Login, while public comment replies worked fine.
  • sendPrivateReply was posting to ${igId}/messages, which is the endpoint for the separate Instagram-Login package. For Page-token connections (Facebook Login), Meta's Messenger Platform requires POST /<PAGE_ID>/messages for private replies.

Changes

  • integrations/instagram-facebook/src/apis/comment.ts: sendPrivateReply now posts to ${version}/${auth.metadata.pageId}/messages instead of ${version}/${auth.metadata.igId}/messages, matching Meta's documented private-reply endpoint for Page-token connections. Updated the misleading comment above the function (it previously and incorrectly justified the igId endpoint).

Test plan

  • pnpm --filter @chatbotx.io/integration-instagram-facebook check-types
  • pnpm lint
  • Manual verification: trigger a private-reply comment automation on an Instagram account connected via Facebook Login and confirm the DM is delivered

sendPrivateReply posted to `${igId}/messages`, but Meta's Messenger
Platform private-reply endpoint for Page-token connections is
`/<PAGE_ID>/messages`. This left IG-via-Facebook-Login private replies
silently broken while public comment replies (a different endpoint)
kept working.
@github-actions github-actions Bot added the bug Something isn't working as expected label Jul 31, 2026
@sung17
sung17 merged commit f1d9699 into main Jul 31, 2026
7 checks passed
viethung0o0 pushed a commit that referenced this pull request Sep 7, 2026
…875)

sendPrivateReply posted to `${igId}/messages`, but Meta's Messenger
Platform private-reply endpoint for Page-token connections is
`/<PAGE_ID>/messages`. This left IG-via-Facebook-Login private replies
silently broken while public comment replies (a different endpoint)
kept working.

Co-authored-by: Deathgiver <[email protected]>
sung17 added a commit that referenced this pull request Sep 9, 2026
…#1122)

sendPrivateReplyMessage posted to `{igId}/messages`, which Meta rejects with
`(#3) Application does not have the capability to make this API call.` even when
the app holds instagram_manage_messages, pages_messaging and Human Agent at
Advanced Access. For Instagram via Facebook Login the `messages` edge only
exists on the Page node, so every private reply on that channel failed: the
automation's `text` and `AIAgent` replies, the first message of a `flow` reply,
and the agent's manual private reply from the inbox.

This is the second time the fix has been needed. #875 moved the endpoint to
`pageId`, then #945 moved it back to green a stale test whose fixture carried no
`pageId` at all — so the endpoint silently became `/undefined/messages` and the
assertion on the IG node kept passing. The test is now the guard instead of the
cause: the fixture carries a `pageId` distinct from `igId`, and a new case
asserts the IG node is never called.

Also guards a missing `pageId` explicitly rather than building
`/undefined/messages`, which is the silent failure mode that hid the regression.

Two adjacent error-mapping bugs surfaced while tracing this:

- Code 3 was in neither Instagram mapper, so it fell through to the
  `type === "OAuthException"` fallback and was reported as AUTH_FAILED —
  pointing operators at a reconnect that could never help. It is a capability
  problem, so it now maps to PERMISSION_DENIED (permanent), as messenger
  already does.
- instagram-facebook's isRevokedTokenError matched *any* OAuthException,
  including code 3, making the disconnect flow skip its remote teardown for
  unrelated errors. Narrowed to code 190 plus a revoked subcode, matching the
  Instagram Login variant, which excludes a bare 190 as ambiguous to avoid
  false-positive disconnects.

Unrelated, found in the same log: the getProfile failure in received-message.ts
logged under `error`, so pino dropped the stack trace. Keyed to `err`.

Co-authored-by: Deathgiver <[email protected]>
hello-jackytruong referenced this pull request in hello-jackytruong/ChatWorkAI Nov 22, 2026
… (#1122)

sendPrivateReplyMessage posted to `{igId}/messages`, which Meta rejects with
`(#3) Application does not have the capability to make this API call.` even when
the app holds instagram_manage_messages, pages_messaging and Human Agent at
Advanced Access. For Instagram via Facebook Login the `messages` edge only
exists on the Page node, so every private reply on that channel failed: the
automation's `text` and `AIAgent` replies, the first message of a `flow` reply,
and the agent's manual private reply from the inbox.

This is the second time the fix has been needed. #875 moved the endpoint to
`pageId`, then #945 moved it back to green a stale test whose fixture carried no
`pageId` at all — so the endpoint silently became `/undefined/messages` and the
assertion on the IG node kept passing. The test is now the guard instead of the
cause: the fixture carries a `pageId` distinct from `igId`, and a new case
asserts the IG node is never called.

Also guards a missing `pageId` explicitly rather than building
`/undefined/messages`, which is the silent failure mode that hid the regression.

Two adjacent error-mapping bugs surfaced while tracing this:

- Code 3 was in neither Instagram mapper, so it fell through to the
  `type === "OAuthException"` fallback and was reported as AUTH_FAILED —
  pointing operators at a reconnect that could never help. It is a capability
  problem, so it now maps to PERMISSION_DENIED (permanent), as messenger
  already does.
- instagram-facebook's isRevokedTokenError matched *any* OAuthException,
  including code 3, making the disconnect flow skip its remote teardown for
  unrelated errors. Narrowed to code 190 plus a revoked subcode, matching the
  Instagram Login variant, which excludes a bare 190 as ambiguous to avoid
  false-positive disconnects.

Unrelated, found in the same log: the getProfile failure in received-message.ts
logged under `error`, so pino dropped the stack trace. Keyed to `err`.

Co-authored-by: Deathgiver <[email protected]>

This branch was previously deployed

1 inactive deployment
dev — 6125e8ef Deployed Jul 31, 2026 by sung17 via Build builder #2201
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