> ## 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-element

> Geef op je site een realtime chat weer voor een kanaal, DM of supportchat met het chat-element uit @whop/elements.

Het chat-element geeft een realtime chat-UI weer die is verbonden met een specifiek kanaal. De kleuren en berichtindeling volgen het [thema en de chatstijl](https://docs.whop.com/nl/developer/guides/chat/theming-and-styles.md) die je instelt. Zie de [`ChatElement`-referentie](https://docs.whop.com/nl/sdk/elements/chat-element) voor alle opties op het web.

### Basisgebruik

Geef een `channelId` mee om verbinding te maken met een specifiek kanaal, een DM of een supportchat.

> [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
>         )
>     }
> }
> ```

### Deeplinks naar berichten

Geef `deeplinkToPostId` mee om naar een specifiek bericht te scrollen en het te markeren. De weergave navigeert automatisch naar dat bericht.

> [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
>         )
>     }
> }
> ```

### Events afhandelen

Gebruik de event-callback van je platform om te luisteren naar geselecteerde profielen, geselecteerde links en verstuurde berichten.

> [tab] React
>
> | Event | Detail | Beschrijving |
> | - | - | - |
> | `profileClick` | `{ id: string }` | Verstuurd wanneer de gebruiker een profiel selecteert |
> | `linkClick` | `{ url: string }` | Verstuurd wanneer de gebruiker een link selecteert |
> | `messageSent` | `{ id: string, content: string, channelId: string }` | Verstuurd wanneer de gebruiker een bericht verstuurt |
> | `experienceClick` | `{ id: string }` | Verstuurd wanneer de gebruiker een vermelding van een experience selecteert |
>
> ```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
>
> | Event | Detail | Beschrijving |
> | - | - | - |
> | `profileClick` | `{ id: string }` | Verstuurd wanneer de gebruiker een profiel selecteert |
> | `linkClick` | `{ url: string }` | Verstuurd wanneer de gebruiker een link selecteert |
> | `messageSent` | `{ id: string, content: string, channelId: string }` | Verstuurd wanneer de gebruiker een bericht verstuurt |
> | `experienceClick` | `{ id: string }` | Verstuurd wanneer de gebruiker een vermelding van een experience selecteert |
>
> ```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
>
> | Event | Detail | Beschrijving |
> | - | - | - |
> | `.profileTap` | `username: String` | Verstuurd wanneer de gebruiker op een profiel tikt |
> | `.urlTap` | `url: String` | Verstuurd wanneer de gebruiker op een link tikt |
> | `.messageSent` | `content: String, messageId: String` | Verstuurd wanneer de gebruiker een bericht verstuurt |
>
> ```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)")
>         }
>     }
> )
> ```


## Related topics

- [ChatElement](https://docs.whop.com/nl/elements/latest/chat/chat.md)
- [ChatElement (Legacy)](https://docs.whop.com/nl/sdk/elements/chat-element.md)
- [Chat](https://docs.whop.com/nl/elements/latest/chat/overview.md)
