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

> Muestra un chat en tiempo real para un canal, un MD o un chat de soporte en tu sitio con el chat element de @whop/elements.

El chat element muestra una interfaz de chat en tiempo real conectada a un canal concreto. Sus colores y la disposición de los mensajes siguen el [tema y el estilo de chat](https://docs.whop.com/es/developer/guides/chat/theming-and-styles.md) que configures. Para ver todas las opciones que acepta en la web, consulta la [referencia de `ChatElement`](https://docs.whop.com/es/sdk/elements/chat-element).

### Uso básico

Pasa un `channelId` para conectarte a un canal, un MD o un chat de soporte concreto.

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

### Enlaces directos a mensajes

Para desplazarte hasta un mensaje concreto y resaltarlo, pasa `deeplinkToPostId`. La vista navegará automáticamente hasta ese mensaje.

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

### Gestión de eventos

Usa la función de callback de eventos de tu plataforma para escuchar las selecciones de perfiles, las selecciones de enlaces y los mensajes enviados.

> [tab] React
>
> | Evento | Detalle | Descripción |
> | - | - | - |
> | `profileClick` | `{ id: string }` | Se emite cuando el usuario selecciona un perfil |
> | `linkClick` | `{ url: string }` | Se emite cuando el usuario selecciona un enlace |
> | `messageSent` | `{ id: string, content: string, channelId: string }` | Se emite cuando el usuario envía un mensaje |
> | `experienceClick` | `{ id: string }` | Se emite cuando el usuario selecciona una mención de experiencia |
>
> ```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
>
> | Evento | Detalle | Descripción |
> | - | - | - |
> | `profileClick` | `{ id: string }` | Se emite cuando el usuario selecciona un perfil |
> | `linkClick` | `{ url: string }` | Se emite cuando el usuario selecciona un enlace |
> | `messageSent` | `{ id: string, content: string, channelId: string }` | Se emite cuando el usuario envía un mensaje |
> | `experienceClick` | `{ id: string }` | Se emite cuando el usuario selecciona una mención de experiencia |
>
> ```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
>
> | Evento | Detalle | Descripción |
> | - | - | - |
> | `.profileTap` | `username: String` | Se emite cuando el usuario toca un perfil |
> | `.urlTap` | `url: String` | Se emite cuando el usuario toca un enlace |
> | `.messageSent` | `content: String, messageId: String` | Se emite cuando el usuario envía un mensaje |
>
> ```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

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