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

# Een chatsessie maken

> Referentie voor de legacy ChatSession. Gebruik voor nieuwe integraties de Chat-groep in @whop/elements.

## Overzicht

Beheert de authenticatie en maakt chatelementen aan.

## Voorbeelden

### Basisgebruik

```typescript theme={null}
const session = whopElements.createChatSession({
  token: async () => {
    const response = await fetch("/api/token");
    const data = await response.json();
    return data.token;
  },
});

session.on("ready", () => {
  console.log("Session is ready");
});
```

### Elementen aanmaken

```typescript theme={null}
const chatElement = session.createElement("chat-element", {
  channelId: "feed_XXXXXXXXXXXXXX",
});
chatElement.mount("#chat-container");
```

## Opties

| Eigenschap | Type | Verplicht | Standaard | Beschrijving |
| - | - | - | - | - |
| `token` | `Token \| GetToken` | Ja | - | Het token dat voor de sessie wordt gebruikt. Als er een functie wordt meegegeven, wordt deze aangeroepen en afgewacht om het token op te halen. Wanneer er een functie wordt meegegeven, wordt het token automatisch vernieuwd voordat het verloopt. Als er een string wordt meegegeven, wordt deze als token gebruikt en niet automatisch vernieuwd. Je kunt het token tijdens runtime echter bijwerken door 'updateOptions' aan te roepen met een nieuw token. |

## Events

Events die door de ChatSession worden uitgezonden.

Luister naar deze events met de methode `on()`.

### `optionsUpdated`

Wordt uitgezonden wanneer de sessieopties worden bijgewerkt via `updateOptions()`.

**Callbacksignatuur:** (options: `ExpandedChatSessionOptions`) => void

### `tokenRefreshed`

Wordt uitgezonden wanneer het authenticatietoken wordt vernieuwd.

**Callbacksignatuur:** (token: `string`) => void

### `tokenRefreshError`

Wordt uitgezonden wanneer het vernieuwen van het token mislukt.

**Callbacksignatuur:** (error: `unknown`) => void

### `error`

Wordt uitgezonden wanneer er een fout optreedt tijdens de werking van de sessie.

**Callbacksignatuur:** (error: `unknown`) => void

### `ready`

Wordt uitgezonden wanneer de sessie gereed en geauthenticeerd is.

**Callbacksignatuur:** (`void`) => void

## Methoden

### `createElement(type, options)`

Maak een nieuwe elementinstantie aan.

| Parameter | Type | Beschrijving |
| - | - | - |
| `type` | T \| \{ type: T; } | Het elementtype (bijv. "chat-element") |
| `options` | ChatSessionElements\[T]\[0] | Elementspecifieke configuratieopties |

**Retourneert:** `ChatSessionElements[T][1]`

```typescript theme={null}
const element = session.createElement("chat-element", {
  channelId: "feed_XXXXXXXXXXXXXX",
  onReady: () => console.log("Element ready"),
});
element.mount("#chat-container");
```

### `updateOptions(options)`

Werk de sessieopties bij na de initialisatie.

Wijzigingen worden doorgevoerd in alle actieve elementen.

| Parameter | Type | Beschrijving |
| - | - | - |
| `options` | Partial\<ChatSessionOptions> | Gedeeltelijk optiesobject met de waarden die moeten worden bijgewerkt |

### `destroy()`

Vernietig de sessie en ruim alle gekoppelde elementen op.

Roep dit aan wanneer je de sessie niet meer nodig hebt, om resources vrij te maken.

### Modal-methoden

#### `showSearchModal(options, force)`

Toon het zoekelement in een modal-overlay.

Standaard sluit de modal automatisch bij voltooiing (`onResultClick`) of bij sluiten (`onClose`).
Roep `ev.preventDefault()` aan in een callback om automatisch sluiten te voorkomen.

| Parameter | Type | Beschrijving |
| - | - | - |
| `options` | [`SearchElementOptions`](https://docs.whop.com/nl/sdk/elements/search-element#searchelementoptions) \| ((modal: ModalContainer) => [`SearchElementOptions`](https://docs.whop.com/nl/sdk/elements/search-element#searchelementoptions)) | Elementopties of een callback die de modal-container ontvangt |
| `force` | Force \| undefined | - |

**Retourneert:** `Force extends true ? ModalContainer : ModalContainer | undefined`


## Related topics

- [Facturen](https://docs.whop.com/nl/developer/guides/invoices.md)
- [Aan de slag met Element Sessions](https://docs.whop.com/nl/sdk/elements/whop-elements.md)
- [Een verificatie bijwerken of verwijderen](https://docs.whop.com/nl/developer/verification/manage.md)
