From 72d1341cbc680d6e1adb8a3c3b7f17bb260bc773 Mon Sep 17 00:00:00 2001 From: Andre Padez Date: Mon, 2 Mar 2026 21:03:37 +0000 Subject: [PATCH] telegram integration: add disconnect/connect toggle Co-Authored-By: Claude Opus 4.6 --- .../TelegramBotConfig.tsx | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/apps/officer-web/Screens/Dashboard/Settings/IntegrationsSettings/TelegramBotConfig.tsx b/src/apps/officer-web/Screens/Dashboard/Settings/IntegrationsSettings/TelegramBotConfig.tsx index e02f17f3..7a3ac183 100644 --- a/src/apps/officer-web/Screens/Dashboard/Settings/IntegrationsSettings/TelegramBotConfig.tsx +++ b/src/apps/officer-web/Screens/Dashboard/Settings/IntegrationsSettings/TelegramBotConfig.tsx @@ -86,6 +86,7 @@ export const TelegramBotConfig = () => { const client = useClient(); const [isLoading, setIsLoading] = useState(true); const [isSaving, setIsSaving] = useState(false); + const [isToggling, setIsToggling] = useState(false); const [botToken, setBotToken] = useState(''); const [serverInvite, setServerInvite] = useState(''); const [botHandle, setBotHandle] = useState(''); @@ -119,6 +120,7 @@ export const TelegramBotConfig = () => { botToken: botToken.trim(), serverInvite: serverInvite.trim() || undefined, botHandle: botHandle.trim() || undefined, + enabled: true, }); toast.success('Telegram bot configuration saved'); fetchStatus(); @@ -129,6 +131,32 @@ export const TelegramBotConfig = () => { } }; + const handleDisconnect = async () => { + setIsToggling(true); + try { + await client.put('/channels/telegram/config', { enabled: false }); + toast.success('Telegram bot disconnected'); + fetchStatus(); + } catch { + toast.error('Failed to disconnect Telegram bot'); + } finally { + setIsToggling(false); + } + }; + + const handleConnect = async () => { + setIsToggling(true); + try { + await client.put('/channels/telegram/config', { enabled: true }); + toast.success('Telegram bot connected'); + fetchStatus(); + } catch { + toast.error('Failed to connect Telegram bot'); + } finally { + setIsToggling(false); + } + }; + if (isLoading) return null; return ( @@ -142,7 +170,9 @@ export const TelegramBotConfig = () => { {status.running ? `Online as @${status.botUsername}` : status.configured - ? 'Bot configured but not running' + ? status.enabled + ? 'Bot configured but not running' + : 'Disconnected' : 'Not configured'} @@ -196,6 +226,28 @@ export const TelegramBotConfig = () => { > {isSaving ? 'Saving...' : 'Save'} + + {status?.running ? ( + + ) : status?.configured && !status.enabled ? ( + + ) : null} );