채널 생성 / 삭제

1. Create Channel

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

  • data의 경우, 최대 5개의 key-value pair를 입력할 수 있습니다. key의 최대 size는 128자 이고 최대 value size는 1024자입니다. Key, value 둘 다 문자열이어야 합니다.

  • 채널 타입의 경우 private, public, invitationOnly 타입을 지원합니다.

  • type와 members 필드는 필수 입니다.

  • invitationOnly 타입의 경우 invitationCode도 추가적으로 필수 필드입니다.

Type

정의값

Join 가능 여부

FCM 지원

PRIVATE

private

불가

지원

PUBLIC

public

가능

지원

INVITATION ONLY

invitationOnly

가능, Invitation Code 필요

지원

BROADCAST

broadcast

가능

지원

SUPER_PRIVATE

super_private

가능

미지원

SUPER_PUBLIC

super_public

가능

미지원

  • PRIVATE 타입의 경우 채널 id와 참여 사용자(targetIds)가 동일한 경우 reuseChannel 파라미터를 true로 설정하여 기존 생성된 채널을 재사용할 수 있습니다. 이는 1:1 대화를 구현하는데 유용하게 사용할 수 있습니다.

  • PUBLIC 타입 채널에 ban당하지 않은 사용자는 누구나 가입할 수 있습니다.

  • INVITATION_ONLY 타입의 경우 invitationCode를 제공해야 채널 가입이 가능합니다.

  • BROADCAST 타입의 경우:

    • 채널 owner가 메시지 발송 시 채널 멤버 모두에게 메시지가 발송됩니다.

    • 채널 owner가 아닌 채널 멤버가 메시지 발송 시 채널 owner에게만 메시지가 전달됩니다.

  • SUPER_PRIVATE, SUPER_PUBLIC 타입의 경우,

    • 최대 멤버 제한수를 100명 이상으로 설정할 수 있습니다.

    • 최대 멤버 제한수를 -1로 설정하면 멤버를 무제한으로 추가할 수 있습니다.

    • members와 bannedUsers 필드에 사용자 정보가 채워져서 내려오는 일반 채널과 달리:

      • members, bannedUsers, mutedUsers 필드는 빈 상태로 내려옵니다.

    • unreadCount, FCM Push Notification, invitationCode, lastReadAt 이 지원되지 않습니다.

await client.createChannel({
      channelId: 'my_private_channel', // required, needs to be URI valid
      name: 'my_private_channel', // optional
      type: 'private', // required
      members: ['my_user_id', 'another_user_id'], // optional. Current user(owner) added by default.
      invitationCode: 'secret invitation code', // required only for 'invitationOnly' channel type
      reuseChannel: true, // default: false
      imageUrl : 'image URL', // optional
      maxMemberCount: 10, // optional. default 100 for non-super-channel
      hideMessagesBeforeJoin: true, // if true, users cannot see messages older than their channel join date
      category: 'category A', // optional. can be used for grouping/searching channels
      subcategory: 'subcategory B', // optional. can be used for grouping/searching channels
      data: { // optional
        someMetaKey1: "someMetaValue1",
        someMetaKey2: "someMetaValue2",
      }, 
    });

Response

{
  "channel": {
    "id": "my_private_channel",
    "name": "my_private_channel",
    "ownerId": "user123",
    "pushNotificationDisabled": false,
    "imageUrl": "image url",
    "data": {
      "someMetaKey1": "someMetaValue1",
      "someMetaKey2": "someMetaValue2"
    },
    "type": "private",
    "invitationCode": "",
    "isFrozen": false,
    "memberCount": 2,
    "maxMemberCount": 10,
    "hideMessagesBeforeJoin": true,
    "category": "test",
    "subcategory": "",
    "privateTag": "",
    "privateData": "",
    "mutedUsers": [],
    "members": [
      {
        "id": "user123",
        "username": "john",
        "profileImageUrl": "http://cnd.test.com/123.jpg",
        "data": {},
        "memberInfo": {},
        "updatedAt": 1603244896634,
        "createdAt": 1603184094285,
        "lastReadAt": 1603244933412,
        "lastSentAt": 1603244933412
      },
      {
        "id": "another_user_id",
        "username": "another_user_id",
        "profileImageUrl": "http://cnd.test.com/another_user.jpg",
        "data": {},
        "memberInfo": {},
        "updatedAt": 1603244410844,
        "createdAt": 1603244410844,
        "lastReadAt": 1603244933412,
        "lastSentAt": 1603244933412
      }
    ],
    "bannedUsers": [],
    "pushNotificationDisabled": false,
    "pushNotificationSoundAOS": "",
    "pushNotificationSoundIOS": "",
    "updatedAt": 0,
    "createdAt": 0,
    "unreadCount": 0,
    "lastReadAt": 0,
    "lastMessage": null
  }
}

2. 채널 삭제

채널 owner만 채널 삭제가 가능합니다.

await client.deleteChannel({channelId: 'my_private_channel'});

Last updated