diff --git a/frontend/src/components/pages/ProfilePage.tsx b/frontend/src/components/pages/ProfilePage.tsx index 68794f1..3bd71db 100644 --- a/frontend/src/components/pages/ProfilePage.tsx +++ b/frontend/src/components/pages/ProfilePage.tsx @@ -1,10 +1,253 @@ -import { PlaceholderPage } from "./PlaceholderPage"; +"use client"; + +import { + Braces, + CheckCircle2, + Eye, + EyeOff, + Globe2, + Loader2, + LockKeyhole, + Send, + Webhook, +} from "lucide-react"; +import { useState } from "react"; + +import { SectionCard } from "@/components/editor/section-card"; +import { ListPageLayout } from "@/components/layout/list-page-layout"; +import { Badge } from "@/components/ui/badge"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Switch } from "@/components/ui/switch"; + +type TestStatus = "idle" | "loading" | "success" | "error"; + +function mockWebhookPayload() { + return { + id: "evt_mock_001", + event: "call.analysis.completed", + timestamp: new Date().toISOString(), + data: { + conversationId: "conv_mock_001", + assistantId: "asst_mock_001", + analysis: { + customer_intent: "high", + need_follow_up: true, + }, + }, + }; +} + +function isHttpsUrl(value: string): boolean { + try { + return new URL(value).protocol === "https:"; + } catch { + return false; + } +} export function ProfilePage() { + const [enabled, setEnabled] = useState(true); + const [url, setUrl] = useState(""); + const [secret, setSecret] = useState(""); + const [secretVisible, setSecretVisible] = useState(false); + const [testStatus, setTestStatus] = useState("idle"); + const [testMessage, setTestMessage] = useState(""); + const [payload, setPayload] = useState | null>(null); + + async function sendTestEvent() { + if (!isHttpsUrl(url.trim())) { + setTestStatus("error"); + setTestMessage("请填写完整的 HTTPS Webhook URL。测试不会发起网络请求。"); + setPayload(null); + return; + } + + setTestStatus("loading"); + setTestMessage(""); + setPayload(null); + await new Promise((resolve) => window.setTimeout(resolve, 700)); + setPayload(mockWebhookPayload()); + setTestStatus("success"); + setTestMessage("已在浏览器中生成测试事件,未向目标地址发送请求。"); + } + return ( - + description="管理站点级配置。Webhook 将统一接收所有助手的通话分析完成事件。" + className="max-w-[1120px]" + > +
+ + + } + title="通话分析 Webhook" + description="站点级事件出口;后端接入后将在分析完成时执行 HTTP POST" + className="self-start" + > +
+
+
+ + 分析完成事件 + + + 前端预览 + +
+

+ 事件类型:call.analysis.completed +

+
+ +
+ +
+ + + +
+ +
+ + + 等待后端设置 API +
+ + {testMessage && ( +
+ {testStatus === "success" && ( + + )} + {testMessage} +
+ )} + + {payload && ( +
+
+ + + Mock payload + +
+
+                {JSON.stringify(payload, null, 2)}
+              
+
+ )} +
+
+ ); }