# Mesajlaşma

Sohbet özelliği, sohbet dizilerine ve sohbet dizilerindeki mesajlara göre düzenlenmektedir.

## Uç Noktaları

## Sohbet Dizilerini Getir

<mark style="color:blue;">`GET`</mark> `https://cubicl.io/api/v1/chat/threads`

{% tabs %}
{% tab title="200: OK Sohbet dizisi listesi" %}

```javascript
ChatThread[]
```

{% endtab %}
{% endtabs %}

## Mesajları Getir

<mark style="color:blue;">`GET`</mark> `https://cubicl.io/api/v1/chat/threads/:threadId/messages`

Bir sohbet grubundaki mesajları getirir.

#### Path Parameters

| Name                                       | Type   | Description                                                            |
| ------------------------------------------ | ------ | ---------------------------------------------------------------------- |
| threadId<mark style="color:red;">\*</mark> | string | Sohbet dizisi ID'si                                                    |
| limit                                      | number |                                                                        |
| search                                     | string | Mesaj içeriğinde aranacak metin                                        |
| before                                     | string | Mesaj ID'si. Bu mesajdan önce gönderilen son mesajlar geri dönecektir. |
| after                                      | string | Mesaj ID'si. Bu mesajdan sonra gönderilen mesajlar geri dönecektir.    |

{% tabs %}
{% tab title="200: OK Mesaj listesi" %}

```javascript
ChatMessage[]
```

{% endtab %}
{% endtabs %}

## Mesaj Ekle

<mark style="color:green;">`POST`</mark> `https://cubicl.io/api/v1/chat/messages`

Mesajlar, sohbet dizilerine veya kullanıcılara gönderilir. İki kullanıcı arasında henüz bir sohbet dizisi yoksa alıcı kullanıcı ID'si ile `to` parametresini ayarlamanız gerekir. İlk mesajdan sonra bir ileti dizisi oluşturulacaktır. Mevcut sohbet dizileri için `thread` parametresini ayarlamalısınız.

`content` veya `files` parametrelerinden birisi ayarlanmalıdır.&#x20;

`thread` veya `to` parametrelerinden birisi ayarlanmalıdır.

#### Request Body

| Name    | Type      | Description                                          |
| ------- | --------- | ---------------------------------------------------- |
| thread  | string    | Sohbet dizisi ID'si                                  |
| replyTo | string    | Mesaj ID'si. Mesaj başka bir mesaja verilen cevapsa. |
| files   | string\[] | Dosyaların ID listesi                                |
| content | string    | Mesaj içeriği                                        |
| to      | string    | Kullanıcı ID'si                                      |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    // Yeni oluşturulan mesajın ID'si
    message: string,
    // Bu istekle yeni bir sohbet dizisi oluşturulursa bu mevcuttur.
    // Bir kullanıcı başka bir kullanıcıya ilk kez mesaj gönderdiğinde
    // yeni sohbet dizisi oluşturulur.
    thread?: ChatThread
}
```

{% endtab %}
{% endtabs %}

## Veriler

#### Sohbet Dizileri

Sohbet mesajları bir ileti dizisinde gönderilir. Dizilerin 3 tipi vardır:

1. **personal** : 2 kullanıcı arasında gerçekleşir. Bir kullanıcı başka bir kullanıcıya mesaj gönderdiğinde oluşturulur.
2. **group** : Her proje için oluşturulur. Tüm proje üyeleri bu dizinin üyesidir.
3. **custom** : Kullanıcıların kendileri tarafından bir grup kullanıcı arasında oluşturulur. Bu özel bir sohbet grubudur.

```typescript
type ChatThread = {
    _id: string;
    type: 'personal' | 'group' | 'custom';
    // 'type' parametresi 'group' olduğunda gereklidir.
    group?: string;
    // Sohbet dizisi adı. 'type' parametresi 'custom' olduğunda gereklidir.
    name?: string;
    // Sohbet dizisindeki kullanıcıların ID'leri.
    // 'type' parametresi 'personal' veya 'custom' olduğunda gereklidir.
    users: string[];
    // Sohbet dizisindeki son aktivitenin (mesajın) tarihi
    activity: number;
    // Mevcut kullanıcının sohbet dizisini görüntülediği tarih.
    // Daha önce erişilmediyse 0'dır.
    access: number;
    lastMessage: ChatMessage | null;
    // Son erişimden bu yana gelen yeni mesaj sayısı
    newActivityCount: number;
    createdAt: number;
}
```

#### Sohbet Mesajları

```typescript
type ChatMessage = {
    _id: string;
    // Sohbet dizisinin ID'si
    thread: string;
    // Mesajı gönderen kullanıcının ID'si
    from: string;
    content: string;
    // Mesajdaki dosya ekleri. Veri biçimi için Dosyalar sayfasını kontrol edin.
    files: File[];
    // Mesajı beğenen kullanıcıların ID'leri
    likes: string[];
    dislikes: string[];
    // Bir mesaj başka bir mesaja verilen cevapsa,
    // bu cevaplanan mesaj kimliği olacaktır.
    replyTo: string | null;
    createdAt: number;
}
```


---

# Agent Instructions: 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:

```
GET https://kilavuz.cubicl.io/api-entegrasyonu/mesajlasma.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
