Skip to content

refactor: migrate TelegramAdapter to grammY and remove Telegraf#6

Merged
shepherdwind merged 1 commit into
mainfrom
refactor/005-remove-telegraf
Apr 5, 2026
Merged

refactor: migrate TelegramAdapter to grammY and remove Telegraf#6
shepherdwind merged 1 commit into
mainfrom
refactor/005-remove-telegraf

Conversation

@shepherdwind

Copy link
Copy Markdown
Owner

Background

Task 005 of the grammY migration plan. The main integration task — remove Telegraf dependency and wire everything through grammY.

Approach

Rewrite TelegramAdapter to use grammY Bot, register conversations and command handlers, and delete all Telegraf-specific code.

Changes

Deleted (7 files, ~1200 lines removed):

  • command-handlers.ts — replaced by grammY middleware chain
  • base-command-handler.ts — no longer needed
  • add-command-handler.ts — replaced by addBill conversation
  • categorization-command-handler.ts — replaced by categorization conversation
  • categorization-utils.ts, categorization-types.ts — internalized
  • categorization-command-handler.test.ts — handler deleted

Modified:

  • telegram.adapter.ts — full rewrite using grammY Bot, conversations, short ID registry
  • query-command-handler.ts — removed BaseCommandHandler dependency
  • custom-query-command-handler.ts — removed BaseCommandHandler dependency
  • conversations/categorization.ts — use short ID registry for merchant lookup, cleanup on all exit paths
  • types.ts — removed Telegraf TextMessage type
  • package.json — removed telegraf dependency

Key design:

  • Short ID hashing for callback data (Telegram 64-byte limit)
  • Pending merchant registry (Map) for conversation data lookup
  • All categorization exit paths clean up registry to prevent leaks

Testing

39 tests pass (7 suites). No Telegraf imports remain in codebase.

Code Review

  • Review tool: Codex
  • Rounds: 3 (max)
  • Issues fixed: (1) preserve merchant metadata in notifications (P1), (2) short ID hashing for callback data limit (P1), (3) registry cleanup on all exit paths (P2), (4) bot.start() fire-and-forget with onStart callback (P1)

- Rewrite TelegramAdapter using grammY Bot with conversations
- Register addBill and categorization conversations
- Wire /add, /query, /cancel commands and callback handlers
- Add short ID hashing for callback data (Telegram 64-byte limit)
- Add pending merchant registry for conversation data lookup
- Delete CommandHandlers, BaseCommandHandler, AddCommandHandler,
  CategorizationCommandHandler, categorization-utils, categorization-types
- Remove telegraf npm dependency
- Clean up all exit paths in categorization to prevent registry leaks

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@shepherdwind shepherdwind merged commit 1037b47 into main Apr 5, 2026
3 checks passed
@shepherdwind shepherdwind deleted the refactor/005-remove-telegraf branch April 5, 2026 00:04
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