From 29978c221ee3ae641ce0b9b97851656c00714a5d Mon Sep 17 00:00:00 2001 From: gdz66601 Date: Tue, 15 Sep 2026 22:34:50 +0800 Subject: [PATCH 1/2] feat: support private groups in Telegram bridge --- CHANGELOG.md | 6 ++ README.en.md | 4 +- README.ja.md | 4 +- README.md | 4 +- frontend/src/demo/api.js | 10 ++- frontend/src/demo/fixtures.js | 1 + frontend/src/demo/realtime.js | 3 +- frontend/src/locales/en-US.js | 6 +- frontend/src/locales/server-errors/en-US.js | 4 +- frontend/src/locales/server-errors/zh-TW.js | 4 +- frontend/src/locales/zh-CN.js | 6 +- frontend/src/locales/zh-TW.js | 6 +- frontend/src/pages/AdminTelegramPage.vue | 9 ++- package-lock.json | 4 +- package.json | 2 +- shared/group-channel.ts | 7 ++ test/admin-ui.test.js | 4 +- test/demo-runtime.test.js | 34 ++++++++ test/telegram-bridge.test.js | 55 +++++++++++++ test/telegram-mappings.test.js | 90 +++++++++++++++++++++ worker/src/api/telegram.js | 4 +- worker/src/data/telegram.js | 20 +++-- worker/src/do/ChannelRoom.js | 3 +- worker/src/integrations/telegram/bridge.js | 5 +- 24 files changed, 252 insertions(+), 43 deletions(-) create mode 100644 shared/group-channel.ts create mode 100644 test/telegram-mappings.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index fdaa3ec1..165191a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ EdgeChat 从 `2.1.2` 起正式采用语义化版本。更早的版本号依据已经完成的主要里程碑补记,用于说明项目演进,不对应历史 Git 标签。 +## 2.7.0 - 2026-09-15 + +- Telegram 桥接由仅支持公开群组扩展为支持公开与私有群组,管理员可在同一后台列表中查看群名、区分群类型并统一配置映射。 +- 私有群的 Telegram 入站、出站、附件、回复、实时广播与未读投影复用现有群聊链路;一对一私信继续保持不可映射。 +- 同步更新生产与 demo 契约、三语言界面和部署文档;不新增数据库迁移、云资源或 Android 原生改动。 + ## 2.6.2 - 2026-09-15 - 新增繁体中文界面,右上角语言入口改为简体中文、繁体中文与 English 三项菜单,并按当前语言异步加载独立语言包。 diff --git a/README.en.md b/README.en.md index 5b3119a8..c0c73c47 100644 --- a/README.en.md +++ b/README.en.md @@ -90,7 +90,7 @@ The project itself is free and open source. Cloud service costs depend on your C **You do not have to move everyone into the same application.** -Administrators can bind EdgeChat groups to Telegram groups and relay messages in both directions through a Telegram Bot: messages sent on the web can be synchronized to Telegram, and messages in the Telegram group return to EdgeChat. +Administrators can view both public and private EdgeChat groups in the admin console and bind any group to a Telegram group. A Telegram Bot relays messages in both directions: messages sent on the web can be synchronized to Telegram, and messages in the Telegram group return to EdgeChat. One-to-one direct messages are never bridged. This suits teams and communities that already have Telegram groups but also need an independent web chat entry point. @@ -129,7 +129,7 @@ This suits teams and communities that already have Telegram groups but also need ### 🔌 Connections and Extensions -- Two-way Telegram group message bridging, including voice message synchronization. +- Administrator-configured two-way Telegram bridging for public and private groups, including voice message synchronization. - WebMCP site tools: in compatible client environments, provides login, conversation queries, message reading, sending, and related capabilities. ## Privacy and Encryption diff --git a/README.ja.md b/README.ja.md index e8eb789c..5038c24d 100644 --- a/README.ja.md +++ b/README.ja.md @@ -90,7 +90,7 @@ EdgeChat は、**自分のチャットスペースを持ちたいが、そのた **全員を同じアプリに移行させる必要はありません。** -管理者は EdgeChat のグループと Telegram のグループを紐付け、Telegram Bot を介してメッセージを双方向に転送できます。Web 上で送信したメッセージは Telegram に同期され、Telegram グループのメッセージも EdgeChat に戻ってきます。 +管理者は管理画面で EdgeChat の公開・非公開グループを確認し、任意のグループを Telegram グループに紐付けられます。Telegram Bot を介してメッセージが双方向に転送され、Web 上で送信したメッセージは Telegram に同期され、Telegram グループのメッセージも EdgeChat に戻ってきます。一対一のダイレクトメッセージはブリッジされません。 Telegram グループがすでにあり、同時に独立した Web チャット入口も必要とするチームやコミュニティに適しています。 @@ -129,7 +129,7 @@ Telegram グループがすでにあり、同時に独立した Web チャット ### 🔌 接続と拡張 -- Telegram グループとの双方向メッセージブリッジ。音声メッセージの同期にも対応。 +- 管理者が設定する公開・非公開グループと Telegram の双方向メッセージブリッジ。音声メッセージの同期にも対応。 - WebMCP サイトツール:対応クライアント環境で、ログイン、会話の検索、メッセージの読み取り・送信などを提供。 ## プライバシーと暗号化 diff --git a/README.md b/README.md index 130e3ed5..5f1c4b7c 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ EdgeChat 面向这样一种需求:**想拥有一个自己的聊天空间,又 **不用把所有人都搬进同一个应用。** -管理员可以将 EdgeChat 群组与 Telegram 群组绑定,通过 Telegram Bot 双向转发消息:在网页里发出的消息可以同步到 Telegram,Telegram 群里的消息也会回到 EdgeChat。 +管理员可以在后台查看 EdgeChat 的公开与私有群组,并将任一群组与 Telegram 群组绑定。Telegram Bot 会双向转发消息:在网页里发出的消息可以同步到 Telegram,Telegram 群里的消息也会回到 EdgeChat;一对一私信不会进入桥接。 适合已经有 Telegram 群、同时又需要一个独立网页聊天入口的团队和社区。 @@ -129,7 +129,7 @@ EdgeChat 面向这样一种需求:**想拥有一个自己的聊天空间,又 ### 🔌 连接与扩展 -- Telegram 群组双向消息桥接,支持语音消息同步。 +- 公开与私有群组均可由管理员配置 Telegram 双向消息桥接,并支持语音消息同步。 - WebMCP 站点工具:在兼容的客户端环境中,提供登录、查询会话、读取与发送消息等能力。 ## 隐私与加密 diff --git a/frontend/src/demo/api.js b/frontend/src/demo/api.js index d1f532aa..811952a8 100644 --- a/frontend/src/demo/api.js +++ b/frontend/src/demo/api.js @@ -13,6 +13,7 @@ import { } from './state.js'; import { demoMaintenanceReport } from './maintenance.ts'; +import { isGroupChannelKind } from '../../../shared/group-channel.ts'; import { parseLocalUserId, validateBio } from '../../../shared/user-profile.ts'; const DEMO_DELAY_MS = 90; @@ -75,8 +76,8 @@ function telegramPayload() { return cloneDemo({ config: demoState.telegram.config, channels: demoState.channels - .filter((channel) => channel.kind === 'public') - .map(({ id, name }) => ({ id, name })), + .filter((channel) => isGroupChannelKind(channel.kind)) + .map(({ id, name, kind }) => ({ id, name, kind })), mappings: demoState.telegram.mappings }); } @@ -498,11 +499,14 @@ export async function requestDemo(path, options = {}) { } if (method === 'POST' && pathname === '/admin/telegram/mappings') { const channel = findDemoChannel(body.channelId); - if (!channel) fail('请选择公开群组'); + if (!channel || !isGroupChannelKind(channel.kind) || !/^-\d+$/.test(String(body.telegramChatId || ''))) { + fail('请选择群组并填写有效的 Telegram 群 ID'); + } demoState.telegram.mappings.push({ id: demoState.nextMappingId++, channelId: channel.id, channelName: channel.name, + channelKind: channel.kind, telegramChatTitle: 'Telegram 演示群', telegramChatId: String(body.telegramChatId || ''), enabled: true diff --git a/frontend/src/demo/fixtures.js b/frontend/src/demo/fixtures.js index 8bf72542..206b8965 100644 --- a/frontend/src/demo/fixtures.js +++ b/frontend/src/demo/fixtures.js @@ -420,6 +420,7 @@ export function createDemoFixtures() { id: 1, channelId: 3, channelName: 'Telegram 联动', + channelKind: 'public', telegramChatTitle: 'EdgeChat 演示群', telegramChatId: '-1002345678901', enabled: true diff --git a/frontend/src/demo/realtime.js b/frontend/src/demo/realtime.js index 63856386..dbbde160 100644 --- a/frontend/src/demo/realtime.js +++ b/frontend/src/demo/realtime.js @@ -5,6 +5,7 @@ import { getDemoDirectMessageBlockStatus, roomKey } from './state.js'; +import { isGroupChannelKind } from '../../../shared/group-channel.ts'; const roomSockets = new Map(); const inboxSockets = new Set(); @@ -73,7 +74,7 @@ function telegramSender() { } function hasEnabledTelegramMapping(kind, roomId) { - return kind === 'public' && demoState.telegram.mappings.some( + return isGroupChannelKind(kind) && demoState.telegram.mappings.some( (mapping) => Number(mapping.channelId) === Number(roomId) && mapping.enabled ); } diff --git a/frontend/src/locales/en-US.js b/frontend/src/locales/en-US.js index 91995b34..766e0bcf 100644 --- a/frontend/src/locales/en-US.js +++ b/frontend/src/locales/en-US.js @@ -282,7 +282,7 @@ export default { 'admin.nav.createUser': 'Create user', 'admin.nav.registrationLinks': 'Registration links', 'admin.nav.telegram': 'Telegram integration', - 'admin.nav.telegramDescription': 'Manage the bot and public group mappings', + 'admin.nav.telegramDescription': 'Manage the bot and group mappings', 'admin.nav.site': 'Site settings', 'admin.nav.siteDescription': 'Manage site appearance and version status', 'admin.nav.siteAppearance': 'Site appearance', @@ -395,7 +395,7 @@ export default { 'invites.copy': 'Copy', 'invites.revoke': 'Disable link', 'telegram.title': 'Telegram integration', - 'telegram.description': 'Connect a Telegram bot and link public groups to Telegram chats.', + 'telegram.description': 'Connect a Telegram bot and link public or private groups to Telegram chats.', 'telegram.botConnected': 'Bot connected. Webhook updated.', 'telegram.mappingSaved': 'Group mapping saved.', 'telegram.confirmDeleteMapping': 'Delete the Telegram mapping for {name}?', @@ -410,7 +410,7 @@ export default { 'telegram.connectBot': 'Connect bot', 'telegram.groupMappings': 'Group mappings', 'telegram.mappingCount': '{count} Telegram groups linked', - 'telegram.edgechatPublicGroup': 'EdgeChat public group', + 'telegram.edgechatGroup': 'EdgeChat group', 'telegram.selectGroup': 'Select group', 'telegram.chatId': 'Telegram group ID', 'telegram.saveMapping': 'Save mapping', diff --git a/frontend/src/locales/server-errors/en-US.js b/frontend/src/locales/server-errors/en-US.js index aae43296..d675a440 100644 --- a/frontend/src/locales/server-errors/en-US.js +++ b/frontend/src/locales/server-errors/en-US.js @@ -65,7 +65,7 @@ const fixedErrorTranslations = new Map([ ['Webhook 验证失败', 'Webhook verification failed'], ['Telegram Bot Token 不能为空', 'Telegram Bot Token cannot be empty'], ['Telegram 配置保存失败', 'Failed to save Telegram configuration'], - ['请选择公开群组并填写有效的 Telegram 群 ID', 'Select a public group and enter a valid Telegram group ID'], + ['请选择群组并填写有效的 Telegram 群 ID', 'Select a group and enter a valid Telegram group ID'], ['请先连接 Telegram Bot', 'Connect the Telegram Bot first'], ['目标必须是 Telegram 群组或超级群组', 'The target must be a Telegram group or supergroup'], ['这个 EdgeChat 群组或 Telegram 群已经绑定', 'This EdgeChat group or Telegram group is already linked'], @@ -79,7 +79,7 @@ const fixedErrorTranslations = new Map([ ['请输入群组名称', 'Please enter a group name'], ['请输入新密码', 'Please enter a new password'], ['请输入 Bot Token', 'Please enter a Bot token'], - ['请选择公开群组', 'Please select a public group'] + ['请选择群组', 'Please select a group'] ]); const dynamicErrorTranslations = [ diff --git a/frontend/src/locales/server-errors/zh-TW.js b/frontend/src/locales/server-errors/zh-TW.js index b4b9e3d7..9d2d024a 100644 --- a/frontend/src/locales/server-errors/zh-TW.js +++ b/frontend/src/locales/server-errors/zh-TW.js @@ -65,7 +65,7 @@ const fixedErrorTranslations = new Map([ ["Webhook 验证失败", "Webhook 驗證失敗"], ["Telegram Bot Token 不能为空", "Telegram Bot Token 不能為空"], ["Telegram 配置保存失败", "Telegram 配置保存失敗"], - ["请选择公开群组并填写有效的 Telegram 群 ID", "請選擇公開群組並填寫有效的 Telegram 群 ID"], + ["请选择群组并填写有效的 Telegram 群 ID", "請選擇群組並填寫有效的 Telegram 群 ID"], ["请先连接 Telegram Bot", "請先連接 Telegram Bot"], ["目标必须是 Telegram 群组或超级群组", "目標必須是 Telegram 群組或超級群組"], ["这个 EdgeChat 群组或 Telegram 群已经绑定", "這個 EdgeChat 群組或 Telegram 群已經綁定"], @@ -79,7 +79,7 @@ const fixedErrorTranslations = new Map([ ["请输入群组名称", "請輸入群組名稱"], ["请输入新密码", "請輸入新密碼"], ["请输入 Bot Token", "請輸入 Bot Token"], - ["请选择公开群组", "請選擇公開群組"] + ["请选择群组", "請選擇群組"] ]); const dynamicErrorTranslations = [ diff --git a/frontend/src/locales/zh-CN.js b/frontend/src/locales/zh-CN.js index 9e86a7dd..f016e5f0 100644 --- a/frontend/src/locales/zh-CN.js +++ b/frontend/src/locales/zh-CN.js @@ -282,7 +282,7 @@ export default { 'admin.nav.createUser': '创建用户', 'admin.nav.registrationLinks': '注册链接', 'admin.nav.telegram': 'Telegram 互通', - 'admin.nav.telegramDescription': '管理 Bot 与公开群组映射', + 'admin.nav.telegramDescription': '管理 Bot 与群组映射', 'admin.nav.site': '网站设置', 'admin.nav.siteDescription': '维护站点外观与版本状态', 'admin.nav.siteAppearance': '站点外观', @@ -395,7 +395,7 @@ export default { 'invites.copy': '复制', 'invites.revoke': '停用链接', 'telegram.title': 'Telegram 互通', - 'telegram.description': '连接一个 Telegram Bot,并将公开群组绑定到 Telegram 群聊。', + 'telegram.description': '连接一个 Telegram Bot,并将公开或私有群组绑定到 Telegram 群聊。', 'telegram.botConnected': 'Bot 已连接,Webhook 已更新。', 'telegram.mappingSaved': '群组映射已保存。', 'telegram.confirmDeleteMapping': '确认删除 {name} 的 Telegram 映射吗?', @@ -410,7 +410,7 @@ export default { 'telegram.connectBot': '连接 Bot', 'telegram.groupMappings': '群组映射', 'telegram.mappingCount': '{count} 个 Telegram 群已绑定', - 'telegram.edgechatPublicGroup': 'EdgeChat 公开群组', + 'telegram.edgechatGroup': 'EdgeChat 群组', 'telegram.selectGroup': '选择群组', 'telegram.chatId': 'Telegram 群 ID', 'telegram.saveMapping': '保存映射', diff --git a/frontend/src/locales/zh-TW.js b/frontend/src/locales/zh-TW.js index 1773b50b..bef08610 100644 --- a/frontend/src/locales/zh-TW.js +++ b/frontend/src/locales/zh-TW.js @@ -349,7 +349,7 @@ export default { "admin.nav.createUser": "創建用戶", "admin.nav.registrationLinks": "註冊鏈接", "admin.nav.telegram": "Telegram 互通", - "admin.nav.telegramDescription": "管理 Bot 與公開群組映射", + "admin.nav.telegramDescription": "管理 Bot 與群組映射", "admin.nav.site": "網站設置", "admin.nav.siteDescription": "維護站點外觀與版本狀態", "admin.nav.siteAppearance": "站點外觀", @@ -462,7 +462,7 @@ export default { "invites.copy": "複製", "invites.revoke": "停用鏈接", "telegram.title": "Telegram 互通", - "telegram.description": "連接一個 Telegram Bot,並將公開群組綁定到 Telegram 群聊。", + "telegram.description": "連接一個 Telegram Bot,並將公開或私有群組綁定到 Telegram 群聊。", "telegram.botConnected": "Bot 已連接,Webhook 已更新。", "telegram.mappingSaved": "群組映射已保存。", "telegram.confirmDeleteMapping": "確認刪除 {name} 的 Telegram 映射嗎?", @@ -477,7 +477,7 @@ export default { "telegram.connectBot": "連接 Bot", "telegram.groupMappings": "群組映射", "telegram.mappingCount": "{count} 個 Telegram 群已綁定", - "telegram.edgechatPublicGroup": "EdgeChat 公開群組", + "telegram.edgechatGroup": "EdgeChat 群組", "telegram.selectGroup": "選擇群組", "telegram.chatId": "Telegram 群 ID", "telegram.saveMapping": "保存映射", diff --git a/frontend/src/pages/AdminTelegramPage.vue b/frontend/src/pages/AdminTelegramPage.vue index 99e78d0d..43096b14 100644 --- a/frontend/src/pages/AdminTelegramPage.vue +++ b/frontend/src/pages/AdminTelegramPage.vue @@ -138,11 +138,11 @@ onMounted(loadState);
@@ -165,7 +165,10 @@ onMounted(loadState); {{ t('telegram.loadingMappings') }} {{ t('telegram.emptyMappings') }} - {{ mapping.channelName }} + + {{ mapping.channelName }} +
{{ t(mapping.channelKind === 'private' ? 'chat.privateGroup' : 'chat.publicGroup') }}
+ {{ mapping.telegramChatTitle || t('telegram.unnamedChat') }}
{{ mapping.telegramChatId }}
diff --git a/package-lock.json b/package-lock.json index dc755d4c..a149c141 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "edgechat", - "version": "2.6.2", + "version": "2.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "edgechat", - "version": "2.6.2", + "version": "2.7.0", "dependencies": { "@capacitor/android": "^8.5.1", "@capacitor/core": "^8.5.1", diff --git a/package.json b/package.json index 422488e3..5ac52e95 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "edgechat", - "version": "2.6.2", + "version": "2.7.0", "private": true, "type": "module", "scripts": { diff --git a/shared/group-channel.ts b/shared/group-channel.ts new file mode 100644 index 00000000..38014909 --- /dev/null +++ b/shared/group-channel.ts @@ -0,0 +1,7 @@ +export const GROUP_CHANNEL_KINDS = ["public", "private"] as const; + +export type GroupChannelKind = (typeof GROUP_CHANNEL_KINDS)[number]; + +export function isGroupChannelKind(kind: unknown): kind is GroupChannelKind { + return kind === "public" || kind === "private"; +} diff --git a/test/admin-ui.test.js b/test/admin-ui.test.js index d5065555..0ad7e927 100644 --- a/test/admin-ui.test.js +++ b/test/admin-ui.test.js @@ -161,7 +161,7 @@ test('仪表盘复用现有概况接口并只展示可验证统计', () => { assert.match(dashboardSource, /t\('dashboard\.systemOverview'\)/); }); -test('Telegram 互通页由管理员路由保护并分别管理 Bot 与公开群组映射', () => { +test('Telegram 互通页由管理员路由保护并统一管理公开与私有群组映射', () => { assert.match(routerSource, /import AdminTelegramPage/); assert.match(routerSource, /path: 'telegram'/); assert.match(routerSource, /adminTitleKey: 'admin\.nav\.telegram'/); @@ -169,6 +169,8 @@ test('Telegram 互通页由管理员路由保护并分别管理 Bot 与公开群 assert.match(telegramSource, /api\.createAdminTelegramMapping/); assert.match(telegramSource, /type="checkbox"/); assert.match(telegramSource, /t\('telegram\.chatId'\)/); + assert.match(telegramSource, /t\('telegram\.edgechatGroup'\)/); + assert.match(telegramSource, /channel\.kind === 'private'/); }); test('仪表盘在中等桌面宽度提前重排且快捷入口文字保持完整', () => { diff --git a/test/demo-runtime.test.js b/test/demo-runtime.test.js index 32c61c1c..2b466a2f 100644 --- a/test/demo-runtime.test.js +++ b/test/demo-runtime.test.js @@ -35,6 +35,8 @@ test('demo backend exposes chat, contacts, admin, storage and Telegram fixture d assert.equal(storage.items.some((item) => item.ownerType === 'telegram'), true); assert.equal(telegram.config.configured, true); assert.equal(telegram.mappings[0].enabled, true); + assert.equal(telegram.channels.some((channel) => channel.kind === 'private'), true); + assert.equal(telegram.channels.every((channel) => channel.kind !== 'dm'), true); }); test('demo backend keeps group and admin mutations in browser memory', async () => { @@ -275,3 +277,35 @@ test('Telegram replies increment the inbox unread projection', async () => { roomSocket.close(); inboxSocket.close(); }); + +test('demo Telegram bridge accepts a private group mapping', async () => { + const state = await requestDemo('/admin/telegram/mappings', { + method: 'POST', + body: { channelId: 2, telegramChatId: '-1002345678902' } + }); + assert.equal(state.mappings.at(-1).channelKind, 'private'); + + const frames = []; + let roomSocket; + await new Promise((resolve) => { + roomSocket = connectDemoRoomSocket({ + kind: 'private', + roomId: 2, + onMessage(frame) { + frames.push(JSON.parse(frame)); + }, + onStatus(event) { + if (event.status === 'open') resolve(); + } + }); + }); + + roomSocket.send(JSON.stringify({ type: 'send', content: '私有群桥接测试' })); + await new Promise((resolve) => setTimeout(resolve, 720)); + + assert.equal( + frames.some((frame) => frame.message?.sender?.source === 'telegram'), + true + ); + roomSocket.close(); +}); diff --git a/test/telegram-bridge.test.js b/test/telegram-bridge.test.js index f4c088d0..e9536d5b 100644 --- a/test/telegram-bridge.test.js +++ b/test/telegram-bridge.test.js @@ -12,6 +12,7 @@ import { import { parseTelegramMessageUpdate } from "../worker/src/integrations/telegram/parser.js"; import { formatTelegramMessage, + ingestTelegramMessage, splitTelegramFormattedMessage, } from "../worker/src/integrations/telegram/bridge.js"; import { @@ -459,6 +460,60 @@ test("消息 projection 保留 Telegram 来源而不伪造 EdgeChat 账号", () ); }); +test("Telegram 私有群入站使用映射中的真实房间类型", async () => { + let roomName = ""; + let submittedPayload = null; + const env = { + DB: { + prepare() { + return { + bind() { + return this; + }, + async all() { + return { results: [] }; + }, + }; + }, + }, + CHANNEL_ROOM: { + idFromName(name) { + roomName = name; + return name; + }, + get() { + return { + async fetch(_url, init) { + submittedPayload = JSON.parse(init.body); + return Response.json({ ok: true, created: true, message: {} }); + }, + }; + }, + }, + }; + + await ingestTelegramMessage(env, { + mapping: { channelId: 9, channelName: "Private bridge", channelKind: "private" }, + telegramMessage: { + sourceMessageId: "-100900:1", + replySourceMessageId: null, + telegramChatId: "-100900", + telegramMessageId: 1, + content: "private inbound", + attachment: null, + sender: { id: "42", displayName: "Alice", avatarUrl: "" }, + }, + botToken: "", + }); + + assert.equal(roomName, "private:9"); + assert.deepEqual(submittedPayload.room, { + id: 9, + kind: "private", + name: "Private bridge", + }); +}); + test("Telegram webhook 公开接收而后台配置仍要求登录", async () => { const env = { DB: { diff --git a/test/telegram-mappings.test.js b/test/telegram-mappings.test.js new file mode 100644 index 00000000..0a9669e3 --- /dev/null +++ b/test/telegram-mappings.test.js @@ -0,0 +1,90 @@ +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import test from "node:test"; +import initSqlJs from "sql.js"; +import { isGroupChannelKind } from "../shared/group-channel.ts"; +import { + createTelegramMapping, + getTelegramMappingByChatId, + listEnabledTelegramMappingsForChannel, + listTelegramBridgeAdminState, +} from "../worker/src/data/telegram.js"; +import { createD1Adapter } from "./support/d1.js"; + +const SQL = await initSqlJs(); +const schema = readFileSync(new URL("../worker/schema.sql", import.meta.url), "utf8"); + +function createTelegramDatabase() { + const database = new SQL.Database(); + database.exec(schema); + database.run( + "INSERT INTO users (username, display_name, password_hash, password_salt, is_admin) VALUES (?, ?, ?, ?, 1)", + ["admin", "Admin", "hash", "salt"], + ); + database.run( + "INSERT INTO channels (name, kind, created_by) VALUES (?, 'private', 1), (?, 'dm', 1)", + ["Private bridge", "Direct message"], + ); + return createD1Adapter(database); +} + +test("Telegram 后台列出公开与私有群,但不把私信当作群聊", async () => { + const DB = createTelegramDatabase(); + const state = await listTelegramBridgeAdminState({ DB }); + + assert.deepEqual( + state.channels.map(({ name, kind }) => ({ name, kind })), + [ + { name: "general", kind: "public" }, + { name: "Private bridge", kind: "private" }, + ], + ); + assert.equal(isGroupChannelKind("public"), true); + assert.equal(isGroupChannelKind("private"), true); + assert.equal(isGroupChannelKind("dm"), false); +}); + +test("Telegram 私有群映射可供双向桥接查询,私信映射继续拒绝", async () => { + const DB = createTelegramDatabase(); + const mappingId = await createTelegramMapping(DB, { + channelId: 2, + telegramChatId: "-100200", + telegramChatTitle: "Private Telegram group", + createdBy: 1, + }); + + assert.equal(Number.isInteger(mappingId), true); + const inboundMapping = await getTelegramMappingByChatId(DB, "-100200"); + assert.deepEqual( + { + id: inboundMapping.id, + channelId: inboundMapping.channelId, + channelName: inboundMapping.channelName, + channelKind: inboundMapping.channelKind, + telegramChatId: inboundMapping.telegramChatId, + telegramChatTitle: inboundMapping.telegramChatTitle, + enabled: inboundMapping.enabled, + }, + { + id: mappingId, + channelId: 2, + channelName: "Private bridge", + channelKind: "private", + telegramChatId: "-100200", + telegramChatTitle: "Private Telegram group", + enabled: true, + }, + ); + const outboundMappings = await listEnabledTelegramMappingsForChannel(DB, 2); + assert.equal(outboundMappings.length, 1); + assert.equal(outboundMappings[0].channelKind, "private"); + assert.equal( + await createTelegramMapping(DB, { + channelId: 3, + telegramChatId: "-100300", + telegramChatTitle: "DM must stay local", + createdBy: 1, + }), + null, + ); +}); diff --git a/worker/src/api/telegram.js b/worker/src/api/telegram.js index 3c0968a0..26801c4d 100644 --- a/worker/src/api/telegram.js +++ b/worker/src/api/telegram.js @@ -159,7 +159,7 @@ export function registerTelegramAdminRoutes(app) { const channelId = Number(payload.channelId); const telegramChatId = String(payload.telegramChatId || "").trim(); if (!Number.isInteger(channelId) || channelId <= 0 || !/^-\d+$/.test(telegramChatId)) { - return errorResponse("请选择公开群组并填写有效的 Telegram 群 ID"); + return errorResponse("请选择群组并填写有效的 Telegram 群 ID"); } try { @@ -179,7 +179,7 @@ export function registerTelegramAdminRoutes(app) { createdBy: c.get("session").userId, }); if (!mappingId) { - return errorResponse("公开群组不存在", 404); + return errorResponse("群组不存在", 404); } return c.json(await listTelegramBridgeAdminState(c.env)); } catch (error) { diff --git a/worker/src/data/telegram.js b/worker/src/data/telegram.js index 37fc71c8..9791aef6 100644 --- a/worker/src/data/telegram.js +++ b/worker/src/data/telegram.js @@ -8,6 +8,7 @@ function mapMapping(row) { id: Number(row.id), channelId: Number(row.channel_id), channelName: row.channel_name || "", + channelKind: row.channel_kind || "", telegramChatId: String(row.telegram_chat_id), telegramChatTitle: row.telegram_chat_title || "", enabled: Boolean(Number(row.enabled)), @@ -25,17 +26,18 @@ export async function listTelegramBridgeAdminState(env) { LIMIT 1`, ).all(), env.DB.prepare( - `SELECT id, name + `SELECT id, name, kind FROM channels - WHERE kind = 'public' AND deleted_at IS NULL + WHERE kind IN ('public', 'private') AND deleted_at IS NULL ORDER BY CASE WHEN name = 'general' THEN 0 ELSE 1 END, name ASC`, ).all(), env.DB.prepare( - `SELECT tm.id, tm.channel_id, c.name AS channel_name, tm.telegram_chat_id, + `SELECT tm.id, tm.channel_id, c.name AS channel_name, c.kind AS channel_kind, + tm.telegram_chat_id, tm.telegram_chat_title, tm.enabled, tm.created_at, tm.updated_at FROM telegram_mappings tm JOIN channels c ON c.id = tm.channel_id - WHERE c.deleted_at IS NULL + WHERE c.kind IN ('public', 'private') AND c.deleted_at IS NULL ORDER BY tm.updated_at DESC, tm.id DESC`, ).all(), ]); @@ -51,6 +53,7 @@ export async function listTelegramBridgeAdminState(env) { channels: channelsResult.results.map((row) => ({ id: Number(row.id), name: row.name, + kind: row.kind, })), mappings: mappingsResult.results.map(mapMapping), }; @@ -123,7 +126,7 @@ export async function getTelegramMappingByChatId(db, telegramChatId) { JOIN channels c ON c.id = tm.channel_id WHERE tm.telegram_chat_id = ? AND tm.enabled = 1 - AND c.kind = 'public' + AND c.kind IN ('public', 'private') AND c.deleted_at IS NULL LIMIT 1`, ) @@ -134,13 +137,14 @@ export async function getTelegramMappingByChatId(db, telegramChatId) { export async function listEnabledTelegramMappingsForChannel(db, channelId) { const { results } = await db.prepare( - `SELECT tm.id, tm.channel_id, c.name AS channel_name, tm.telegram_chat_id, + `SELECT tm.id, tm.channel_id, c.name AS channel_name, c.kind AS channel_kind, + tm.telegram_chat_id, tm.telegram_chat_title, tm.enabled, tm.created_at, tm.updated_at FROM telegram_mappings tm JOIN channels c ON c.id = tm.channel_id WHERE tm.channel_id = ? AND tm.enabled = 1 - AND c.kind = 'public' + AND c.kind IN ('public', 'private') AND c.deleted_at IS NULL ORDER BY tm.id ASC`, ) @@ -158,7 +162,7 @@ export async function createTelegramMapping(db, { const channelResult = await db.prepare( `SELECT id FROM channels - WHERE id = ? AND kind = 'public' AND deleted_at IS NULL + WHERE id = ? AND kind IN ('public', 'private') AND deleted_at IS NULL LIMIT 1`, ) .bind(Number(channelId)) diff --git a/worker/src/do/ChannelRoom.js b/worker/src/do/ChannelRoom.js index b98ad678..7ea34b72 100644 --- a/worker/src/do/ChannelRoom.js +++ b/worker/src/do/ChannelRoom.js @@ -11,6 +11,7 @@ import { } from '../message-pinning.js'; import { submitExternalMessage } from '../external-message-submission.js'; import { forwardEdgeChatMessageToTelegram } from '../integrations/telegram/bridge.js'; +import { isGroupChannelKind } from '../../../shared/group-channel.ts'; import { authorizeRoom } from '../room-access.js'; import { validateSession } from '../session.js'; import { projectUnreadMessage } from '../unread-projection.js'; @@ -178,7 +179,7 @@ export class ChannelRoom { const payload = await request.json(); const room = payload.room; - if (room?.kind !== 'public' || !Number.isInteger(Number(room.id))) { + if (!isGroupChannelKind(room?.kind) || !Number.isInteger(Number(room.id))) { return new Response('Invalid room', { status: 400 }); } diff --git a/worker/src/integrations/telegram/bridge.js b/worker/src/integrations/telegram/bridge.js index 9a3914cb..40dc8e68 100644 --- a/worker/src/integrations/telegram/bridge.js +++ b/worker/src/integrations/telegram/bridge.js @@ -2,6 +2,7 @@ import { getTelegramCredentials, listEnabledTelegramMappingsForChannel, } from "../../data/telegram.js"; +import { isGroupChannelKind } from "../../../../shared/group-channel.ts"; import { getMessageBySource } from "../../data/messages.js"; import { findMessageReplyBySource, @@ -133,7 +134,7 @@ function telegramReplyMessageId(reference, telegramChatId) { } export async function forwardEdgeChatMessageToTelegram(env, { room, message }) { - if (room.kind !== "public" || message.source === "telegram") { + if (!isGroupChannelKind(room.kind) || message.source === "telegram") { return; } @@ -216,7 +217,7 @@ export async function ingestTelegramMessage(env, { mapping, telegramMessage, bot const response = await submitExternalRoomMessage(env, { room: { id: mapping.channelId, - kind: "public", + kind: mapping.channelKind, name: mapping.channelName, }, content, From 099fa4aeee7a278640f446481455c2da30b54f97 Mon Sep 17 00:00:00 2001 From: gdz66601 Date: Tue, 15 Sep 2026 22:50:28 +0800 Subject: [PATCH 2/2] ci: stop requesting retired Android SDK tools --- .github/workflows/capacitor-android-ci.yml | 2 ++ CHANGELOG.md | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- test/capacitor-android.test.js | 1 + 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/capacitor-android-ci.yml b/.github/workflows/capacitor-android-ci.yml index 3bd3e65f..0e238dc7 100644 --- a/.github/workflows/capacitor-android-ci.yml +++ b/.github/workflows/capacitor-android-ci.yml @@ -43,6 +43,8 @@ jobs: java-version: "21" - name: Setup Android SDK uses: android-actions/setup-android@v3 + with: + packages: platform-tools - name: Install Android SDK 36 run: sdkmanager "platforms;android-36" "build-tools;36.0.0" - name: Validate Gradle wrappers diff --git a/CHANGELOG.md b/CHANGELOG.md index 165191a9..3c67d56c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ EdgeChat 从 `2.1.2` 起正式采用语义化版本。更早的版本号依据已经完成的主要里程碑补记,用于说明项目演进,不对应历史 Git 标签。 +## 2.7.1 - 2026-09-15 + +- 修复 Capacitor Android CI 初始化阶段请求已下架 Android SDK `tools` 包的问题,显式仅安装仍可用的 `platform-tools` 后再安装既有 SDK 36;不改动 Android 源码或功能。 + ## 2.7.0 - 2026-09-15 - Telegram 桥接由仅支持公开群组扩展为支持公开与私有群组,管理员可在同一后台列表中查看群名、区分群类型并统一配置映射。 diff --git a/package-lock.json b/package-lock.json index a149c141..6228f307 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "edgechat", - "version": "2.7.0", + "version": "2.7.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "edgechat", - "version": "2.7.0", + "version": "2.7.1", "dependencies": { "@capacitor/android": "^8.5.1", "@capacitor/core": "^8.5.1", diff --git a/package.json b/package.json index 5ac52e95..c031dbd4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "edgechat", - "version": "2.7.0", + "version": "2.7.1", "private": true, "type": "module", "scripts": { diff --git a/test/capacitor-android.test.js b/test/capacitor-android.test.js index bd63ddfb..ff6b8c71 100644 --- a/test/capacitor-android.test.js +++ b/test/capacitor-android.test.js @@ -45,6 +45,7 @@ test("Capacitor Android CI builds an independent tested APK", () => { const viteConfig = read("../frontend/vite.capacitor.config.js"); assert.match(workflow, /actions\/setup-node@v5/); assert.match(workflow, /node-version: "24"/); + assert.match(workflow, /android-actions\/setup-android@v3[\s\S]*packages: platform-tools/); assert.match(workflow, /gradle\/actions\/wrapper-validation@v4/); assert.match(workflow, /npm run build:capacitor/); assert.match(workflow, /edgechat-capacitor-debug/);