Merge pull request 'PEP-86: подключение своего Telegram-бота — первым шагом на Главной' (#78) from task/pep-86 into main
This commit is contained in:
commit
0157c74c94
@ -714,7 +714,8 @@ export async function connectOwnBotAction(f: FormData) {
|
||||
const user = asWebActor(await requireUser());
|
||||
await attempt(f, async () => {
|
||||
await setUserBot(db, user.id, String(f.get("token") ?? ""));
|
||||
return "/settings?bot=connected#telegram";
|
||||
// On the Home page the next step (Start) shows right there.
|
||||
return str(f, "back") === "/" ? "/" : "/settings?bot=connected#telegram";
|
||||
});
|
||||
}
|
||||
|
||||
@ -722,6 +723,6 @@ export async function disconnectOwnBotAction(f: FormData) {
|
||||
const user = asWebActor(await requireUser());
|
||||
await attempt(f, async () => {
|
||||
await clearUserBot(db, user.id);
|
||||
return "/settings#telegram";
|
||||
return str(f, "back") === "/" ? "/" : "/settings#telegram";
|
||||
});
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ export default async function Home({ searchParams }: { searchParams: Promise<{ e
|
||||
<LiveRefresh scope="home" />
|
||||
<Flash error={error} />
|
||||
<PageHeader title="Главная">{items.length ? "Агенты ждут твоего решения — ответь здесь, в Telegram или через MCP." : "Всё идёт само: агентам от тебя ничего не нужно."}</PageHeader>
|
||||
{onboarding.visible && <OnboardingChecklist data={onboarding} />}
|
||||
{onboarding.visible && <OnboardingChecklist data={onboarding} botUsername={user.telegramBotUsername} />}
|
||||
<Section title="Вопросы агентов" count={items.length}>
|
||||
<PugBanner count={items.length} />
|
||||
{items.map((q) => <QuestionCard key={q.id} q={q} taskKey={q.taskKey} taskStatus={q.taskStatus} back="/" />)}
|
||||
|
||||
@ -5,23 +5,16 @@ import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Input, Label } from "@/components/ui/input";
|
||||
import { EgovSign } from "@/components/EgovSign";
|
||||
import { OwnBotSteps } from "@/components/OwnBotSteps";
|
||||
import { Workspace } from "@/components/Workspace";
|
||||
import { publicOrigin, requireUser } from "@/lib/auth";
|
||||
import { db } from "@/lib/db";
|
||||
import { connectOwnBotAction, disconnectOwnBotAction, pairTelegram, revokeConnectedApp, saveNotifyPrefsAction, unpairTelegramAction } from "../actions";
|
||||
import { disconnectOwnBotAction, revokeConnectedApp, saveNotifyPrefsAction, unpairTelegramAction } from "../actions";
|
||||
import { PushNotifications } from "@/components/PushNotifications";
|
||||
import { TimezoneField } from "@/components/TimezoneField";
|
||||
|
||||
const back = { back: "/settings" };
|
||||
|
||||
function StepNum({ n, done }: { n: number; done: boolean }) {
|
||||
return (
|
||||
<span aria-hidden className={done ? "mt-0.5 grid size-5.5 shrink-0 place-items-center rounded-full bg-ok/20 text-xs font-semibold text-ok" : "mt-0.5 grid size-5.5 shrink-0 place-items-center rounded-full bg-primary/15 text-xs font-semibold text-primary"}>
|
||||
{done ? "✓" : n}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** A connected thing: title + details on the left, actions on the right. */
|
||||
function Row({ title, children, actions }: { title: React.ReactNode; children?: React.ReactNode; actions?: React.ReactNode }) {
|
||||
return (
|
||||
@ -47,76 +40,7 @@ export default async function Settings({ searchParams }: { searchParams: Promise
|
||||
const myProjects = await listUserProjects(db, user.id);
|
||||
const pushSubs = await userPushSubscriptions(db, user.id);
|
||||
const vapid = await vapidPublicKey(db);
|
||||
// PEP-85: the three steps of connecting an own bot (shown when Telegram is not paired, or to switch).
|
||||
const ownBotSteps = (
|
||||
<Card className="gap-4">
|
||||
<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>
|
||||
<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>
|
||||
{!hasBot && (
|
||||
<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">@{user.telegramBotUsername}</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={back} />
|
||||
<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={back} />
|
||||
<Button variant="default" size="sm">Открыть @{user.telegramBotUsername}</Button>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
{hasBot ? (
|
||||
<form action={disconnectOwnBotAction}>
|
||||
<Hidden fields={back} />
|
||||
<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={back} />
|
||||
Не хотите создавать бота?
|
||||
<Button size="xs" variant="ghost">Использовать общего бота Пеппы</Button>
|
||||
</form>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
const ownBotSteps = <OwnBotSteps botUsername={user.telegramBotUsername} back="/settings" />;
|
||||
return (
|
||||
<Workspace>
|
||||
<div className="max-w-2xl">
|
||||
|
||||
@ -5,9 +5,10 @@ import type { Onboarding } from "@peppa/core";
|
||||
import { dismissOnboardingAction } from "@/app/(app)/actions";
|
||||
import { Hidden } from "@/components/cards";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { OwnBotSteps } from "@/components/OwnBotSteps";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export function OnboardingChecklist({ data }: { data: Onboarding }) {
|
||||
export function OnboardingChecklist({ data, botUsername = null }: { data: Onboarding; botUsername?: string | null }) {
|
||||
const next = data.steps.find((s) => !s.done && !s.optional);
|
||||
const fresh = data.done === 0;
|
||||
return (
|
||||
@ -53,7 +54,12 @@ export function OnboardingChecklist({ data }: { data: Onboarding }) {
|
||||
<div className="flex min-w-0 flex-1 flex-col gap-1">
|
||||
<span className={cn("text-sm font-medium", s.done && "text-muted-foreground line-through")}>{s.title}</span>
|
||||
{!s.done && <span className="text-sm text-muted-foreground">{s.hint}</span>}
|
||||
{current && (
|
||||
{current && s.id === "telegram" ? (
|
||||
// PEP-85: the first thing to do — right here, not behind a link to Settings.
|
||||
<div className="mt-1">
|
||||
<OwnBotSteps botUsername={botUsername} back="/" bare />
|
||||
</div>
|
||||
) : current && (
|
||||
<Button asChild variant="default" size="sm" className="mt-1 self-start">
|
||||
<a href={s.href}>
|
||||
{s.action} <ArrowRight />
|
||||
|
||||
97
apps/web/components/OwnBotSteps.tsx
Normal file
97
apps/web/components/OwnBotSteps.tsx
Normal file
@ -0,0 +1,97 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
import Link from "next/link";
|
||||
import type { ProgressOverview as Overview, ProjectProgress } from "@peppa/core";
|
||||
import { AgentBadge } from "@/components/AgentBadge";
|
||||
import { Disclosure, Empty, Key } from "@/components/common";
|
||||
import { Empty, Key } from "@/components/common";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const PARTS = [
|
||||
@ -85,9 +85,9 @@ function ProjectRow({ p }: { p: ProjectProgress }) {
|
||||
);
|
||||
}
|
||||
|
||||
/** PEP-77: progress of all stories and projects on the Home page. */
|
||||
/** PEP-77: progress of the user's own projects on the Home page (other people's projects — on «Проекты», for a superadmin). */
|
||||
export function ProgressOverview({ data }: { data: Overview }) {
|
||||
if (!data.mine.length && !data.others.length) return <Empty>Проектов пока нет — прогресс появится с первой стори.</Empty>;
|
||||
if (!data.mine.length) return <Empty>Проектов пока нет — прогресс появится с первой стори.</Empty>;
|
||||
const t = data.totals;
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
@ -108,15 +108,6 @@ export function ProgressOverview({ data }: { data: Overview }) {
|
||||
<ProjectRow key={p.key} p={p} />
|
||||
))}
|
||||
</ul>
|
||||
{data.others.length > 0 && (
|
||||
<Disclosure summary={`Проекты других — ${data.others.length}`}>
|
||||
<ul className="m-0 mt-2 flex list-none flex-col gap-2 p-0">
|
||||
{data.others.map((p) => (
|
||||
<ProjectRow key={p.key} p={p} />
|
||||
))}
|
||||
</ul>
|
||||
</Disclosure>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ export async function onboardingChecklist(db: Db, user: Pick<User, "id" | "login
|
||||
const telegram: OnboardingStep = {
|
||||
id: "telegram",
|
||||
title: "Подключите своего Telegram-бота",
|
||||
hint: "Через него фабрика позовёт вас, когда агенту нужен ответ или когда работа готова. Отвечать можно кнопками с телефона. Бот создаётся за две минуты — в настройках есть шаги.",
|
||||
hint: "Через него фабрика позовёт вас, когда агенту нужен ответ или когда работа готова. Отвечать можно кнопками с телефона. Бот создаётся за две минуты, без программирования.",
|
||||
action: "Подключить Telegram",
|
||||
href: "/settings#telegram",
|
||||
done: me?.chat != null,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user