From d9d6e4f657319d55f17deeba708a90e786d4e997 Mon Sep 17 00:00:00 2001 From: Nexus Dev Date: Sat, 4 Apr 2026 03:12:31 +0000 Subject: [PATCH] feat(38-03): create TelegramStep onboarding component - BotFather numbered instructions (4-step setup guide) - Token input with live validation via POST /api/telegram/token - Success state showing connected bot username - Error state with descriptive message - Skip/Back/Next navigation; Next enabled only after validation --- ui/src/components/onboarding/TelegramStep.tsx | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 ui/src/components/onboarding/TelegramStep.tsx diff --git a/ui/src/components/onboarding/TelegramStep.tsx b/ui/src/components/onboarding/TelegramStep.tsx new file mode 100644 index 00000000..d7d6e0ad --- /dev/null +++ b/ui/src/components/onboarding/TelegramStep.tsx @@ -0,0 +1,157 @@ +// [nexus] Telegram bridge onboarding step — BotFather guided setup with token validation +import { useState } from "react"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { cn } from "@/lib/utils"; + +interface TelegramStepProps { + onNext: () => void; + onBack: () => void; +} + +export function TelegramStep({ onNext, onBack }: TelegramStepProps) { + const [token, setToken] = useState(""); + const [validating, setValidating] = useState(false); + const [botUsername, setBotUsername] = useState(null); + const [error, setError] = useState(null); + + async function handleValidate() { + if (!token.trim()) return; + setValidating(true); + setError(null); + setBotUsername(null); + + try { + const res = await fetch("/api/telegram/token", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ token: token.trim() }), + }); + + if (res.ok) { + const data = await res.json(); + setBotUsername(data.botUsername ?? data.bot_username ?? null); + } else { + let msg = "Invalid token"; + try { + const data = await res.json(); + if (data?.error) msg = data.error; + } catch { + // ignore parse errors + } + setError(msg); + } + } catch { + setError("Could not reach the server. Check your connection and try again."); + } finally { + setValidating(false); + } + } + + return ( +
+ {/* Header */} +
+

Connect Telegram

+

+ Get instant notifications and interact with your agents via Telegram. +

+
+ + {/* BotFather instructions */} +
+

Set up your bot in 4 steps:

+
    + {[ + <>Open Telegram and search for @BotFather, + <>Send /newbot and follow the prompts to create a bot, + <>Copy the bot token — it looks like 123456:ABC-DEF..., + "Paste the token below and click Validate", + ].map((instruction, i) => ( +
  1. + + {i + 1} + + {instruction} +
  2. + ))} +
+
+ + {/* Token input */} +
+ + { + setToken(e.target.value); + setBotUsername(null); + setError(null); + }} + disabled={validating} + autoComplete="off" + className="font-mono text-sm" + /> + + {/* Success state */} + {botUsername && ( +

+ Connected to @{botUsername} +

+ )} + + {/* Error state */} + {error && ( +

+ {error} +

+ )} +
+ + {/* Actions */} +
+ + + + + + + +
+
+ ); +}