feat(portal): channel-agnostic channels portal (WeChat + Telegram)#55
Merged
Conversation
…egram) The portal opened straight into a WeChat-only editor with no entry point for other channels. It now lists every configured channel in an overview and opens a type-appropriate editor for each. - portal.py: public_config emits both wechat + telegram instances (each tagged with a type); save() splits posted instances by type; new telegram_status() getMe probe (token stays server-side, never logged); require_approval now serialized for both types (previously silently dropped on WeChat save). - portal_html.py: channel overview list + per-type editors (WeChat keeps contacts/groups/QR; Telegram gets token status, id-list allowlists, dedup); shared behavior/safety cards; save() payload now carries type/api_base/require_approval. - Fixed a save bug found via Playwright: the client dropped the type field, mis-serializing a Telegram instance as a wechat block. Added a static guard + backend round-trip tests. - Hoisted the contact-search dropdown listener so it registers once instead of per render. 34 portal tests (full suite 481 pass/1 skip); Playwright-verified both editors + save round-trip.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
The
coding-bridge channels portalopened straight into a WeChat-only editor ("Channels · WeChat") — it proxied WeChat gateway endpoints and had no entry point for any other channel. With Telegram now a first-class channel (#54), the portal needs to be channel-agnostic.This redesigns the portal into a channel overview that lists every configured instance (WeChat + Telegram) with a type badge and enabled state, and opens a type-appropriate editor when you click one.
Changes
Backend (
portal.py)public_config()now emits both WeChat and Telegram instances, each tagged with atype("wechat"/"telegram"). New_telegram_instance_public().save()splits posted instances bytypeinto[[channels.wechat]]/[[channels.telegram]]blocks and round-trips through the real loader (unknown type → 400).dump_channels_toml()+ new_dump_telegram_instance()serialize Telegram blocks;require_approvalis now serialized for both types (it was silently dropped on WeChat portal saves before).telegram_status()— agetMeprobe (sync httpx). The bot token lives only in the request URL path and is never logged or surfaced; errors reduce to the exception class name only.GET /api/telegram/status;_telegram_instance()lookup.Frontend (
portal_html.py)微/✈icon + type badge + enabled dot), click to select.render()branches onit.type→renderWeChatEditor(unchanged: account/contacts search/groups/QR) vs newrenderTelegramEditor(token status viagetMe, numeric-id allowlists as textareas, dedup field, provider, rate limit).behaviorCard/safetyCard(the Safety card exposesrequire_approvalfor both types now).save()payload carriestype+api_base(Telegram) /base_url(WeChat) +require_approval.Tests
test_channels_portal.py(type inpublic_config, save round-trips both types,require_approvalpreserved for both, unknown-type rejected,telegram_statusok/401-no-leak/404, live/api/telegram/statusroute, TOML round-trip) + a static guard asserting the clientsave()carriestype.Testing
ruff checkclean. Portal suite 34 passed; full suite 481 passed, 1 skipped (3 pre-existing Windows-only failures unrelated to this change).require_approvalreflecting config); editing + enabling + Save rewrotechannels.tomlwith both blocks intact (WeChat preserved, Telegramenabled/require_approval/allowlists persisted).🤖 对抗评审
Reviewer: Claude
general-purposesubagent (Codex unavailable on this host), read-only, one round. It returned VERDICT: ISSUES FOUND with 2RISKs:documentclick listener accumulates (portal_html.py). Real (a latent issue amplified by the new per-select re-render). FIXED: hoisted the contact-search dropdown-close listener to a single global registration at bootstrap; removed the per-renderaddEventListener. Verified with Playwright — after 6 channel switches the dropdown still closes on an outside click (results show→results), with one listener.save()defaults a missingtypeto"wechat"(portal.py). REBUTTED (won't fix): this is deliberate backward-compatibility. The legacy WeChat-only payload (and 6 existing tests) post instances with notype; defaulting towechatkeeps them working. Telegram is brand-new so no type-less Telegram payload can exist; the client always sendstype(enforced by a static guard test); and unknown non-empty types are already rejected with 400. Forcingtyperequired would break the documented backward-compatible payload for no real-world safety gain.A separate save bug was found during Playwright testing and fixed before review: the client
save()mapper dropped thetypefield (and sentbase_urlfor Telegram), so a Telegram instance was mis-serialized as a[[channels.wechat]]block →base_url missing400. The mapper now sendstype/api_base/require_approval; a backend round-trip test + a static HTML guard prevent regression.