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

> Vis en realtidschat for en kanal, en DM eller en supportchat på dit website med chat-elementet fra @whop/elements.

Chat-elementet viser en chat-brugerflade i realtid, der er forbundet med en bestemt kanal. Dets farver og beskedlayout følger det [tema og den chatstil](https://docs.whop.com/da/developer/guides/chat/theming-and-styles.md), du angiver. Se [`ChatElement`-referencen](https://docs.whop.com/da/sdk/elements/chat-element) for alle de indstillinger, det tager på web.

### Grundlæggende brug

Angiv et `channelId` for at forbinde til en bestemt kanal, DM eller 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
>         )
>     }
> }
> ```

### Direkte links til beskeder

Angiv `deeplinkToPostId` for at rulle til og fremhæve en bestemt besked. Visningen navigerer automatisk til den besked.

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

### Håndtering af hændelser

Brug din platforms hændelses-callback til at lytte efter valg af profiler, valg af links og sendte beskeder.

> [tab] React
>
> | Hændelse | Detalje | Beskrivelse |
> | - | - | - |
> | `profileClick` | `{ id: string }` | Udsendes, når brugeren vælger en profil |
> | `linkClick` | `{ url: string }` | Udsendes, når brugeren vælger et link |
> | `messageSent` | `{ id: string, content: string, channelId: string }` | Udsendes, når brugeren sender en besked |
> | `experienceClick` | `{ id: string }` | Udsendes, når brugeren vælger en omtale af en experience |
>
> ```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
>
> | Hændelse | Detalje | Beskrivelse |
> | - | - | - |
> | `profileClick` | `{ id: string }` | Udsendes, når brugeren vælger en profil |
> | `linkClick` | `{ url: string }` | Udsendes, når brugeren vælger et link |
> | `messageSent` | `{ id: string, content: string, channelId: string }` | Udsendes, når brugeren sender en besked |
> | `experienceClick` | `{ id: string }` | Udsendes, når brugeren vælger en omtale af en experience |
>
> ```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
>
> | Hændelse | Detalje | Beskrivelse |
> | - | - | - |
> | `.profileTap` | `username: String` | Udsendes, når brugeren trykker på en profil |
> | `.urlTap` | `url: String` | Udsendes, når brugeren trykker på et link |
> | `.messageSent` | `content: String, messageId: String` | Udsendes, når brugeren sender en besked |
>
> ```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)")
>         }
>     }
> )
> ```
