Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(desktop): add Channels configuration page with Telegram support

Naiyuan Qingc99675b6e449
diff --git a/apps/desktop/electron/electron-env.d.ts b/apps/desktop/electron/electron-env.d.ts
index d9a5846e66..b53664a40e 100644
--- a/apps/desktop/electron/electron-env.d.ts
+++ b/apps/desktop/electron/electron-env.d.ts
@@ -132,6 +132,13 @@ interface CurrentProviderInfo {
available: boolean
}
+interface ChannelAccountStateInfo {
+ channelId: string
+ accountId: string
+ status: 'stopped' | 'starting' | 'running' | 'error'
+ error?: string
+}
+
interface ElectronAPI {
hub: {
init: () => Promise<unknown>
@@ -190,6 +197,14 @@ interface ElectronAPI {
saveApiKey: (providerId: string, apiKey: string) => Promise<{ ok: boolean; error?: string }>
importOAuth: (providerId: string) => Promise<{ ok: boolean; expiresAt?: number; error?: string }>
}
+ channels: {
+ listStates: () => Promise<ChannelAccountStateInfo[]>
+ getConfig: () => Promise<Record<string, Record<string, Record<string, unknown>> | undefined>>
+ saveToken: (channelId: string, accountId: string, token: string) => Promise<{ ok: boolean; error?: string }>
+ removeToken: (channelId: string, accountId: string) => Promise<{ ok: boolean; error?: string }>
+ stop: (channelId: string, accountId: string) => Promise<{ ok: boolean }>
+ start: (channelId: string, accountId: string) => Promise<{ ok: boolean; error?: string }>
+ }
localChat: {
subscribe: (agentId: string) => Promise<{ ok?: boolean; error?: string; alreadySubscribed?: boolean }>
unsubscribe: (agentId: string) => Promise<{ ok: boolean }>
diff --git a/apps/desktop/electron/ipc/channels.ts b/apps/desktop/electron/ipc/channels.ts
new file mode 100644
index 0000000000..dd85ef7488
--- /dev/null
+++ b/apps/desktop/electron/ipc/channels.ts
@@ -0,0 +1,133 @@
+/**
+ * Channel IPC handlers for Electron main process.
+ *
+ * Manages channel account configuration, start/stop lifecycle.
+ * The Channels page in the renderer uses these to configure
+ * Telegram (and future channels) with immediate effect.
+ */
+import { ipcMain } from 'electron'
+import { getCurrentHub } from './hub.js'
+import { credentialManager } from '../../../../src/agent/credentials.js'
+import { listChannels } from '../../../../src/channels/registry.js'
+
+/**
+ * Register all Channel-related IPC handlers.
+ */
+export function registerChannelsIpcHandlers(): void {
+ /**
+ * List all channel account states (running / stopped / error).
+ */
+ ipcMain.handle('channels:listStates', async () => {
+ const hub = getCurrentHub()
+ if (!hub) return []
+ return hub.channelManager.listAccountStates()
+ })
+
+ /**
+ * Get the channels config from credentials.json5.
+ * Returns the raw `channels` section: { telegram: { default: { botToken: "..." } } }
+ */
+ ipcMain.handle('channels:getConfig', async () => {
+ return credentialManager.getChannelsConfig()
+ })
+
+ /**
+ * Save a channel account token and start the bot immediately.
+ * Flow: write to credentials.json5 → start the channel account.
+ */
+ ipcMain.handle(
+ 'channels:saveToken',
+ async (_event, channelId: string, accountId: string, token: string): Promise<{ ok: boolean; error?: string }> => {
+ try {
+ const hub = getCurrentHub()
+ if (!hub) return { ok: false, error: 'Hub not initialized' }
+
+ // Find the plugin to validate channelId
+ const plugin = listChannels().find((p) => p.id === channelId)
+ if (!plugin) return { ok: false, error: `Unknown channel: ${channelId}` }
+
+ // Persist config to credentials.json5
+ credentialManager.setChannelAccountConfig(channelId, accountId, { botToken: token })
+ console.log(`[IPC] Channel config saved: ${channelId}:${accountId}`)
+
+ // Stop existing account if running (e.g. token update)
+ hub.channelManager.stopAccount(channelId, accountId)
+
+ // Start the account with the new config
+ await hub.channelManager.startAccount(channelId, accountId, { botToken: token })
+ console.log(`[IPC] Channel started: ${channelId}:${accountId}`)
+
+ return { ok: true }
+ } catch (err) {
+ const message = err instanceof Error ? err.message : String(err)
+ console.error(`[IPC] Failed to save channel token: ${message}`)
+ return { ok: false, error: message }
+ }
+ }
+ )
+
+ /**
+ * Remove a channel account token and stop the bot.
+ */
+ ipcMain.handle(
+ 'channels:removeToken',
+ async (_event, channelId: string, accountId: string): Promise<{ ok: boolean; error?: string }> => {
+ try {
+ const hub = getCurrentHub()
+ if (!hub) return { ok: false, error: 'Hub not initialized' }
+
+ // Stop the account
+ hub.channelManager.stopAccount(channelId, accountId)
+
+ // Remove from credentials.json5
+ credentialManager.removeChannelAccountConfig(channelId, accountId)
+ console.log(`[IPC] Channel config removed: ${channelId}:${accountId}`)
+
+ return { ok: true }
+ } catch (err) {
+ const message = err instanceof Error ? err.message : String(err)
+ console.error(`[IPC] Failed to remove channel token: ${message}`)
+ return { ok: false, error: message }
+ }
+ }
+ )
+
+ /**
+ * Stop a channel account without removing its config.
+ */
+ ipcMain.handle(
+ 'channels:stop',
+ async (_event, channelId: string, accountId: string): Promise<{ ok: boolean }> => {
+ const hub = getCurrentHub()
+ if (!hub) return { ok: false }
+ hub.channelManager.stopAccount(channelId, accountId)
+ return { ok: true }
+ }
+ )
+
+ /**
+ * Start a channel account using its saved config.
+ */
+ ipcMain.handle(
+ 'channels:start',
+ async (_event, channelId: string, accountId: string): Promise<{ ok: boolean; error?: string }> => {
+ try {
+ const hub = getCurrentHub()
+ if (!hub) return { ok: false, error: 'Hub not initialized' }
+
+ // Read config from credentials
+ const config = credentialManager.getChannelsConfig()
+ const accountConfig = config[channelId]?.[accountId]
+ if (!accountConfig) {
+ return { ok: false, error: `No config found for ${channelId}:${accountId}` }
+ }
+
+ await hub.channelManager.startAccount(channelId, accountId, accountConfig)
+ return { ok: true }
+ } catch (err) {
+ const message = err instanceof Error ? err.message : String(err)
+ return { ok: false, error: message }
+ }
+ }
+ )
+}
diff --git a/apps/desktop/electron/ipc/index.ts b/apps/desktop/electron/ipc/index.ts
index fc11179c64..7c7c596e18 100644
--- a/apps/desktop/electron/ipc/index.ts
+++ b/apps/desktop/electron/ipc/index.ts
@@ -6,12 +6,14 @@ export { registerSkillsIpcHandlers } from './skills.js'
export { registerHubIpcHandlers, cleanupHub, initializeHub, setupDeviceConfirmation } from './hub.js'
export { registerProfileIpcHandlers } from './profile.js'
export { registerProviderIpcHandlers } from './provider.js'
+export { registerChannelsIpcHandlers } from './channels.js'
import { registerAgentIpcHandlers, cleanupAgent } from './agent.js'
import { registerSkillsIpcHandlers } from './skills.js'
import { registerHubIpcHandlers, cleanupHub, initializeHub } from './hub.js'
import { registerProfileIpcHandlers } from './profile.js'
import { registerProviderIpcHandlers } from './provider.js'
+import { registerChannelsIpcHandlers } from './channels.js'
/**
* Register all IPC handlers.
@@ -23,6 +25,7 @@ export function registerAllIpcHandlers(): void {
registerSkillsIpcHandlers()
registerProfileIpcHandlers()
registerProviderIpcHandlers()
+ registerChannelsIpcHandlers()
}
/**
diff --git a/apps/desktop/electron/preload.ts b/apps/desktop/electron/preload.ts
index a0d3d00e2d..6c963a94e4 100644
--- a/apps/desktop/electron/preload.ts
+++ b/apps/desktop/electron/preload.ts
@@ -201,6 +201,26 @@ const electronAPI = {
ipcRenderer.invoke('provider:importOAuth', providerId),
},
+ // Channel management (Telegram, Discord, etc.)
+ channels: {
+ /** List all channel account states */
+ listStates: () => ipcRenderer.invoke('channels:listStates'),
+ /** Get channels config from credentials.json5 */
+ getConfig: () => ipcRenderer.invoke('channels:getConfig'),
+ /** Save a channel token and start the bot immediately */
+ saveToken: (channelId: string, accountId: string, token: string) =>
+ ipcRenderer.invoke('channels:saveToken', channelId, accountId, token),
+ /** Remove a channel token and stop the bot */
+ removeToken: (channelId: string, accountId: string) =>
+ ipcRenderer.invoke('channels:removeToken', channelId, accountId),
+ /** Stop a channel account */
+ stop: (channelId: string, accountId: string) =>
+ ipcRenderer.invoke('channels:stop', channelId, accountId),
+ /** Start a channel account from saved config */
+ start: (channelId: string, accountId: string) =>
+ ipcRenderer.invoke('channels:start', channelId, accountId),
+ },
+
// Local chat (direct IPC, no Gateway required)
localChat: {
/** Subscribe to agent events for local direct chat */
diff --git a/apps/desktop/src/App.tsx b/apps/desktop/src/App.tsx
index df6ae8b16f..ac89454e95 100644
--- a/apps/desktop/src/App.tsx
+++ b/apps/desktop/src/App.tsx
@@ -4,6 +4,7 @@ import HomePage from './pages/home'
import ChatPage from './pages/chat'
import ToolsPage from './pages/tools'
import SkillsPage from './pages/skills'
+import ChannelsPage from './pages/channels'
const router = createHashRouter([
{
@@ -14,6 +15,7 @@ const router = createHashRouter([
{ path: 'chat', element: <ChatPage /> },
{ path: 'tools', element: <ToolsPage /> },
{ path: 'skills', element: <SkillsPage /> },
+ { path: 'channels', element: <ChannelsPage /> },
],
},
])
diff --git a/apps/desktop/src/hooks/use-channels.ts b/apps/desktop/src/hooks/use-channels.ts
new file mode 100644
index 0000000000..29f52100a3
--- /dev/null
+++ b/apps/desktop/src/hooks/use-channels.ts
@@ -0,0 +1,121 @@
+/**
+ * Hook for managing channel accounts (Telegram, Discord, etc.) in the Desktop App.
+ *
+ * Provides state and actions for the Channels settings page:
+ * - List channel account states (running / stopped / error)
+ * - Read channel config (tokens)
+ * - Save / remove tokens with immediate start/stop
+ */
+import { useState, useEffect, useCallback } from 'react'
+
+interface UseChannelsReturn {
+ /** Runtime states of all channel accounts */
+ states: ChannelAccountStateInfo[]
+ /** Raw channel config from credentials.json5 */
+ config: Record<string, Record<string, Record<string, unknown>> | undefined>
+ /** Loading state */
+ loading: boolean
+ /** Error message if any */
+ error: string | null
+ /** Refresh states and config */
+ refresh: () => Promise<void>
+ /** Save a bot token — persists to file and starts the bot immediately */
+ saveToken: (channelId: string, accountId: string, token: string) => Promise<{ ok: boolean; error?: string }>
+ /** Remove a bot token — stops the bot and removes from file */
+ removeToken: (channelId: string, accountId: string) => Promise<{ ok: boolean; error?: string }>
+ /** Stop a channel account without removing config */
+ stopChannel: (channelId: string, accountId: string) => Promise<void>
+ /** Start a channel account from saved config */
+ startChannel: (channelId: string, accountId: string) => Promise<void>
+}
+
+export function useChannels(): UseChannelsReturn {
+ const [states, setStates] = useState<ChannelAccountStateInfo[]>([])
+ const [config, setConfig] = useState<Record<string, Record<string, Record<string, unknown>> | undefined>>({})
+ const [loading, setLoading] = useState(true)
+ const [error, setError] = useState<string | null>(null)
+
+ const refresh = useCallback(async () => {
+ setLoading(true)
+ setError(null)
+
+ try {
+ const [stateList, channelConfig] = await Promise.all([
+ window.electronAPI.channels.listStates(),
+ window.electronAPI.channels.getConfig(),
+ ])
+
+ setStates(stateList)
+ setConfig(channelConfig)
+ } catch (err) {
+ const message = err instanceof Error ? err.message : String(err)
+ setError(message)
+ console.error('[useChannels] Failed to load:', message)
+ } finally {
+ setLoading(false)
+ }
+ }, [])
+
+ useEffect(() => {
+ refresh()
+ }, [refresh])
+
+ const saveToken = useCallback(async (channelId: string, accountId: string, token: string) => {
+ setError(null)
+ try {
+ const result = await window.electronAPI.channels.saveToken(channelId, accountId, token)
+ if (!result.ok) {
+ setError(result.error ?? 'Failed to save token')
+ }
+ // Refresh to pick up new state
+ await refresh()
+ return result
+ } catch (err) {
+ const message = err instanceof Error ? err.message : String(err)
+ setError(message)
+ return { ok: false, error: message }
+ }
+ }, [refresh])
+
+ const removeToken = useCallback(async (channelId: string, accountId: string) => {
+ setError(null)
+ try {
+ const result = await window.electronAPI.channels.removeToken(channelId, accountId)
+ if (!result.ok) {
+ setError(result.error ?? 'Failed to remove token')
+ }
+ await refresh()
+ return result
+ } catch (err) {
+ const message = err instanceof Error ? err.message : String(err)
+ setError(message)
+ return { ok: false, error: message }
+ }
+ }, [refresh])
+
+ const stopChannel = useCallback(async (channelId: string, accountId: string) => {
+ await window.electronAPI.channels.stop(channelId, accountId)
+ await refresh()
+ }, [refresh])
+
+ const startChannel = useCallback(async (channelId: string, accountId: string) => {
+ setError(null)
+ const result = await window.electronAPI.channels.start(channelId, accountId)
+ if (!result.ok) {
+ setError(result.error ?? 'Failed to start channel')
+ }
+ await refresh()
+ }, [refresh])
+
+ return {
+ states,
+ config,
+ loading,
+ error,
+ refresh,
+ saveToken,
+ removeToken,
+ stopChannel,
+ startChannel,
+ }
+}
diff --git a/apps/desktop/src/pages/channels.tsx b/apps/desktop/src/pages/channels.tsx
new file mode 100644
index 0000000000..1f7b38cdfe
--- /dev/null
+++ b/apps/desktop/src/pages/channels.tsx
@@ -0,0 +1,175 @@
+import { useState } from 'react'
+import {
+ Card,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+} from '@multica/ui/components/ui/card'
+import { Button } from '@multica/ui/components/ui/button'
+import { Input } from '@multica/ui/components/ui/input'
+import { Badge } from '@multica/ui/components/ui/badge'
+import { useChannels } from '../hooks/use-channels'
+
+/** Status badge color mapping */
+function statusVariant(status: string): 'default' | 'secondary' | 'destructive' | 'outline' {
+ switch (status) {
+ case 'running': return 'default'
+ case 'starting': return 'secondary'
+ case 'error': return 'destructive'
+ default: return 'outline'
+ }
+}
+
+function TelegramCard() {
+ const { states, config, saveToken, removeToken, startChannel, stopChannel } = useChannels()
+ const [token, setToken] = useState('')
+ const [saving, setSaving] = useState(false)
+ const [localError, setLocalError] = useState<string | null>(null)
+
+ // Current state and config for telegram:default
+ const state = states.find((s) => s.channelId === 'telegram' && s.accountId === 'default')
+ const savedConfig = config['telegram']?.['default'] as { botToken?: string } | undefined
+ const hasToken = Boolean(savedConfig?.botToken)
+ const isRunning = state?.status === 'running'
+ const isStarting = state?.status === 'starting'
+
+ const handleSave = async () => {
+ if (!token.trim()) return
+ setSaving(true)
+ setLocalError(null)
+ const result = await saveToken('telegram', 'default', token.trim())
+ if (!result.ok) {
+ setLocalError(result.error ?? 'Failed to save')
+ } else {
+ setToken('') // Clear input on success
+ }
+ setSaving(false)
+ }
+
+ const handleRemove = async () => {
+ setSaving(true)
+ setLocalError(null)
+ const result = await removeToken('telegram', 'default')
+ if (!result.ok) {
+ setLocalError(result.error ?? 'Failed to remove')
+ }
+ setSaving(false)
+ }
+
+ const handleToggle = async () => {
+ setSaving(true)
+ setLocalError(null)
+ if (isRunning || isStarting) {
+ await stopChannel('telegram', 'default')
+ } else {
+ await startChannel('telegram', 'default')
+ }
+ setSaving(false)
+ }
+
+ // Mask the token for display: show first 5 and last 5 chars
+ const maskedToken = savedConfig?.botToken
+ ? `${savedConfig.botToken.slice(0, 5)}${'*'.repeat(10)}${savedConfig.botToken.slice(-5)}`
+ : null
+
+ return (
+ <Card>
+ <CardHeader>
+ <div className="flex items-center justify-between">
+ <div>
+ <CardTitle>Telegram</CardTitle>
+ <CardDescription>
+ Connect a Telegram bot via Bot API long polling.
+ </CardDescription>
+ </div>
+ {state && (
+ <Badge variant={statusVariant(state.status)}>
+ {state.status}
+ </Badge>
+ )}
+ </div>
+ </CardHeader>
+ <CardContent className="space-y-4">
+ {hasToken ? (
+ // Token is configured — show masked token and actions
+ <div className="space-y-3">
+ <div className="flex items-center gap-2">
+ <code className="text-sm text-muted-foreground bg-muted px-2 py-1 rounded flex-1 truncate">
+ {maskedToken}
+ </code>
+ </div>
+
+ {state?.error && (
+ <p className="text-sm text-destructive">{state.error}</p>
+ )}
+
+ <div className="flex gap-2">
+ <Button
+ variant={isRunning ? 'outline' : 'default'}
+ size="sm"
+ onClick={handleToggle}
+ disabled={saving}
+ >
+ {isRunning ? 'Stop' : isStarting ? 'Starting...' : 'Start'}
+ </Button>
+ <Button
+ variant="destructive"
+ size="sm"
+ onClick={handleRemove}
+ disabled={saving || isRunning}
+ >
+ Remove
+ </Button>
+ </div>
+ </div>
+ ) : (
+ // No token — show input form
+ <div className="space-y-3">
+ <Input
+ type="password"
+ placeholder="Bot Token (from @BotFather)"
+ value={token}
+ onChange={(e) => setToken(e.target.value)}
+ onKeyDown={(e) => e.key === 'Enter' && handleSave()}
+ />
+ <Button
+ size="sm"
+ onClick={handleSave}
+ disabled={saving || !token.trim()}
+ >
+ {saving ? 'Saving...' : 'Save & Connect'}
+ </Button>
+ </div>
+ )}
+
+ {localError && (
+ <p className="text-sm text-destructive">{localError}</p>
+ )}
+ </CardContent>
+ </Card>
+ )
+}
+
+export default function ChannelsPage() {
+ const { loading, error } = useChannels()
+
+ return (
+ <div className="max-w-4xl mx-auto space-y-4">
+ <div>
+ <h2 className="text-lg font-semibold">Channels</h2>
+ <p className="text-sm text-muted-foreground">
+ Connect messaging platforms to your Agent.
+ </p>
+ </div>
+
+ {loading ? (
+ <p className="text-sm text-muted-foreground">Loading...</p>
+ ) : error ? (
+ <p className="text-sm text-destructive">{error}</p>
+ ) : (
+ <TelegramCard />
+ )}
+ </div>
+ )
+}
diff --git a/apps/desktop/src/pages/layout.tsx b/apps/desktop/src/pages/layout.tsx
index 85e97e1539..47e5af0d1c 100644
--- a/apps/desktop/src/pages/layout.tsx
+++ b/apps/desktop/src/pages/layout.tsx
@@ -8,6 +8,7 @@ import {
CodeIcon,
PlugIcon,
Comment01Icon,
+ Share08Icon,
} from '@hugeicons/core-free-icons'
import { cn } from '@multica/ui/lib/utils'
import { DeviceConfirmDialog } from '../components/device-confirm-dialog'
@@ -18,6 +19,7 @@ const tabs = [
{ path: '/chat', label: 'Chat', icon: Comment01Icon },
{ path: '/tools', label: 'Tools', icon: CodeIcon },
{ path: '/skills', label: 'Skills', icon: PlugIcon },
+ { path: '/channels', label: 'Channels', icon: Share08Icon },
]
export default function Layout() {