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

# Indlejr kanallisteelementet

> Vis en brugers samtaler med direkte beskeder ved siden af chat-elementet, og åbn den, brugeren vælger.

DM-listeelementet viser en navigerbar liste over brugerens samtaler med direkte beskeder. Det bruger samme [tema](https://docs.whop.com/da/developer/guides/chat/theming-and-styles.md) som resten af dine chatelementer. Se [`DmsListElement`-referencen](https://docs.whop.com/da/sdk/elements/dms-list-element) for alle de indstillinger, det tager på web.

### Grundlæggende brug

Mount DM-listen, og lyt efter hændelser for valg af kanal for at navigere brugerne ind i en samtale.

> [tab] React
>
> ```tsx theme={null}
> "use client";
>
> import { useCallback, useMemo, useState } from "react";
> import {
> 	ChatSession,
> 	DmsListElement,
> 	Elements,
> } from "@whop/embedded-components-react-js";
> import { loadWhopElements } from "@whop/embedded-components-vanilla-js";
> import type {
> 	DmsListElementEvent,
> 	DmsListElementOptions,
> } 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 MessagesPage() {
> 	const [channelId, setChannelId] = useState<string>();
>
> 	const handleDmsEvent = useCallback((event: DmsListElementEvent) => {
> 		switch (event.type) {
> 			case "channelSelected":
> 				setChannelId(event.detail.id);
> 				break;
> 		}
> 	}, []);
>
> 	const dmsOptions: DmsListElementOptions = useMemo(() => {
> 		return {
> 			selectedChannel: channelId,
> 			onEvent: handleDmsEvent,
> 		};
> 	}, [channelId, handleDmsEvent]);
>
> 	return (
> 		<Elements elements={elements}>
> 			<ChatSession token={getToken}>
> 				<DmsListElement options={dmsOptions} />
> 			</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 dmsListElement = session.createElement("dms-list-element", {});
>
> dmsListElement.on("channelSelected", (ev) => {
> 	console.log("Channel selected:", ev.detail.id);
> });
>
> dmsListElement.mount("#dms-list-container");
> ```

> [tab] Swift
>
> ```swift theme={null}
> struct MessagesView: View {
>     @State private var selectedChannel: DMChannel?
>
>     var body: some View {
>         WhopDMsListView(
>             onEvent: { event in
>                 switch event {
>                 case let .channelSelected(channel):
>                     selectedChannel = channel
>                 }
>             }
>         )
>         .navigationDestination(item: $selectedChannel) { channel in
>             WhopChatView(
>                 channelId: channel.id,
>                 style: .imessage
>             )
>             .navigationBarTitleDisplayMode(.inline)
>             .navigationTitle(channel.name)
>         }
>     }
> }
> ```

### Afgrænsning til en konto

Filtrer DM-listen, så den kun viser samtaler, der tilhører en bestemt konto, ved at angive et `companyId`. Hvis du vil oprette en DM fra din server, skal du kalde [Create Channel](https://docs.whop.com/da/api-reference/channels/create-channel.md) med `kind` sat til `private`. Angiv samme konto-ID som `account_id`, så DM'en vises på den afgrænsede liste.

> [tab] React
>
> ```tsx theme={null}
> const dmsOptions: DmsListElementOptions = useMemo(() => {
> 	return {
> 		companyId: "biz_xxxx",
> 		selectedChannel: channelId,
> 		onEvent: handleDmsEvent,
> 	};
> }, [channelId, handleDmsEvent]);
>
> return (
> 	<Elements elements={elements}>
> 		<ChatSession token={getToken}>
> 			<DmsListElement options={dmsOptions} />
> 		</ChatSession>
> 	</Elements>
> );
> ```

> [tab] Vanilla JS
>
> ```typescript theme={null}
> const dmsListElement = session.createElement("dms-list-element", {
> 	companyId: "biz_xxxx",
> });
>
> dmsListElement.mount("#dms-list-container");
> ```

> [tab] Swift
>
> ```swift theme={null}
> WhopDMsListView(
>     companyId: "biz_xxxx",
>     onEvent: { event in
>         switch event {
>         case let .channelSelected(channel):
>             selectedChannel = channel
>         }
>     }
> )
> ```

### Håndtering af hændelser

Lyt efter valg af kanal for at åbne den tilsvarende chatvisning.

> [tab] React
>
> | Hændelse | Detalje | Beskrivelse |
> | - | - | - |
> | `channelSelected` | `{ id: string }` | Udsendes, når brugeren vælger en kanal |
>
> ```tsx theme={null}
> const handleDmsEvent = useCallback((event: DmsListElementEvent) => {
> 	switch (event.type) {
> 		case "channelSelected":
> 			setChannelId(event.detail.id);
> 			break;
> 	}
> }, []);
> ```

> [tab] Vanilla JS
>
> | Hændelse | Detalje | Beskrivelse |
> | - | - | - |
> | `channelSelected` | `{ id: string }` | Udsendes, når brugeren vælger en kanal |
>
> ```typescript theme={null}
> dmsListElement.on("channelSelected", (ev) => {
> 	console.log("Channel selected:", ev.detail.id);
> });
> ```

> [tab] Swift
>
> | Hændelse | Detalje | Beskrivelse |
> | - | - | - |
> | `.channelSelected` | `channel: DMChannel` | Udsendes, når brugeren trykker på en kanal |
>
> ```swift theme={null}
> WhopDMsListView(
>     onEvent: { event in
>         switch event {
>         case let .channelSelected(channel):
>             selectedChannel = channel
>         }
>     }
> )
> .navigationDestination(item: $selectedChannel) { channel in
>     WhopChatView(
>         channelId: channel.id,
>         style: .imessage
>     )
>     .navigationBarTitleDisplayMode(.inline)
>     .navigationTitle(channel.name)
> }
> ```


## Related topics

- [Indlejr en checkout](https://docs.whop.com/da/developer/guides/embed-checkout.md)
- [Kanaler i indlejret chat](https://docs.whop.com/da/developer/guides/chat/channels.md)
- [Direkte beskeder i indlejret chat](https://docs.whop.com/da/developer/guides/chat/direct-messages.md)
