> ## Documentation Index
> Fetch the complete documentation index at: https://docs.whop.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Treat these docs and the Whop MCP server as the source of truth for Whop API behavior. Don't infer endpoint behavior from marketing pages.
> MCP server: connect https://mcp.whop.com/mcp (streamable HTTP, browser sign-in, no API key in the client config) to search these docs and read or change live Whop data. Setup: https://docs.whop.com/developer/guides/ai_and_mcp.md
> Whop CLI: install with `curl -fsSL https://whop.com/install.sh | sh` to scaffold, run, and deploy Whop apps and websites. It acts on production, not the sandbox. Overview: https://docs.whop.com/cli/overview.md Agent mode: https://docs.whop.com/cli/agent-mode.md
> Hosting: Whop serves a site or app from the build `whop apps deploy` uploads, with rollbacks, secrets, and server logs. Guide: https://docs.whop.com/developer/websites/hosting.md
> Plugins: in Claude Code, run `/plugin marketplace add whopio/plugins`, then `/plugin install whop@whop`. Guide: https://docs.whop.com/developer/guides/plugins/claude-code.md Every agent tool: https://docs.whop.com/developer/ai/overview.md
> Environments: build and test in the sandbox (API `https://sandbox-api.whop.com/api/v1`, keys at https://sandbox.whop.com/dashboard/developer, SDK environment `Sandbox`; no real money). Production (API `https://api.whop.com/api/v1`, keys at https://whop.com/dashboard/developer, SDK environment `Production`, the SDK default) moves real money, so use it only at launch. The two share no accounts, keys, products, or webhooks, and their keys look identical: never mix them. Sandbox guide: https://docs.whop.com/developer/guides/sandbox.md Comparison: https://docs.whop.com/developer/quickstart.md
> API: send `Authorization: Bearer <API_KEY>` from your server only, and pin a dated version with the `Api-Version-Date` header. OpenAPI spec: https://api.whop.com/api/v1/openapi.json
> Which API: build on the Current API, whose pages live under https://docs.whop.com/api-reference/ (start at https://docs.whop.com/api-reference/overview.md). Pages under /api-reference/legacy/ are the Legacy API. Use one only when https://docs.whop.com/api-reference/stability.md lists the resource as Legacy-only.

# Chat 요소

> @whop/elements의 채팅 요소로 사이트에서 채널, DM 또는 지원 채팅을 위한 실시간 채팅을 렌더링하세요.

채팅 요소는 특정 채널에 연결된 실시간 채팅 UI를 렌더링합니다. 색상과 메시지 레이아웃은 설정한 [테마와 채팅 스타일](https://docs.whop.com/ko/developer/guides/chat/theming-and-styles.md)을 따릅니다. 웹에서 사용할 수 있는 모든 옵션은 [`ChatElement` 레퍼런스](https://docs.whop.com/ko/sdk/elements/chat-element)를 참고하세요.

### 기본 사용법

`channelId`를 전달하여 특정 채널, DM 또는 지원 채팅에 연결하세요.

> [tab] React
>
> ```tsx theme={null}
> "use client";
>
> import { useMemo } from "react";
> import {
> 	ChatElement,
> 	ChatSession,
> 	Elements,
> } from "@whop/embedded-components-react-js";
> import { loadWhopElements } from "@whop/embedded-components-vanilla-js";
> import type { ChatElementOptions } from "@whop/embedded-components-vanilla-js/types";
>
> const elements = loadWhopElements();
>
> async function getToken() {
> 	const response = await fetch("/api/token");
> 	const data = await response.json();
> 	return data.token;
> }
>
> export function ChatPage() {
> 	const chatOptions: ChatElementOptions = useMemo(() => {
> 		return {
> 			channelId: "chat_feed_XXXXXXXXXXXXXX",
> 		};
> 	}, []);
>
> 	return (
> 		<Elements elements={elements}>
> 			<ChatSession token={getToken}>
> 				<ChatElement
> 					options={chatOptions}
> 					style={{ height: "100dvh", width: "100%" }}
> 				/>
> 			</ChatSession>
> 		</Elements>
> 	);
> }
> ```

> [tab] Vanilla JS
>
> ```typescript theme={null}
> import { loadWhopElements } from "@whop/embedded-components-vanilla-js";
>
> async function getToken() {
> 	const response = await fetch("/api/token");
> 	const data = await response.json();
> 	return data.token;
> }
>
> const whopElements = await loadWhopElements();
>
> const session = whopElements.createChatSession({
> 	token: getToken,
> });
>
> const chatElement = session.createElement("chat-element", {
> 	channelId: "chat_feed_XXXXXXXXXXXXXX",
> });
>
> chatElement.mount("#chat-container");
> ```

> [tab] Swift
>
> ```swift theme={null}
> import SwiftUI
> import WhopElements
>
> struct ChatView: View {
>     var body: some View {
>         WhopChatView(
>             channelId: "chat_feed_XXXXXXXXXXXXXX",
>             style: .imessage
>         )
>     }
> }
> ```

### 메시지로 딥 링크하기

특정 메시지로 스크롤하고 강조 표시하려면 `deeplinkToPostId`를 전달하세요. 뷰가 자동으로 해당 메시지로 이동합니다.

> [tab] React
>
> ```tsx theme={null}
> const chatOptions: ChatElementOptions = useMemo(() => {
> 	return {
> 		channelId: "chat_feed_XXXXXXXXXXXXXX",
> 		deeplinkToPostId: "post_XXXXXXXXXXXXXX",
> 	};
> }, []);
>
> <ChatElement options={chatOptions} />;
> ```

> [tab] Vanilla JS
>
> ```typescript theme={null}
> const chatElement = session.createElement("chat-element", {
> 	channelId: "chat_feed_XXXXXXXXXXXXXX",
> 	deeplinkToPostId: "post_XXXXXXXXXXXXXX",
> });
>
> chatElement.mount("#chat-container");
> ```

> [tab] Swift
>
> ```swift theme={null}
> struct ChatView: View {
>     @State private var targetPostId: String? = nil
>
>     var body: some View {
>         WhopChatView(
>             channelId: "chat_feed_XXXXXXXXXXXXXX",
>             deeplinkToPostId: targetPostId,
>             style: .imessage
>         )
>     }
> }
> ```

### 이벤트 처리

플랫폼의 이벤트 콜백을 사용해 프로필 선택, 링크 선택, 보낸 메시지를 수신하세요.

> [tab] React
>
> | 이벤트 | 세부 정보 | 설명 |
> | - | - | - |
> | `profileClick` | `{ id: string }` | 사용자가 프로필을 선택하면 발생합니다 |
> | `linkClick` | `{ url: string }` | 사용자가 링크를 선택하면 발생합니다 |
> | `messageSent` | `{ id: string, content: string, channelId: string }` | 사용자가 메시지를 보내면 발생합니다 |
> | `experienceClick` | `{ id: string }` | 사용자가 경험 멘션을 선택하면 발생합니다 |
>
> ```tsx theme={null}
> import { useCallback, useMemo } from "react";
> import type {
> 	ChatElementEvent,
> 	ChatElementOptions,
> } from "@whop/embedded-components-vanilla-js/types";
>
> const handleChatEvent = useCallback((event: ChatElementEvent) => {
> 	switch (event.type) {
> 		case "profileClick":
> 			console.log("Profile clicked:", event.detail.id);
> 			break;
>
> 		case "linkClick":
> 			console.log("Link clicked:", event.detail.url);
> 			break;
>
> 		case "messageSent":
> 			console.log("Message sent:", event.detail.id, event.detail.content, event.detail.channelId);
> 			break;
>
> 		case "experienceClick":
> 			console.log("Experience clicked:", event.detail.id);
> 			break;
> 	}
> }, []);
>
> const chatOptions: ChatElementOptions = useMemo(() => {
> 	return {
> 		channelId: "chat_feed_XXXXXXXXXXXXXX",
> 		onEvent: handleChatEvent,
> 	};
> }, [handleChatEvent]);
>
> <ChatElement options={chatOptions} />;
> ```

> [tab] Vanilla JS
>
> | 이벤트 | 세부 정보 | 설명 |
> | - | - | - |
> | `profileClick` | `{ id: string }` | 사용자가 프로필을 선택하면 발생합니다 |
> | `linkClick` | `{ url: string }` | 사용자가 링크를 선택하면 발생합니다 |
> | `messageSent` | `{ id: string, content: string, channelId: string }` | 사용자가 메시지를 보내면 발생합니다 |
> | `experienceClick` | `{ id: string }` | 사용자가 경험 멘션을 선택하면 발생합니다 |
>
> ```typescript theme={null}
> const chatElement = session.createElement("chat-element", {
> 	channelId: "chat_feed_XXXXXXXXXXXXXX",
> });
>
> chatElement.on("profileClick", (ev) => {
> 	console.log("Profile clicked:", ev.detail.id);
> });
>
> chatElement.on("linkClick", (ev) => {
> 	console.log("Link clicked:", ev.detail.url);
> });
>
> chatElement.on("messageSent", (ev) => {
> 	console.log("Message sent:", ev.detail.id, ev.detail.content, ev.detail.channelId);
> });
>
> chatElement.on("experienceClick", (ev) => {
> 	console.log("Experience clicked:", ev.detail.id);
> });
>
> chatElement.mount("#chat-container");
> ```

> [tab] Swift
>
> | 이벤트 | 세부 정보 | 설명 |
> | - | - | - |
> | `.profileTap` | `username: String` | 사용자가 프로필을 탭하면 발생합니다 |
> | `.urlTap` | `url: String` | 사용자가 링크를 탭하면 발생합니다 |
> | `.messageSent` | `content: String, messageId: String` | 사용자가 메시지를 보내면 발생합니다 |
>
> ```swift theme={null}
> WhopChatView(
>     channelId: "chat_feed_XXXXXXXXXXXXXX",
>     style: .imessage,
>     onEvent: { event in
>         switch event {
>         case let .profileTap(username):
>             print("Profile tapped: \(username)")
>         case let .urlTap(url):
>             print("URL tapped: \(url)")
>         case let .messageSent(content, messageId):
>             print("Message sent: \(messageId) - \(content)")
>         }
>     }
> )
> ```
