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

# Sohbet Oturumu Oluşturun

> Eski ChatSession için referans. Yeni entegrasyonlar için @whop/elements içindeki Chat grubunu kullanın.

## Genel bakış

Kimlik doğrulamayı yönetir ve sohbet öğeleri oluşturur.

## Örnekler

### Temel kullanım

```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");
});
```

### Öğe oluşturma

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

## Seçenekler

| Özellik | Tür | Zorunlu | Varsayılan | Açıklama |
| - | - | - | - | - |
| `token` | `Token \| GetToken` | Evet | - | Oturum için kullanılacak token. Bir fonksiyon sağlanırsa, token'ı almak için çağrılır ve beklenir. Bir fonksiyon sağlandığında token, süresi dolmadan önce otomatik olarak yenilenir. Bir string sağlanırsa token olarak kullanılır ve otomatik olarak yenilenmez. Ancak yeni bir token ile 'updateOptions' çağırarak token'ı çalışma zamanında güncelleyebilirsiniz. |

## Olaylar

ChatSession tarafından yayılan olaylar.

Bu olayları `on()` metodunu kullanarak dinleyin.

### `optionsUpdated`

Oturum seçenekleri `updateOptions()` aracılığıyla güncellendiğinde yayılır.

**Geri çağırma imzası:** (options: `ExpandedChatSessionOptions`) => void

### `tokenRefreshed`

Kimlik doğrulama token'ı yenilendiğinde yayılır.

**Geri çağırma imzası:** (token: `string`) => void

### `tokenRefreshError`

Token yenileme başarısız olduğunda yayılır.

**Geri çağırma imzası:** (error: `unknown`) => void

### `error`

Oturum işlemi sırasında bir hata oluştuğunda yayılır.

**Geri çağırma imzası:** (error: `unknown`) => void

### `ready`

Oturum hazır olduğunda ve kimliği doğrulandığında yayılır.

**Geri çağırma imzası:** (`void`) => void

## Metodlar

### `createElement(type, options)`

Yeni bir öğe örneği oluşturur.

| Parametre | Tür | Açıklama |
| - | - | - |
| `type` | T \| \{ type: T; } | Öğe türü (ör. "chat-element") |
| `options` | ChatSessionElements\[T]\[0] | Öğeye özgü yapılandırma seçenekleri |

**Döndürür:** `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)`

Başlatmadan sonra oturum seçeneklerini günceller.

Değişiklikler tüm etkin öğelere yayılır.

| Parametre | Tür | Açıklama |
| - | - | - |
| `options` | Partial\<ChatSessionOptions> | Güncellenecek değerleri içeren kısmi seçenekler nesnesi |

### `destroy()`

Oturumu yok eder ve yerleştirilmiş tüm öğeleri temizler.

Kaynakları serbest bırakmak için oturuma artık ihtiyacınız olmadığında bunu çağırın.

### Modal Metodları

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

Arama öğesini bir modal katmanında gösterir.

Varsayılan olarak modal, tamamlandığında (`onResultClick`) veya kapatıldığında (`onClose`) otomatik olarak kapanır.
Otomatik kapanmayı önlemek için bir geri çağırmada `ev.preventDefault()` çağırın.

| Parametre | Tür | Açıklama |
| - | - | - |
| `options` | [`SearchElementOptions`](https://docs.whop.com/tr/sdk/elements/search-element#searchelementoptions) \| ((modal: ModalContainer) => [`SearchElementOptions`](https://docs.whop.com/tr/sdk/elements/search-element#searchelementoptions)) | Öğe seçenekleri veya modal kapsayıcısını alan bir geri çağırma |
| `force` | Force \| undefined | - |

**Döndürür:** `Force extends true ? ModalContainer : ModalContainer | undefined`
