> For the complete documentation index, see [llms.txt](https://developer.konukcrm.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.konukcrm.com/rehberler/gercek-zamanli-olaylar-sse.md).

# Gerçek Zamanlı Olaylar (SSE)

Anlık ekranlar (canlı çağrı panosu, bekleyen kuyruk, gelen mesaj) için KonukCRM **Server-Sent Events** yayınlar.

|                  | SSE                      | Webhook                             |
| ---------------- | ------------------------ | ----------------------------------- |
| Yön              | Sunucu → açık istemci    | Sunucu → sizin sunucunuz            |
| Teslim garantisi | Bağlantı açıkken         | En az bir kez, tekrar denemeli      |
| Kullanım         | Canlı pano, softphone UI | Muhasebe, veri ambarı, PMS senkronu |

## Bağlanma

```http
GET /api/v1/{{events/stream}}
Authorization: Bearer <accessToken>
Accept: text/event-stream
```

Tarayıcının yerleşik `EventSource`'u özel başlık göndermez; token'ı sorgu parametresi ile taşıyın veya kendi proxy'niz üzerinden bağlanın:

```typescript
const es = new EventSource(`${BASE}/{{events/stream}}?access_token=${token}`);

es.addEventListener("call.ringing", (e) => {
  const call = JSON.parse(e.data);
  showIncomingCallToast(call);
});

es.onerror = () => {
  // tarayıcı otomatik yeniden bağlanır; token süresi dolduysa yenileyip yeni EventSource açın
};
```

## Kanallar ve olaylar

| Olay                   | Yük özeti                                   |
| ---------------------- | ------------------------------------------- |
| `call.ringing`         | Gelen çağrı; arayan numara, eşleşen misafir |
| `call.answered`        | Ajan çağrıyı aldı                           |
| `call.ended`           | Çağrı kapandı, süre                         |
| `queue.updated`        | Bekleyen çağrı listesi değişti              |
| `agent.presence`       | Ajan durumu (müsait / meşgul / mola)        |
| `message.received`     | Yeni WhatsApp / Instagram / web chat mesajı |
| `notification.created` | Kullanıcıya bildirim                        |

## Yeniden bağlanma

Sunucu periyodik `:heartbeat` yorumu gönderir. İstemci kuralları:

1. `EventSource` kopmada kendiliğinden yeniden bağlanır — kendi döngünüzü kurmayın.
2. **Token süresi dolarsa** bağlantı `401` ile kapanır: token'ı yenileyip **yeni** `EventSource` açın.
3. {{45}} saniyedir heartbeat gelmiyorsa bağlantıyı kapatıp yeniden açın.
4. Yeniden bağlandıktan sonra ekran durumunu REST ile **tazeleyin** — kopukken kaçan olaylar tekrar gönderilmez.

## Anonim arayan

Numarası gizli çağrılarda `callerNumber` boş gelir. Arayüzde "Bilinmeyen numara" gösterin; boş string'i geçerli numara gibi işlemeyin.

## Ölçekleme notu

Her açık akış bir sunucu bağlantısı tutar. Kullanıcı başına **tek** akış açın ve olayları uygulama içinde dağıtın; sekme başına yeni bağlantı açmayın (`BroadcastChannel` veya paylaşılan worker kullanın).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developer.konukcrm.com/rehberler/gercek-zamanli-olaylar-sse.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
