Repository navigation
fix(instagram-facebook): send private replies via the page node again - #1122
Merged
Merged
Conversation
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`.
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 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
(#3) Application does not have the capability to make this API call.The app was not at fault — it holdsinstagram_manage_messages,pages_messaging,instagram_manage_commentsand Human Agent at Advanced Access, and normal DMs kept working. Meta simply does not expose themessagesedge on the IG node for this login type, so{igId}/messagescan never succeed; the reply has to go to{pageId}/messages.pageId; perf(builder): optimize build pipeline and gate types in CI #945 moved it back to green a stale test whose fixture carried nopageIdat all, so the endpoint silently became/undefined/messageswhile the assertion on the IG node kept passing. The test is now the guard rather than the cause.textandAIAgentreplies, the first message of aflowreply, and the agent's manual private reply from the inbox (a separate entry point viahandlers/comment/outgoing-private-reply).Changes
integrations/instagram-facebook/src/apis/comment.ts—sendPrivateReplyMessageposts to{pageId}/messages. Guards a missingpageIdexplicitly instead of building/undefined/messages(the silent failure mode that hid the regression), and isasyncso that guard rejects rather than throwing synchronously. The doc comment now records why the Page node is correct and warns against reverting.integrations/instagram-facebook/__tests__/send-private-reply.test.ts— fixture carries apageIddistinct fromigId(the old one could not tell the two nodes apart), asserts the Page node, adds a regression case asserting the IG node is never called, and covers the missing-pageIdguard.integrations/instagram-facebook/src/lib/error-mapper.ts,integrations/instagram/src/lib/error-mapper.ts— code 3 was in neither Instagram mapper, so it fell through to thetype === "OAuthException"fallback and was reported asAUTH_FAILED, pointing operators at a reconnect that could never help. It is a capability problem, so it now maps toPERMISSION_DENIED(permanent), asintegrations/messengeralready does.integrations/instagram-facebook/src/lib/error-mapper.ts—isRevokedTokenErrormatched anyOAuthException, 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).integrations/instagram-facebook/__tests__/error-mapper.test.ts(new) — pins both of the above.apps/worker/.../received-message.ts— unrelated, found in the same log: thegetProfilefailure logged undererror, so pino dropped the stack trace. Keyed toerrper the structured-logging invariant.docs/fb-comment-automation.md, the integration README, and thefb-comment-automationskill all record the Page-vs-IG node rule and the fix(instagram-facebook): send private reply via page node, not igId #875 → perf(builder): optimize build pipeline and gate types in CI #945 history, so the next reader does not "fix" it back. Also notes that both Instagram packages logmodule=integration-instagram, so production failures must be attributed by request host, not module name.Not in this PR
apis/page.tsreads the API version offauth.version, which the connect flow never writes (it only writesauth.metadata.version), sosendInstagramMessageis pinned toDEFAULT_API_VERSION(v23.0) whilecomment.ts/attachment.tsuse the configuredv25.0. Documented in the README; fixing it changes the version of a working send path, so it deserves its own change and verification.Test plan
pnpm lint(6297 files, includes i18n parity + schema drift)pnpm --filter @chatbotx.io/integration-instagram-facebook check-typespnpm --filter @chatbotx.io/integration-instagram check-typespnpm --filter worker check-typespnpm --filter builder check-typespnpm --filter @chatbotx.io/integration-instagram-facebook test— 63 passedpnpm --filter @chatbotx.io/integration-instagram test— 81 passedpnpm --filter worker test— 2094 passedpnpm --filter builder test— 3325 passed/<PAGE_ID>/messages) and the unified Instagram Platform page (/<APP_USERS_IG_ID>/messages), and this file has already flip-flopped twice, so one manual call settles it. Samecomment_id(inside the 7-day window), samev25.0, both nodes:<PAGE_ID>should returnrecipient_id+message_id;<IG_ID>should reproduce#3.text,AIAgent,flow(first message), and the agent's manual private reply from the inbox (text and with an attachment)