telegram integration: add disconnect/connect toggle

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-02 21:03:37 +00:00
co-authored by Claude Opus 4.6
parent 40a9768cb3
commit 72d1341cbc
@@ -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'}
</span>
</div>
@@ -196,6 +226,28 @@ export const TelegramBotConfig = () => {
>
{isSaving ? 'Saving...' : 'Save'}
</Button>
{status?.running ? (
<Button
type="button"
variant="outline"
onClick={handleDisconnect}
disabled={isToggling}
className="w-full h-11 cursor-pointer"
>
{isToggling ? 'Disconnecting...' : 'Disconnect'}
</Button>
) : status?.configured && !status.enabled ? (
<Button
type="button"
variant="outline"
onClick={handleConnect}
disabled={isToggling}
className="w-full h-11 cursor-pointer"
>
{isToggling ? 'Connecting...' : 'Connect'}
</Button>
) : null}
</div>
</div>
);