feat: add Telegram private messaging channel
Connect a user-created Telegram bot to channel projects with encrypted credentials, numeric sender allowlists, unified execution and text replies. Use Electron networking for system proxy support, with polling recovery, cancellable delivery retries and live status updates. Add schema 61 channel support, lifecycle regression tests, Electron integration probes and feature documentation. Require the performance principles in AGENTS.md and record three alternating baseline/current Main benchmark rounds. Validation: typecheck, lint and diff checks passed. Full suite: 6087 passed, 87 skipped, one intermittent inline-help Electron failure that passed unchanged in isolation. Real Bot plus model acceptance remains pending; the local TLS proxy probe is opt-in. Release note: 新增 Telegram 私聊通道,可配置 Bot Token 和用户白名单,通过通道项目处理文字请求并回复结果。支持系统代理、断线重连和停用取消;真实 Bot 与模型的完整联调仍待完成。
This commit is contained in:
+11
-1
@@ -92,10 +92,12 @@ import type {
|
||||
} from '../shared/assistant-contracts'
|
||||
import type {
|
||||
ChannelConnectionTestResult,
|
||||
ChannelRuntimeStatusChange,
|
||||
ChannelSettingsApply,
|
||||
ChannelSettingsSnapshot,
|
||||
CredentialChannel,
|
||||
DingTalkChannelSettingsInput,
|
||||
TelegramChannelSettingsInput,
|
||||
WeComChannelSettingsInput
|
||||
} from '../shared/channel-settings-contracts'
|
||||
import type {
|
||||
@@ -626,6 +628,14 @@ const desktopApi: DesktopApi = {
|
||||
}
|
||||
},
|
||||
channels: {
|
||||
onStatusChanged: (listener) => {
|
||||
const handler = (
|
||||
_event: Electron.IpcRendererEvent,
|
||||
change: ChannelRuntimeStatusChange
|
||||
): void => listener(change)
|
||||
ipcRenderer.on(ipcChannels.channelStatusChanged, handler)
|
||||
return () => ipcRenderer.removeListener(ipcChannels.channelStatusChanged, handler)
|
||||
},
|
||||
getSnapshot: () =>
|
||||
ipcRenderer.invoke(
|
||||
ipcChannels.channelSettingsGet
|
||||
@@ -637,7 +647,7 @@ const desktopApi: DesktopApi = {
|
||||
) as Promise<ChannelSettingsSnapshot>,
|
||||
testConnection: (
|
||||
channel: CredentialChannel,
|
||||
settings?: WeComChannelSettingsInput | DingTalkChannelSettingsInput
|
||||
settings?: WeComChannelSettingsInput | DingTalkChannelSettingsInput | TelegramChannelSettingsInput
|
||||
) =>
|
||||
ipcRenderer.invoke(ipcChannels.channelSettingsTest, {
|
||||
channel,
|
||||
|
||||
@@ -1,8 +1,50 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { DesktopApi } from '../shared/contracts'
|
||||
import { ipcChannels } from '../shared/ipc-channels'
|
||||
|
||||
const electron = vi.hoisted(() => ({
|
||||
contextBridge: { exposeInMainWorld: vi.fn() },
|
||||
ipcRenderer: { invoke: vi.fn(), on: vi.fn(), removeListener: vi.fn() },
|
||||
webUtils: {}
|
||||
}))
|
||||
vi.mock('electron', () => electron)
|
||||
|
||||
describe('sandboxed preload', () => {
|
||||
it('forwards status deltas without the Electron event and removes the exact subscription', async () => {
|
||||
await import('./index')
|
||||
const api = electron.contextBridge.exposeInMainWorld.mock.calls[0]![1] as DesktopApi
|
||||
const listener = vi.fn()
|
||||
const unsubscribe = api.channels!.onStatusChanged(listener)
|
||||
const [channel, handler] = electron.ipcRenderer.on.mock.calls.at(-1)!
|
||||
expect(channel).toBe(ipcChannels.channelStatusChanged)
|
||||
const change = { channel: 'telegram', status: { state: 'error', lastError: 'Network unavailable' } }
|
||||
handler({ sender: 'main' }, change)
|
||||
expect(listener).toHaveBeenCalledExactlyOnceWith(change)
|
||||
unsubscribe()
|
||||
expect(electron.ipcRenderer.removeListener).toHaveBeenCalledExactlyOnceWith(channel, handler)
|
||||
})
|
||||
|
||||
it('forwards Telegram settings and draft or saved connection tests through channel IPC', async () => {
|
||||
await import('./index')
|
||||
const api = electron.contextBridge.exposeInMainWorld.mock.calls[0]![1] as DesktopApi
|
||||
const settings = {
|
||||
enabled: false, secret: { action: 'replace' as const, value: '456:test-token' },
|
||||
allowedSenderIds: ['123'], allowGroupMessages: false as const
|
||||
}
|
||||
await api.channels!.getSnapshot()
|
||||
await api.channels!.apply({ telegram: settings })
|
||||
await api.channels!.testConnection('telegram', settings)
|
||||
await api.channels!.testConnection('telegram')
|
||||
expect(electron.ipcRenderer.invoke.mock.calls).toEqual([
|
||||
[ipcChannels.channelSettingsGet],
|
||||
[ipcChannels.channelSettingsApply, { telegram: settings }],
|
||||
[ipcChannels.channelSettingsTest, { channel: 'telegram', settings }],
|
||||
[ipcChannels.channelSettingsTest, { channel: 'telegram', settings: undefined }]
|
||||
])
|
||||
})
|
||||
|
||||
it('does not import Node built-ins unavailable in Electron sandbox', () => {
|
||||
const source = readFileSync(
|
||||
join(process.cwd(), 'src', 'preload', 'index.ts'),
|
||||
|
||||
Reference in New Issue
Block a user