> For the complete documentation index, see [llms.txt](https://platform-business.gitbook.io/klat/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://platform-business.gitbook.io/klat/flutter/channel/create.md). Agents can also search and read this documentation through its [MCP server](https://platform-business.gitbook.io/klat/~gitbook/mcp).

# 채널 생성 / 삭제

## 1. 채널 생성

대화를 위한 채널을 생성합니다.

* `targetId`의 경우 `TPUser` 객체에서 `getUserId`함수를 통하여 얻어올 수 있습니다.
* data의 경우, 최대 5개의 key-value pair를 입력할 수 있습니다. key의 최대 size는 128자 이고 최대 value size는 1024자입니다.
* 채널 타입의 경우 `private`, `public`, `invitationOnly`, `broadcast`, `super_broadcast`, `super_private`, `super_public` 타입을 지원합니다.
* type 필드는 필수 입니다.
* invitationOnly 타입의 경우 invitationCode도 추가적으로 필수 필드입니다.
* hideMessagesBeforeJoin 파라미터를 true로 설정하면 채널의 새로운 참여자는 참여 시점 이전의 메시지를 볼 수 없습니다.

| Type             | 정의값              | Join 가능 여부             | FCM 지원 |
| ---------------- | ---------------- | ---------------------- | ------ |
| PRIVATE          | private          | 불가                     | 지원     |
| PUBLIC           | public           | 가능                     | 지원     |
| INVITATION ONLY  | invitationOnly   | 가능, Invitation Code 필요 | 지원     |
| BROADCAST        | broadcast        | 가능                     | 지원     |
| SUPER\_BROADCAST | super\_broadcast | 가능                     | 미지원    |
| SUPER\_PRIVATE   | super\_private   | 불가                     | 미지원    |
| SUPER\_PUBLIC    | super\_public    | 가능                     | 미지원    |

* PRIVATE 타입의 경우 채널 id와 참여 사용자(targetIds)가 동일한 경우 reuseChannel 파라미터를 true로 설정하여 기존 생성된 채널을 재사용할 수 있습니다. 이는 1:1 대화를 구현하는데 유용하게 사용할 수 있습니다.
* PUBLIC 타입 채널에 ban당하지 않은 사용자는 누구나 가입할 수 있습니다.
* INVITATION\_ONLY 타입의 경우 invitationCode를 제공해야 채널 가입이 가능합니다.
* BROADCAST, SUPER\_BROADCAST 타입의 경우:
  * 채널 owner가 메시지 발송 시 채널 멤버 모두에게 메시지가 발송됩니다.
  * 채널 owner가 아닌 채널 멤버가 메시지 발송 시 채널 owner에게만 메시지가 전달됩니다.
* **SUPER\_BROADCAST, SUPER\_PRIVATE, SUPER\_PUBLIC 타입의 경우,**
  * **최대 멤버 제한수를 100명 이상으로 설정할 수 있습니다.**
  * **최대 멤버 제한수를 -1로 설정하면 멤버를 무제한으로** **추가할 수 있습니다.**
  * **members와 bannedUsers 필드에 사용자 정보가 채워져서 내려오는 일반 채널과 달리:**
    * **members, bannedUsers, mutedUsers 필드는 빈 상태로 내려옵니다.**
  * **unreadCount, FCM Push Notification, invitationCode, lastReadAt 이 지원되지 않습니다.**

```dart
var params = TPChannelCreateParams(channelType: TPChannelCreateType.TPChannelPublic);
params.channelName = "unique_channel_name";
params.maxMemberCount = 50;
params.targetIds = ["test1", "test2"];
params.reuseChannel = true;
params.hideMessagesBeforeJoin = true;
params.category = "category_name";
params.subCategory = "sub_category_name";
params.imageUrl = "image_url";
params.metaData = {"key":"value"};

TPChannel? channel = await TalkPlusAPI.createTPChannel(params, 
    errorCallback: (errorCode, errorMessage)
{ 

});
```

{% hint style="info" %}
TPChannelCreateParams 및 createTPChannel 메소드는 Klat Flutter SDK v1.0.0 이상에서 지원됩니다.
{% endhint %}

## 2. 채널 삭제

현재 참여중인 채널 목록을 조회할 수 있습니다.

{% hint style="info" %}
채널 owner만 채널 삭제가 가능합니다.
{% endhint %}

```csharp
await TalkPlusAPI.deleteChannel(
    channelId, 
    errorCallback: (errorCode, errorMessage){}
);
```
