Repository navigation
feat(telegram): add a persistThreadHistory option - #1079
mlenczewski-tidio wants to merge 1 commit into
Conversation
Telegram always copied every incoming message into the Chat state adapter, and persistThreadHistory was typed as the literal `true`, so neither config nor a subclass could turn it off. An app that keeps its own transcript ended up with a second, unredacted copy of every message in the state store. Add a persistThreadHistory config option, defaulting to true as before, and type the field as boolean so a subclass can override it too. Signed-off-by: Miłosz Lenczewski <m.lenczewski@tidio.net>
|
@mlenczewski-tidio is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Thanks for this. The change is small and correct: core only reads the flag in two places (incoming-message persistence and wiring the history cache into threads), so a per-instance boolean works, the default is unchanged, and minor is the right bump. A few things before merge:
Required
- The wording undersells what the flag does. The JSDoc in
types.ts, the docs row intelegram.mdx, and the changeset all say turning it off stops persisting incoming messages. It also stops persisting the bot's own sent messages:ThreadandChannelonly append posts when the history cache is wired in, and that cache is now gated on this flag (for examplethread.tsL568 andchannel.tsL339). Please say "incoming and sent messages", matching how the Twitch docs describepersistThreadHistory.
Nits
- Existing data. Turning the flag off does not remove history that is already in the state adapter; it stays until its TTL expires. A sentence in the docs row would save people from assuming it gets purged.
- Subclass override precedence. A subclass that declares
override readonly persistThreadHistory = falseignores thepersistThreadHistoryconfig value, because subclass field initializers run after the base constructor. That is expected, but a short note on the field (or in the JSDoc) would make the precedence explicit. - Test coverage. The new tests assert the property value only. That is fine since
chat.test.tsalready covers the core gating, but an integration-style test showing a Telegram message is not appended to state withpersistThreadHistory: falsewould lock in the end-to-end behavior. - Catalog (optional).
packages/catalog/src/adapters/official/telegram.tslists config-only options (nativeStreaming,streamingEditIntervalMs). Consider addingpersistThreadHistorythere, the way the web catalog entry listspersistMessageHistory.
|
Thanks for this, @mlenczewski-tidio. We wanted to rebase it and add a few docs and test changes, but this branch lives in a fork owned by the For future contributions, please open PRs from a fork under a personal account with "Allow edits by maintainers" turned on. Going forward we won't be able to accept PRs from organization-owned forks, since we can't make changes to them before merging. |
This picks up #1079 from @mlenczewski-tidio. That PR comes from a fork owned by the `tidio-tools` organization, and GitHub doesn't let maintainers push to organization-owned forks, so we couldn't update it in place. Their commit is kept with their authorship and sign-off, and a second commit adds the follow-up changes. The branch is rebased onto main, which resolves the merge conflict in `packages/adapter-telegram/src/subclass.test-d.ts` with the new long message tests. The Telegram adapter copied every incoming message into the Chat state adapter, and `persistThreadHistory` was typed as the literal `true`, so neither config nor a subclass could turn it off. An app that keeps its own transcript ended up with a second, unredacted copy of every message in the state store. This adds a `persistThreadHistory` option that defaults to `true`, and types the field as `boolean` so a subclass can override it. ```ts const telegram = createTelegramAdapter({ persistThreadHistory: false }); ``` With `false`, the SDK saves neither incoming messages nor the bot's own posts, so `thread.messages` and `bot.history.thread.list()` only see what the current process has cached. On serverless that's empty after a cold start. The Telegram docs, README, core history docs, and catalog entry now describe this. New tests run a real `Chat` with the Telegram adapter and check what lands in state with the option on and off. --------- Signed-off-by: Miłosz Lenczewski <m.lenczewski@tidio.net> Signed-off-by: Ben Sabic <bensabic@users.noreply.github.com> Co-authored-by: Miłosz Lenczewski <m.lenczewski@tidio.net> Co-authored-by: Ben Sabic <bensabic@users.noreply.github.com>
Summary
The Telegram adapter copies every incoming message into the Chat state adapter, and
persistThreadHistoryis typed as the literaltrue, so neither config nor a subclass can turn that off. An app that keeps its own transcript ends up with a second, unredacted copy of every message in the state store that nothing reads.persistThreadHistoryconfig option. It defaults totrue, so nothing changes unless you set it, the same way the web adapter'spersistMessageHistoryworks.boolean, so a subclass can override it too (override readonly persistThreadHistory = false).The adapter's own
fetchMessagesreads its in-process cache, not the state adapter, so turning the option off only affects whatthread.messages/channel.messagescan return from state.Test plan
true) andpersistThreadHistory: false.subclass.test-d.tsshowing a subclass can override the field withfalse. It fails against the old literaltruedeclaration and passes with this change.pnpm validatepasses.Checklist
git commit -s)pnpm validatepasses