peppa/apps/web/components/OwnBotSteps.tsx
Асель 664f96a92e PEP-97: users see «Пеппа ЗАВОД» everywhere — logo, titles, app name, texts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 14:25:12 +05:00

98 lines
5.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { connectOwnBotAction, disconnectOwnBotAction, pairTelegram } from "@/app/(app)/actions";
import { Hidden } from "@/components/cards";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { cn } from "@/lib/utils";
function StepNum({ n, done }: { n: number; done: boolean }) {
return (
<span aria-hidden className={cn("mt-0.5 grid size-5.5 shrink-0 place-items-center rounded-full text-xs font-semibold", done ? "bg-ok/20 text-ok" : "bg-primary/15 text-primary")}>
{done ? "✓" : n}
</span>
);
}
/**
* PEP-85: connecting the user's own Telegram bot in three plain steps (BotFather → token →
* Start). Shown on the Home page as the first thing a new user does, and in Settings.
*/
export function OwnBotSteps({ botUsername, back, bare = false }: { botUsername: string | null; back: string; bare?: boolean }) {
const hasBot = !!botUsername;
const fields = { back };
return (
<div className={cn("flex flex-col gap-4", !bare && "rounded-lg border bg-card p-4")}>
{!bare && (
<p className="m-0 text-sm">
Через Telegram завод зовёт вас, когда агенту нужен ответ или работа готова, — отвечать можно кнопками с телефона. У каждого пользователя свой бот: вы создаёте его за две минуты, без программирования.
</p>
)}
<ol className="m-0 flex list-none flex-col gap-3 p-0 text-sm">
<li className="flex gap-2.5">
<StepNum n={1} done={hasBot} />
<div className="flex min-w-0 flex-col items-start gap-1.5">
<span className="font-medium">Создайте бота в Telegram</span>
{!hasBot && (
<>
<span className="text-muted-foreground">
Откройте <b>@BotFather</b> (официальный бот Telegram), отправьте ему <span className="font-mono">/newbot</span>, придумайте название и адрес — адрес должен заканчиваться на <span className="font-mono">bot</span>, например{" "}
<span className="font-mono">my_factory_bot</span>.
</span>
<Button asChild size="sm" variant="outline">
<a href="https://t.me/BotFather" target="_blank" rel="noreferrer">Открыть BotFather</a>
</Button>
</>
)}
</div>
</li>
<li className="flex gap-2.5">
<StepNum n={2} done={hasBot} />
<div className="flex min-w-0 flex-1 flex-col items-start gap-1.5">
<span className="font-medium">Вставьте токен бота</span>
{hasBot ? (
<span className="text-muted-foreground">
Подключён <span className="font-mono">@{botUsername}</span>. Токен хранится зашифрованным.
</span>
) : (
<>
<span className="text-muted-foreground">
BotFather пришлёт сообщение с длинной строкой вида <span className="font-mono">1234567890:AAH…</span> — это токен. Скопируйте его сюда. Пеппа хранит его зашифрованным и никому не показывает.
</span>
<form action={connectOwnBotAction} className="flex w-full flex-wrap gap-2">
<Hidden fields={fields} />
<Input name="token" type="password" required autoComplete="off" placeholder="Токен от BotFather" aria-label="Токен бота" className="h-9 min-w-48 flex-1 font-mono" />
<Button variant="default">Подключить бота</Button>
</form>
</>
)}
</div>
</li>
<li className="flex gap-2.5">
<StepNum n={3} done={false} />
<div className="flex min-w-0 flex-col items-start gap-1.5">
<span className="font-medium">Откройте своего бота и нажмите Start</span>
<span className="text-muted-foreground">Так бот узнает, куда вам писать. Удобнее сделать это на телефоне — там и будут приходить сообщения.</span>
{hasBot && (
<form action={pairTelegram}>
<Hidden fields={fields} />
<Button variant="default" size="sm">Открыть @{botUsername}</Button>
</form>
)}
</div>
</li>
</ol>
{hasBot ? (
<form action={disconnectOwnBotAction}>
<Hidden fields={fields} />
<Button size="xs" variant="ghost" className="text-muted-foreground">Отключить этого бота</Button>
</form>
) : (
<form action={pairTelegram} className="flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
<Hidden fields={fields} />
Не хотите создавать бота?
<Button size="xs" variant="ghost">Использовать общего бота Пеппы</Button>
</form>
)}
</div>
);
}