Repository navigation
feat(tiktok): add messaging and comments switches to the app credential - #1572
Conversation
TikTok's Business Messaging API is not available to accounts registered in the EEA, Switzerland or the UK, so they can never grant message.list.*. ChatbotX required those scopes, so such accounts could not connect at all, not even for comment automation. The TikTok app credential now carries two switches, Messaging and Comments (absent = both on, at least one required). With Messaging off the authorize request asks for no messaging scope, both connect paths require the comment scopes instead, and saving subscribes only the COMMENT webhook. The private reply and Comment-to-Message refuse early on a connection that cannot message. Closes #1563 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed scopes Both token-refresh paths re-stamp metadata.scopes from TikTok's refresh response, so an empty or partial answer there would have blocked the private reply and Comment-to-Message on a working DM connection. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks again @rancaHoratiu for reporting #1563 and for the original proposal in #1564. Your write-up made the root cause easy to track down, and this PR builds directly on your idea. The main difference is that comments-only is now a switch on each TikTok app credential instead of a server-wide env var, so EU and non-EU accounts can be served side by side. If you get a chance to try it with your EEA account (turn Messaging off in the TikTok credential settings, then connect), we'd love to hear whether comments come through as expected. |
|
Thanks @sung17, that was fast! The per-credential switches are exactly what we needed. Our TikTok app is still in review; I'll test with Messaging off and report back here once it's approved. |
|
Hey, it's ya boy again 👋 @sung17 Tested this on our EU account (Romania), self-hosted on 1.18.0, and comments work end to end:
One bug in the connect flow, though. The OAuth but
Workaround we used: replace the Possible fix: decode with Thanks for shipping the switches so quickly, this is exactly what we needed 🙏 |
|
@rancaHoratiu thanks a lot for the detailed test and the clear bug report 🙏 You're right: TikTok encodes the OAuth Once it's merged, the TikTok connect flow should work without the |
TikTok encodes the OAuth state as base64url, but the integrations callback decoded it with atob, which rejects "-" and "_". Whenever the encoded state contained them the callback returned 404, so connecting TikTok failed for most workspaces. Decode with Node's base64url decoder, which accepts both base64url and the standard base64 the other integrations produce with btoa. Reported in #1572 (comment 6650507443). Co-authored-by: Deathgiver <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…al (#1572) * feat(tiktok): add messaging and comments switches to the app credential TikTok's Business Messaging API is not available to accounts registered in the EEA, Switzerland or the UK, so they can never grant message.list.*. ChatbotX required those scopes, so such accounts could not connect at all, not even for comment automation. The TikTok app credential now carries two switches, Messaging and Comments (absent = both on, at least one required). With Messaging off the authorize request asks for no messaging scope, both connect paths require the comment scopes instead, and saving subscribes only the COMMENT webhook. The private reply and Comment-to-Message refuse early on a connection that cannot message. Closes #1563 Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(tiktok): default credential features to both on when omitted Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(tiktok): decide messaging from connect-time features, not refreshed scopes Both token-refresh paths re-stamp metadata.scopes from TikTok's refresh response, so an empty or partial answer there would have blocked the private reply and Comment-to-Message on a working DM connection. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Deathgiver <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
TikTok encodes the OAuth state as base64url, but the integrations callback decoded it with atob, which rejects "-" and "_". Whenever the encoded state contained them the callback returned 404, so connecting TikTok failed for most workspaces. Decode with Node's base64url decoder, which accepts both base64url and the standard base64 the other integrations produce with btoa. Reported in #1572 (comment 6650507443). Co-authored-by: Deathgiver <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Closes #1563. Supersedes #1564; thanks to @rancaHoratiu for the report and the original proposal.
Why
TikTok's Business Messaging API is not available to accounts registered in the EEA, Switzerland or the UK, so they can never grant
message.list.*. ChatbotX treated those scopes as required, and saving the credential failed whenever TikTok rejected theDIRECT_MESSAGEwebhook. Those accounts therefore couldn't use comment automation either, even though it only needs the comment scopes.#1564 proposed a deployment-wide
TIKTOK_COMMENTS_ONLYenv var. This PR makes the choice per credential instead, for two reasons:callbackHandlerwould still have refused EU accounts.What
TiktokCredential.features). If unset, both are on, so existing credentials behave exactly as before. At least one must stay on (zod refine, and the UI disables the last switch that is on).integrations/tiktok/src/lib/scopes.ts):tiktokRequestedScopes(features): the authorize request asks only for what the enabled features use. With Messaging off, no messaging scope is requested.tiktokRequiredScopes(features): what the grant must contain. With Messaging off,comment.list+comment.list.manageare required instead of the messaging scopes.assertTiktokGrant: one check now used by both connect paths (exchangeCodeandcallbackHandler). It stampsmetadata.featureson the connection.subscribeTiktokWebhooks): only the enabled features are subscribed. With Messaging off, a failedCOMMENTsubscription fails the save. With both on, the behaviour is unchanged: DM failure is fatal, comment failure is best-effort.tiktokCanMessage, read from the granted scopes):ChannelErrorpermission_denied)setCommentToMessagefields.tiktok.*keys in all 21 locales.docs/comment-automation.md.No migration: the credential config is encrypted JSON.
Public API: exempt under invariant 23, because this is a platform credential setting (platform administration).
Test plan
pnpm lintcheck-typesfor all packages (pre-commit hook, 63/63)@chatbotx.io/integration-tiktok: 139 tests. New cases: scopes in both modes, both connect paths with a comments-only grant, webhook subscription per feature, private-reply refusal.🤖 Generated with Claude Code