telegram integration: add disconnect/connect toggle
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+53
-1
@@ -86,6 +86,7 @@ export const TelegramBotConfig = () => {
|
|||||||
const client = useClient();
|
const client = useClient();
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [isSaving, setIsSaving] = useState(false);
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
|
const [isToggling, setIsToggling] = useState(false);
|
||||||
const [botToken, setBotToken] = useState('');
|
const [botToken, setBotToken] = useState('');
|
||||||
const [serverInvite, setServerInvite] = useState('');
|
const [serverInvite, setServerInvite] = useState('');
|
||||||
const [botHandle, setBotHandle] = useState('');
|
const [botHandle, setBotHandle] = useState('');
|
||||||
@@ -119,6 +120,7 @@ export const TelegramBotConfig = () => {
|
|||||||
botToken: botToken.trim(),
|
botToken: botToken.trim(),
|
||||||
serverInvite: serverInvite.trim() || undefined,
|
serverInvite: serverInvite.trim() || undefined,
|
||||||
botHandle: botHandle.trim() || undefined,
|
botHandle: botHandle.trim() || undefined,
|
||||||
|
enabled: true,
|
||||||
});
|
});
|
||||||
toast.success('Telegram bot configuration saved');
|
toast.success('Telegram bot configuration saved');
|
||||||
fetchStatus();
|
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;
|
if (isLoading) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -142,7 +170,9 @@ export const TelegramBotConfig = () => {
|
|||||||
{status.running
|
{status.running
|
||||||
? `Online as @${status.botUsername}`
|
? `Online as @${status.botUsername}`
|
||||||
: status.configured
|
: status.configured
|
||||||
? 'Bot configured but not running'
|
? status.enabled
|
||||||
|
? 'Bot configured but not running'
|
||||||
|
: 'Disconnected'
|
||||||
: 'Not configured'}
|
: 'Not configured'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -196,6 +226,28 @@ export const TelegramBotConfig = () => {
|
|||||||
>
|
>
|
||||||
{isSaving ? 'Saving...' : 'Save'}
|
{isSaving ? 'Saving...' : 'Save'}
|
||||||
</Button>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user