From a4242201db8c98f7205dfb09ee1cf6d037432f57 Mon Sep 17 00:00:00 2001 From: f1devbin <280303226+f1devbin@users.noreply.github.com> Date: Sat, 21 Nov 2026 13:15:55 +0300 Subject: [PATCH] perf: lazy-load tab editors and extend Bot API drift checks - import tab controllers only on first activation; the landing page ships less JS - assert in e2e that tabs/* are not requested before connect - check InputProfilePhoto subtypes; the weekly watch also flags a stale spec source - bump version to 3.4.0 --- .github/workflows/bot-api-watch.yml | 28 +++++++++++++++++---- CHANGELOG.md | 7 ++++++ CLAUDE.md | 2 +- README.md | 2 +- package.json | 2 +- scripts/check-bot-api.mjs | 5 +++- scripts/screenshots.mjs | 7 ++++-- src/assets/js/main.js | 38 +++++++++++++++++++++-------- tests/check-bot-api.test.mjs | 4 +++ 9 files changed, 74 insertions(+), 21 deletions(-) diff --git a/.github/workflows/bot-api-watch.yml b/.github/workflows/bot-api-watch.yml index cd618b0..a76907c 100644 --- a/.github/workflows/bot-api-watch.yml +++ b/.github/workflows/bot-api-watch.yml @@ -27,24 +27,42 @@ jobs: code=$? cat report.md echo "status=$code" >> "$GITHUB_OUTPUT" + if grep -q "source may be stale" report.md; then + echo "stale=true" >> "$GITHUB_OUTPUT" + else + echo "stale=false" >> "$GITHUB_OUTPUT" + fi [ "$code" -le 1 ] - name: Open or update issue - if: steps.check.outputs.status == '1' + if: steps.check.outputs.status == '1' || steps.check.outputs.stale == 'true' env: GH_TOKEN: ${{ github.token }} run: | gh label create bot-api-update --color 2481cc --description "Telegram Bot API changed" 2>/dev/null || true version=$(sed -n 's/^Spec: \*\*Bot API \([0-9.]*\)\*\*.*/\1/p' report.md) + stale="${{ steps.check.outputs.stale }}" + status="${{ steps.check.outputs.status }}" { - echo "The Telegram Bot API spec differs from \`src/assets/js/data.js\`." + if [ "$status" = "1" ]; then + echo "The Telegram Bot API spec differs from \`src/assets/js/data.js\`." + else + echo "The Bot API spec source may be stale; the check could not confirm that the project is up to date." + fi echo cat report.md echo - echo "To update: edit \`src/assets/js/data.js\` (lists and \`BOT_API_VERSION\`), add labels to all \`src/i18n/*.json\`, add new method parameters to \`METHOD_PARAMS\` in \`scripts/check-bot-api.mjs\`, then run \`npm test\` and \`node scripts/check-bot-api.mjs\`." + echo "If this is a real API change: edit \`src/assets/js/data.js\` (lists and \`BOT_API_VERSION\`), add labels to all \`src/i18n/*.json\`, add new method parameters to \`METHOD_PARAMS\` in \`scripts/check-bot-api.mjs\`, then run \`npm test\` and \`node scripts/check-bot-api.mjs\`." + echo + echo "If the spec source looks stale, verify https://core.telegram.org/bots/api before changing the project." } > body.md + if [ "$stale" = "true" ] && [ "$status" != "1" ]; then + title="Bot API spec source may be stale" + else + title="Update to Telegram Bot API $version" + fi existing=$(gh issue list --label bot-api-update --state open --json number --jq '.[0].number') if [ -n "$existing" ]; then - gh issue edit "$existing" --title "Update to Telegram Bot API $version" --body-file body.md + gh issue edit "$existing" --title "$title" --body-file body.md else - gh issue create --title "Update to Telegram Bot API $version" --label bot-api-update --body-file body.md + gh issue create --title "$title" --label bot-api-update --body-file body.md fi diff --git a/CHANGELOG.md b/CHANGELOG.md index 97f638d..15de3c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 3.4.0 — 2026-11-21 + +### Changed +- Tab editors are imported only when a tab is opened; the landing page no longer downloads the whole editor module graph. +- The Bot API drift check also covers `InputProfilePhoto` subtypes. +- The weekly Bot API watch opens or updates an issue when the spec source looks stale, not only when fields differ. + ## 3.3.1 — 2026-11-21 ### Fixed diff --git a/CLAUDE.md b/CLAUDE.md index 2605912..a3aeacb 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -10,7 +10,7 @@ Static site (GitHub Pages) that calls the Telegram Bot API from the browser. No ## Updating to a new Bot API version -1. `node scripts/check-bot-api.mjs` — lists new update types, admin rights, getMe flags, command scopes, BotCommand/MenuButton/WebhookInfo fields, parameters of every method the tool calls, and bot-settings methods (spec: PaulSonOfLars/telegram-bot-api-spec; core.telegram.org may be unreachable). It also warns when the spec release date is stale, so an outdated spec source is not mistaken for “no changes”. +1. `node scripts/check-bot-api.mjs` — lists new update types, admin rights, getMe flags, command scopes, BotCommand/MenuButton/InputProfilePhoto/WebhookInfo fields, parameters of every method the tool calls, and bot-settings methods (spec: PaulSonOfLars/telegram-bot-api-spec; core.telegram.org may be unreachable). It also warns when the spec release date is stale, and the weekly watch opens an issue for a stale source, so an outdated spec is not mistaken for “no changes”. 2. Update `src/assets/js/data.js`: `UPDATE_GROUPS` (mark `optIn` if the spec says it must be requested explicitly), `ADMIN_RIGHTS` (with `target`), `ME_FLAGS`, `COMMAND_SCOPES`, `BOT_API_VERSION`. If a new parameter appears on a method the tool already calls, add it to `METHOD_PARAMS` in `scripts/check-bot-api.mjs` and expose it in the UI when it matters. 3. Add labels for every new key to all five locale files (`app.updates.*`, `app.rights.*`, `app.me.*`, `app.scopes.*`). `npm test` lists anything missing. 4. A new bot-settings method that needs its own UI (a new tab or form) is a design change: describe it in the PR instead of building it silently. diff --git a/README.md b/README.md index b32dd9e..f153738 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ npm run build && node scripts/screenshots.mjs # e2e smoke test (Playwright + C ## Automation - **CI** (`.github/workflows/ci.yml`, on pull requests): unit tests, build, end-to-end test in Chromium against a mocked Bot API, and a Lighthouse audit (accessibility ≥ 95, best practices ≥ 90 and SEO ≥ 95 are errors; performance ≥ 85 is a warning; reports are attached to the run). -- **Bot API watch** (`.github/workflows/bot-api-watch.yml`, weekly): compares the latest Bot API spec with `src/assets/js/data.js` via `scripts/check-bot-api.mjs` — update types, admin rights, `getMe` flags, scopes, `BotCommand`/`MenuButton`/`WebhookInfo` fields and the parameters of every method the tool calls — and opens an issue labelled `bot-api-update` when something is missing. A stale spec source is reported as a warning. +- **Bot API watch** (`.github/workflows/bot-api-watch.yml`, weekly): compares the latest Bot API spec with `src/assets/js/data.js` via `scripts/check-bot-api.mjs` — update types, admin rights, `getMe` flags, scopes, `BotCommand`/`MenuButton`/`InputProfilePhoto`/`WebhookInfo` fields and the parameters of every method the tool calls — and opens an issue labelled `bot-api-update` when something is missing or the spec source looks stale. - **Agent instructions** for updating the project are in [`CLAUDE.md`](CLAUDE.md). ## FAQ diff --git a/package.json b/package.json index 0523704..ff6ca70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "telegram-bot-manager", - "version": "3.3.1", + "version": "3.4.0", "private": true, "description": "Free online Telegram Bot Manager: set, check and delete webhooks, edit commands, profile, menu button and admin rights right in your browser.", "type": "module", diff --git a/scripts/check-bot-api.mjs b/scripts/check-bot-api.mjs index 066f7b0..4bd9efa 100644 --- a/scripts/check-bot-api.mjs +++ b/scripts/check-bot-api.mjs @@ -49,6 +49,7 @@ export const WEBHOOK_INFO_FIELDS = [ ]; export const BOT_COMMAND_FIELDS = ['command', 'description', 'is_ephemeral']; export const MENU_BUTTON_TYPES = ['MenuButtonCommands', 'MenuButtonWebApp', 'MenuButtonDefault']; +export const INPUT_PROFILE_PHOTO_TYPES = ['InputProfilePhotoStatic', 'InputProfilePhotoAnimated']; // A stale spec source is a silent-drift risk: it can look "up to date" while Telegram has // already shipped a newer API. The report warns when the spec release date is older than this. @@ -123,6 +124,7 @@ export async function checkBotApi(spec, { now = new Date(), maxSpecAgeDays = MAX ), botCommandFields: diff(fields('BotCommand'), BOT_COMMAND_FIELDS), menuButtonTypes: diff(spec.types.MenuButton?.subtypes ?? [], MENU_BUTTON_TYPES), + profilePhotoTypes: diff(spec.types.InputProfilePhoto?.subtypes ?? [], INPUT_PROFILE_PHOTO_TYPES), webhookInfoFields: diff(fields('WebhookInfo'), WEBHOOK_INFO_FIELDS), methodParams, uncheckedMethods: { added: uncheckedMethods, removed: [] }, @@ -133,7 +135,7 @@ export async function checkBotApi(spec, { now = new Date(), maxSpecAgeDays = MAX }; const sections = [ report.updateTypes, report.adminRights, report.meFlags, report.commandScopes, - report.botCommandFields, report.menuButtonTypes, report.webhookInfoFields, + report.botCommandFields, report.menuButtonTypes, report.profilePhotoTypes, report.webhookInfoFields, report.methodParams, report.uncheckedMethods, report.botSettingsMethods, ]; report.upToDate = report.specVersion === report.ourVersion @@ -154,6 +156,7 @@ export function toMarkdown(r) { commandScopes: 'BotCommandScope types', botCommandFields: 'BotCommand fields', menuButtonTypes: 'MenuButton types', + profilePhotoTypes: 'InputProfilePhoto types', webhookInfoFields: 'WebhookInfo fields', methodParams: 'Method parameters', uncheckedMethods: 'Used methods without a parameter check', diff --git a/scripts/screenshots.mjs b/scripts/screenshots.mjs index 3dbe1c9..f5c5d6c 100644 --- a/scripts/screenshots.mjs +++ b/scripts/screenshots.mjs @@ -119,6 +119,8 @@ async function openApp({ theme = 'dark', lang = '', width = 1280, height = 900, viewport: { width, height }, colorScheme: theme, deviceScaleFactor: 1, ...(locale ? { locale } : {}), }); const page = await context.newPage(); + const requests = []; + page.on('request', (request) => requests.push(request.url())); page.on('pageerror', (e) => errors.push(`pageerror: ${e.message}`)); page.on('console', (m) => { // Failed mocked requests (e.g. the deliberate 429) are logged by the browser; they are expected. @@ -138,7 +140,7 @@ async function openApp({ theme = 'dark', lang = '', width = 1280, height = 900, return route.fulfill({ status: json.ok ? 200 : json.error_code, contentType: 'application/json', body: JSON.stringify(json), headers: { 'access-control-allow-origin': '*' } }); }); await page.goto(`${base}${lang}`); - return { page, mock, context }; + return { page, mock, context, requests }; } async function shot(page, name, options = {}) { @@ -161,9 +163,10 @@ async function connect(page) { try { // Landing page { - const { page, context } = await openApp({ theme: 'light' }); + const { page, context, requests } = await openApp({ theme: 'light' }); assert(await page.title() !== '', 'title'); assert((await page.locator('link[rel="alternate"][hreflang]').count()) === 6, 'hreflang links'); + assert(!requests.some((url) => url.includes('/assets/js/tabs/')), 'tab modules load lazily'); await page.fill('#token', 'bad'); await page.click('#connect-form button[type="submit"]'); assert(await page.locator('.field-error').isVisible(), 'token validation'); diff --git a/src/assets/js/main.js b/src/assets/js/main.js index e7c6707..2abb1a8 100644 --- a/src/assets/js/main.js +++ b/src/assets/js/main.js @@ -4,14 +4,16 @@ import { DEFAULT_API_BASE, LANGUAGE_CODES, ME_FLAGS } from './data.js'; import { validateToken, validateApiBase, normalizeApiBase } from './validators.js'; import * as storage from './storage.js'; import { $, $$, el, describeError, withBusy, copyText, bindCounters, badge, showError, applyValidation } from './ui.js'; -import webhookTab from './tabs/webhook.js'; -import profileTab from './tabs/profile.js'; -import commandsTab from './tabs/commands.js'; -import menuTab from './tabs/menu.js'; -import rightsTab from './tabs/rights.js'; -import devTab from './tabs/dev.js'; - -const TABS = [webhookTab, profileTab, commandsTab, menuTab, rightsTab, devTab]; +// Tab controllers are imported on first activation: the landing page only needs the +// connection form, so the editor code is not part of its initial module graph. +const TABS = [ + { id: 'webhook', loader: () => import('./tabs/webhook.js') }, + { id: 'profile', loader: () => import('./tabs/profile.js') }, + { id: 'commands', loader: () => import('./tabs/commands.js') }, + { id: 'menu', loader: () => import('./tabs/menu.js') }, + { id: 'rights', loader: () => import('./tabs/rights.js') }, + { id: 'dev', loader: () => import('./tabs/dev.js'), alwaysReload: true }, +]; const LOG_LIMIT = 100; const LANGUAGE_SUGGESTIONS = [ { code: 'ru', prefix: 'ru/', name: 'Русский' }, @@ -40,6 +42,8 @@ const app = { }; const loadedTabs = new Set(); +const tabControllers = new Map(); +const tabLoads = new Map(); let avatarUrl = null; let activeTab = null; @@ -210,6 +214,19 @@ function activateTab(id, { focus = false } = {}) { loadTab(id); } +async function ensureTab(tab) { + if (tabControllers.has(tab.id)) return tabControllers.get(tab.id); + if (!tabLoads.has(tab.id)) { + tabLoads.set(tab.id, tab.loader().then((module) => { + const controller = module.default; + controller.init(app); + tabControllers.set(tab.id, controller); + return controller; + }).finally(() => tabLoads.delete(tab.id))); + } + return tabLoads.get(tab.id); +} + async function loadTab(id, force = false) { const tab = TABS.find((x) => x.id === id); if (!app.api || (loadedTabs.has(id) && !force && !tab.alwaysReload)) return; @@ -217,7 +234,8 @@ async function loadTab(id, force = false) { const panel = $(`#panel-${id}`); panel.classList.add('is-loading'); try { - await tab.load(app); + const controller = await ensureTab(tab); + await controller.load(app); } catch (error) { loadedTabs.delete(id); showError(error); @@ -242,7 +260,7 @@ function initTabs() { const id = tabFromHash(); if (id && app.api && id !== activeTab) activateTab(id); }); - for (const tab of TABS) tab.init(app); + // Controllers are imported and initialised on the first tab activation. } // ---------- Misc UI ---------- diff --git a/tests/check-bot-api.test.mjs b/tests/check-bot-api.test.mjs index 3fcdb68..f43721f 100644 --- a/tests/check-bot-api.test.mjs +++ b/tests/check-bot-api.test.mjs @@ -3,6 +3,7 @@ import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; import { checkBotApi, toMarkdown, usedMethods, METHOD_PARAMS, WEBHOOK_INFO_FIELDS, BOT_COMMAND_FIELDS, MENU_BUTTON_TYPES, + INPUT_PROFILE_PHOTO_TYPES, } from '../scripts/check-bot-api.mjs'; import { loadLocales, LANGS } from '../scripts/build.mjs'; import * as data from '../src/assets/js/data.js'; @@ -20,6 +21,7 @@ function specFromProject() { BotCommandScope: { subtypes: scopeTypes }, BotCommand: { fields: BOT_COMMAND_FIELDS.map((n) => field(n)) }, MenuButton: { subtypes: [...MENU_BUTTON_TYPES] }, + InputProfilePhoto: { subtypes: [...INPUT_PROFILE_PHOTO_TYPES] }, WebhookInfo: { fields: WEBHOOK_INFO_FIELDS.map((n) => field(n)) }, }; data.COMMAND_SCOPES.forEach((s, i) => { @@ -60,6 +62,7 @@ test('detects new method parameters and object fields', async () => { spec.types.WebhookInfo.fields.push(field('new_info_field')); spec.types.BotCommand.fields.push(field('new_command_field')); spec.types.MenuButton.subtypes.push('MenuButtonNew'); + spec.types.InputProfilePhoto.subtypes.push('InputProfilePhotoNew'); const report = await checkBotApi(spec, { now: NOW }); assert.equal(report.upToDate, false); assert.deepEqual(report.methodParams.added, ['setMyCommands.new_parameter']); @@ -67,6 +70,7 @@ test('detects new method parameters and object fields', async () => { assert.deepEqual(report.webhookInfoFields.added, ['new_info_field']); assert.deepEqual(report.botCommandFields.added, ['new_command_field']); assert.deepEqual(report.menuButtonTypes.added, ['MenuButtonNew']); + assert.deepEqual(report.profilePhotoTypes.added, ['InputProfilePhotoNew']); const md = toMarkdown(report); assert.ok(md.includes('`setMyCommands.new_parameter`') && md.includes('### WebhookInfo fields')); });