fix: replace Telegraf with grammY to fix Bun TypeError crash#1066
fix: replace Telegraf with grammY to fix Bun TypeError crash#1066
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe Telegram adapter is migrated from the Telegraf SDK to the grammY SDK. Dependencies are updated, test assertions adjusted for the new library API, and the main adapter implementation refactored to use grammY's bot type, API methods, and startup flow. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔍 Comprehensive PR ReviewPR: #1066 — fix: replace Telegraf with grammY to fix Bun TypeError crash SummaryThis PR correctly migrates the Telegram adapter from Telegraf to grammY. All critical paths are accurate: the Verdict:
🟡 Medium Issue — Misleading log when
|
Fix ReportAll 4 review findings have been addressed in commit fd03d2d. Fixed (4/4)MEDIUM — Misleading const maskedId = userId !== undefined ? `${String(userId).slice(0, 4)}***` : 'unknown';LOW — Post-startup bot crash silently dropped LOW — Silent message drop when LOW/Test — Validation
|
Archon PR Validation ReportVerdict: APPROVE SummaryClean migration from EOL Telegraf v4 to grammY, fixing a deterministic Bun crash where Bug Confirmation
IssuesNo blocking issues found. Fix quality: 5/5. What's Done Well
Validated by archon-validate-pr workflow |
Telegraf v4's internal `redactToken()` assigns to readonly `error.message` properties, which crashes under Bun's strict ESM mode. Telegraf is EOL. Changes: - Replace `telegraf` dependency with `grammy` ^1.36.0 - Migrate adapter from Telegraf API to grammY API (Bot, bot.api, bot.start) - Use grammY's `onStart` callback pattern for async polling launch - Preserve 409 retry logic and all existing behavior - Update test mocks from telegraf types to grammy types Fixes #1042 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix misleading 'unde***' log when ctx.from is undefined; use 'unknown' to match the Slack/Discord adapter pattern - Log post-startup bot runtime errors before reject() (no-op after onStart fires but errors are now visible in logs) - Add debug log when message is dropped due to no handler registered - Add stop() unit test to guard against grammY API rename regressions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fd03d2d to
a5e5d5c
Compare
…1042 fix: replace Telegraf with grammY to fix Bun TypeError crash
Summary
telegrafwithgrammyinpackages/adaptersto fix a crash on Bun where Telegraf's internalredactToken()function assigns to a non-writableerror.messageproperty, throwingTypeError: Attempted to assign to readonly propertyon everybot.launch()callfetch(nonode-fetch) and has no error-mutation patternsdropPendingUpdates, auth checks, message splitting, and the adapter's public interfaceChanges
packages/adapters/package.jsontelegraf ^4.16.0withgrammy ^1.36.0packages/adapters/src/chat/telegram/adapter.tsBotclass,bot.api.*calls,message:textfilter,bot.start()withonStartcallback)packages/adapters/src/chat/telegram/adapter.test.tstelegraftogrammytypes; updatelaunch→startmock withonStartcallback patternbun.lockbun installKey API differences handled:
bot.telegram.sendMessage→bot.api.sendMessagebot.launch({ dropPendingUpdates })→bot.start({ drop_pending_updates, onStart })wrapped in a Promise that resolves ononStart(grammY'sstart()only resolves when the bot stops)bot.on('message', ...)with manual'text' in ctx.messagecheck →bot.on('message:text', ...)filterhandlerTimeout: Infinityremoved — grammY has no handler timeout by defaultValidation
All checks pass on the migrated code:
bun run type-checkbun run lintbun run format:checkbun run testFixes #1042
Summary by CodeRabbit
Refactor
Tests