UNPKG

@roottale/cms-mcp

Version:

RootTale CMS integration MCP server — bundled integration docs, Next.js example code, and public API lookup tools. Run with: npx @roottale/cms-mcp

55 lines (48 loc) 2.42 kB
// 상담문의 폼 → RootTale CRM. 블로그와 같은 API 키로 테넌트가 식별된다. // 클라이언트 폼에서 useActionState(submitContact, { status: "idle" })로 연결. "use server"; import { parseAttributionJson, submitInquiry } from "@roottale/cms-client/server"; export interface ContactState { status: "idle" | "success" | "error"; message?: string; errors?: Partial<Record<"name" | "phone" | "privacyConsent", string>>; } export async function submitContact( _prevState: ContactState, formData: FormData, ): Promise<ContactState> { const name = (formData.get("name") as string | null)?.trim() ?? ""; const phone = (formData.get("phone") as string | null)?.trim() ?? ""; const field = (formData.get("field") as string | null)?.trim() ?? ""; const message = (formData.get("message") as string | null)?.trim() ?? ""; const privacyConsent = formData.get("privacyConsent") !== null; // 유입 어트리뷰션 (선택) — 클라이언트 폼이 readAttribution() 값을 hidden // input(name="attribution")에 JSON 으로 실어 보내면 CRM 에 유입 경로가 표시된다. const attribution = parseAttributionJson(formData.get("attribution")); const errors: ContactState["errors"] = {}; if (!name) errors.name = "이름을 입력해주세요."; if (!phone || phone.length < 7) errors.phone = "연락처를 입력해주세요."; if (!privacyConsent) errors.privacyConsent = "개인정보 수집·이용에 동의해주세요."; if (Object.keys(errors).length > 0) { return { status: "error", message: "필수 항목을 입력해주세요.", errors }; } const result = await submitInquiry({ apiKey: process.env.ROOTTALE_API_KEY!, baseUrl: process.env.ROOTTALE_API_BASE, fields: { vertical: "consulting", // 사이트 업종에 맞게: consulting | medical | tax | legal contactName: name, businessName: name, // 사업체명 미수집 폼이면 이름으로 대체 email: `noemail-${Date.now()}@example.invalid`, // 이메일 미수집 폼 placeholder phone, consultationField: field || undefined, message: message || undefined, privacyConsent: true, // 사용자가 명시 동의한 경우에만 attribution, }, }); if (result.ok) { return { status: "success", message: "상담 문의가 접수되었습니다." }; } return { status: "error", message: result.message }; }