Skip to content

fix(telegram): tolerate out-of-range message timestamps - #947

Open
NecatiY wants to merge 2 commits into
profullstack:masterfrom
NecatiY:fix/telegram-out-of-range-timestamps
Open

fix(telegram): tolerate out-of-range message timestamps#947
NecatiY wants to merge 2 commits into
profullstack:masterfrom
NecatiY:fix/telegram-out-of-range-timestamps

Conversation

@NecatiY

@NecatiY NecatiY commented Aug 9, 2026

Copy link
Copy Markdown

Summary

toBotEvent in packages/bots/telegram called new Date(msg.timestamp).toISOString() with no NaN guard. msg.date from the Telegram API can be absent — undefined * 1000 === NaN — and new Date(NaN).toISOString() throws RangeError: Invalid time value, dropping the message before any handler runs.

This is the same bug class already fixed in discord (#919), whatsapp (#920), slack (#930) and signal (#932) — telegram was the only bot missed.

Fix

const date = new Date(msg.timestamp);
...
timestamp: Number.isNaN(date.getTime()) ? new Date(0).toISOString() : date.toISOString(),

toBotEvent is now exported so it can be tested, matching the pattern in the other bots.

Verification

  • Regression test added: falls back when Telegram provides an out-of-range timestamp (16 tests pass in the package)
  • Full suite: 712 files / 3523 tests pass
  • tsc -p tsconfig.json clean

Necati Yönet added 2 commits August 9, 2026 13:03
packages/bot/core and packages/bots/core both fail to compile with
TS2345: the finish() callback parameter was typed with a loose
{ type: string; ... } shape, which is not assignable to AIResult
(type must be the literal "result"). Type it as AIResult so the
workspace build (tsc -p tsconfig.json) passes in both trees.

Also fixes packages/bots/signal compile errors in the test file:
- IncomingMessage.groupId widened to string | null | undefined (the
  implementation already falls back with ??, so undefined is valid)
- test literal now includes isGroup and drops the unused raw field
toBotEvent called new Date(msg.timestamp).toISOString() with no NaN
guard. msg.date from the Telegram API can be absent/undefined
(undefined * 1000 = NaN), which threw RangeError: Invalid time value
and dropped the message before handlers ran. Mirrors the same fix
already shipped in discord (profullstack#919), whatsapp (profullstack#920), signal (profullstack#932)
and slack (profullstack#930): fall back to the epoch when the timestamp is
invalid. toBotEvent is now exported so it can be tested, matching
the pattern in the other bots.
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

1 similar comment
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: git fetch upstream master && git rebase upstream/master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant