4.2 KiB
4.2 KiB
Tasks: enterprise-telegram-client
Change ID: enterprise-telegram-client
Package: @suaveplan/telegram-client
Target path: universal/social/telegram-client
Prerequisite packages on Verdaccio: @suaveplan/error, @suaveplan/types, @suaveplan/retry
0. Pre-flight (non-negotiable)
- 0.1 Confirm clean working tree (
git statusreports nothing) and no in-flight worktrees with uncommitted work (git worktree listthengit statusin each) - 0.2 If any worktrees exist under
.claude/worktrees/, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (git worktree remove) before opening a new one — code that has been lost twice on main is the failure mode this guards against. - 0.3 Confirm the package set in
MANIFEST.mdmatchesfind packages -maxdepth 3 -name package.jsoncount. Drift here means a prior change archived without regenerating the manifest.
1. Scaffold
- Create
universal/social/telegram-client/withsrc/,tests/,src/__benchmarks__/and all feature subdirectories per the layout inproposal.md. - Write
package.jsonat version0.1.0with"type": "module","sideEffects": false, correctexportsmap,dependencies, anddevDependencies. - Write
tsconfig.jsonextending@suaveplan/typescript-config/library.json. - Write
vitest.config.tsusingcreateTestConfig()from@suaveplan/testing/config. - Add
lint,typecheck,test,test:coverage,build,docs:checkscripts.
2. Types + errors
src/types/common.ts—TelegramBotOptions,SendMessageOptions,SendMediaOptions,EditOptions,AnswerCallbackOptions,GetUpdatesOptions,WebhookOptions,TelegramMessage,TelegramUpdate,TelegramUser,InlineQueryResult,InlineKeyboardMarkup,ReplyKeyboardMarkup,ReplyKeyboardRemove.src/types/common.md(≥200 words, both examples, API reference).src/error-codes.ts—TelegramErrorCode(7 codes), metadata, register, eager call.src/types/schemas.ts+schemas.md— Zod schemas.
3. Core modules
src/core/api-caller/—ApiCaller: callshttps://api.telegram.org/bot{token}/method; parses JSON; throwsTELEGRAM_API_ERRORonok:false(with Telegramerror_codeanddescription); handles 429 withretry_after; wraps with@suaveplan/retry. Tests: success, ok:false, 429.src/core/telegram-bot/—TelegramBot: implements all public methods.sendPhoto/sendDocumentwith URL string usesphoto=urlform data; withUint8Arrayusesmultipart/form-data. Tests:sendMessagetext+HTML parse_mode,sendPhotoURL,editMessageText,deleteMessage,answerCallbackQuery,setWebhook,deleteWebhook,getMe.src/core/update-poller/—getUpdates(options):AsyncGenerator<TelegramUpdate>that managesoffset(last_update_id + 1); each iteration callsgetUpdatesAPI withtimeout=25(long-poll); onAbortSignal, finishes current batch and yields. Tests: yields updates in order, offset advances, abort exits generator cleanly.src/keyboards/keyboard-builder/—inlineKeyboard,replyKeyboard,removeKeyboard: pure constructors. Tests: 2×2 inline, 3-button reply, remove, ForceReply.
4. OTel instrumentation
- Span
telegram.api_callwith attributetelegram.method; countertelegram.api_total; histogramtelegram.api_duration_ms.
5. Property-based tests (tests/property.test.ts)
- Keyboard builder: for arbitrary row/button arrays,
inlineKeyboard(rows)produces JSON withinline_keyboardarray of same dimensions.
6. Benchmarks (src/__benchmarks__/telegram-client.bench.ts)
inlineKeyboardconstruction for 10-row × 5-button keyboard 100 000 times.
7. Docs + verify
- One
.mdper implementation file (≥200 words, both examples, API reference). RootREADME.md. bunx turbo lint typecheck test --filter=@suaveplan/telegram-client— green.bunx turbo test:coverage --filter=@suaveplan/telegram-client— 100%.bun scripts/publish.ts --package @suaveplan/telegram-client.- Archive:
openspec/archive/2026-04-24-enterprise-telegram-client/.