Skip to content

fix(telegram): guard token.trim() against undefined to prevent startup crash#31973

Merged
steipete merged 2 commits intoopenclaw:mainfrom
ningding97:fix/31944-telegram-trim-crash
Mar 2, 2026
Merged

fix(telegram): guard token.trim() against undefined to prevent startup crash#31973
steipete merged 2 commits intoopenclaw:mainfrom
ningding97:fix/31944-telegram-trim-crash

Conversation

@ningding97
Copy link

Closes #31944

Problem

findTelegramTokenOwnerAccountId and the health-check path call account.token.trim() without null guard. When account.token is undefined (missing botToken config / tokenFile not found), the channel crashes on startup with:

Cannot read properties of undefined (reading 'trim')

Fix

Use (account.token ?? "").trim() in both call sites.

Tests

pnpm test -- extensions/telegram/src/channel.test.ts (5 tests pass)

@openclaw-barnacle openclaw-barnacle bot added channel: telegram Channel integration: telegram size: XS labels Mar 2, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 2, 2026

Greptile Summary

Fixed a startup crash in the Telegram extension when account.token is undefined (missing botToken config or tokenFile not found) by adding null guards using the nullish coalescing operator at two call sites.

  • Prevented crash in findTelegramTokenOwnerAccountId (channel.ts:47)
  • Prevented crash in health-check/startup path (channel.ts:468)
  • Fix correctly falls back to empty string, which then fails the empty check as expected

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • Simple, focused bug fix that correctly prevents a startup crash. All other token accesses in the file already use safe optional chaining. Tests pass.
  • No files require special attention

Last reviewed commit: d5ea338

@steipete steipete force-pushed the fix/31944-telegram-trim-crash branch from d5ea338 to 3610ace Compare March 2, 2026 18:33
steipete added a commit to ningding97/openclaw that referenced this pull request Mar 2, 2026
ningding97 and others added 2 commits March 2, 2026 18:33
…p crash

When account.token is undefined (e.g. missing botToken config),
calling .trim() directly throws "Cannot read properties of undefined".
Use nullish coalescing to fall back to empty string before trimming.

Closes openclaw#31944
@steipete steipete force-pushed the fix/31944-telegram-trim-crash branch from 3610ace to 68b3453 Compare March 2, 2026 18:33
@steipete steipete merged commit d52e5e1 into openclaw:main Mar 2, 2026
9 checks passed
@steipete
Copy link
Contributor

steipete commented Mar 2, 2026

Landed via temp rebase onto main.

  • Gate: pnpm test extensions/telegram/src/channel.test.ts
  • Land commit: 68b3453
  • Merge commit: d52e5e1

Thanks @ningding97!

execute008 pushed a commit to execute008/openclaw that referenced this pull request Mar 2, 2026
dawi369 pushed a commit to dawi369/davis that referenced this pull request Mar 3, 2026
OWALabuy pushed a commit to kcinzgg/openclaw that referenced this pull request Mar 4, 2026
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Telegram channel crashes on startup - Cannot read properties of undefined (reading 'trim'

2 participants