# Introduction

## 소개

## 게임을 위한 채팅 기능을 쉽고 빠르게 구현할 수 있는 서비스


# Dashboard

NAVER CLOUD PLATFORM의 Game Chat에서 제공하는 대시보드에 대한 가이드입니다.

## Game Chat 대시보드 소개

**Q. 대시보드란?**

대시보드를 통해 채팅을 운영하고 관리하실 수 있습니다.

**Q. 대시보드에서 어떤 운영 기능이 포함되나요?**

대시보드에는 채팅 관련 통계 확인이 가능하고 NAVER CLOUD PLATFORM의 서비스와 연동하여 Papago 번역 등 다양한 기능을 제어할 수 있습니다.

## Game Chat 대시보드 시작하기

### 로그인

#### Step 1. 대시보드 접속

NAVER CLOUD PLATFORM의 콘솔에서 관리 페이지 URL을 클릭하여 대시보드에 접속합니다.

#### STEP 2. 회원가입

프로젝트 생성 시 등록한 관리자 계정으로 비밀번호 초기화 메일이 전송됩니다.

관리자 계정이 대시보드 관리의 모든 권한을 갖는 마스터 계정이 됩니다.

사용할 비밀번호와 대시보드에 보일 시간대를 설정하고 로그인합니다.

## 대시보드 메뉴 활용하기

## 운영

### 대시보드

대시보드에서는 접속 현황, 메시지, 통계 등의 채팅의 전반적인 운영 상황을 한눈에 파악할 수 있습니다.

날짜를 선택하여 그래프를 확인할 수 있습니다.

### 회원

#### - 목록

가입한 회원 목록이 표시됩니다.

가입일, ID, 닉네임, 국가, IP 등을 지정하여 회원을 조회할 수 있습니다.

사용자 ID를 클릭하면 상세 정보를 확인할 수 있습니다.

![gamechat\_dashboard\_01](https://1574644262-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEIk-Gy8pz5Qt-YTFil%2Fsync%2F680eb109ae37871bce6301a82a16573c73fd9bfd.png?generation=1609987764071461\&alt=media)

**정지** 버튼을 클릭하여 특정 회원을 이용정지할 수 있습니다.

* 이용정지 활성화 여부를 선택할 수 있습니다.
* KICK을 체크한 상태로 저장하면 회원이 참여되어 있는 모든 채팅에서 내보냅니다.

**삭제** 버튼을 클릭하여 특정 회원을 삭제할 수 있습니다.

**저장** 버튼을 클릭하여 회원 정보를 수정할 수 있습니다.

#### - 이용정지

특정 회원에 대해, 지정된 기간 동안 채팅에 접속할 수 없도록 합니다.

이용정지는 회원의 사용자 ID를 기준으로 적용됩니다.

이용정지된 회원들을 표로 확인할 수 있고 시작일, 아이디 등으로 조회할 수 있습니다.

**등록** 버튼을 클릭하여 이용정지할 회원을 추가할 수 있습니다.

회원을 클릭하면 이용정지 상세 내역을 확인할 수 있습니다.

**삭제** 버튼을 클릭하여 이용정지 내역을 삭제할 수 있습니다.

**저장** 버튼을 클릭하여 이용정지 내역을 수정할 수 있습니다.

### 채팅

![gamechat\_dashboard\_02](https://1574644262-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEIk-Gy8pz5Qt-YTFil%2Fsync%2F73971cde4c71784ffdef299810c1238299704f25.png?generation=1609902115858712\&alt=media)

채널을 확인하고 채팅을 전송할 수 있습니다.

**채널 추가** 버튼을 클릭하여 채널명을 입력해 채널을 추가할 수 있습니다.

Unique ID를 입력하면 SDK에서 해당 값을 이용하여 채널에 접속 가능합니다.

**참여 목록** 버튼을 클릭하여 채팅 참여 인원 목록을 확인할 수 있습니다.

**채널 수정** 버튼을 클릭하여 채널 정보를 수정할 수 있습니다.

**삭제** 버튼을 클릭하여 채널을 삭제할 수 있습니다.

### 검색

프로젝트의 모든 채널의 메시지를 확인하고 검색할 수 있습니다.

발송 일시, 아이디, 닉네임, 메시지, 채널 ID 등으로 검색할 수 있습니다.

메시지 목록을 CSV 파일 형태로 다운로드할 수 있습니다.

**보기** 버튼을 클릭하여 상세정보를 확인할 수 있습니다.

**삭제** 버튼을 클릭하여 메시지를 삭제할 수 있습니다.

### 설정

Game Chat의 전반적인 환경을 설정하고 채팅을 운영하기 위한 다양한 키값을 입력하실 수 있습니다.

#### - 프로젝트 설정

프로젝트의 기본 정보를 확인하고 프로젝트명, 금칙어 설정 등을 수정할 수 있습니다.

Papago를 활성화하면 채팅 번역 기능을 사용할 수 있습니다.

네이버 클라우드와 연동을 위한 Papago 키값을 추가해야 합니다.

[NAVER AI Application 사용 가이드](https://api.ncloud-docs.com/docs/ai-naver-papagonmt)를 참고하여 키값을 입력해 주세요.

#### - 사용자 설정

프로젝트의 사용자를 확인할 수 있습니다.

**상세 보기** 버튼을 클릭하여 사용자의 상세정보를 확인하고 수정할 수 있습니다.

단, 현재 접속한 계정은 회원정보 수정에서 수정 가능합니다.

### 작업관리

각 메뉴에서 csv로 내보내기 한 결과를 30일간 다운로드할 수 있습니다.

## DOCS

### Unity

게임챗 Unity 사용 가이드로 이동합니다.

![gamechat\_dashboard\_03](https://1574644262-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEIk-Gy8pz5Qt-YTFil%2Fsync%2F61c89b36fa5a5f7a25d435a7c31569acccbdc09f.png?generation=1609987765014748\&alt=media)

## 언어 변경

대시보드의 각 메뉴 등이 선택한 언어로 변경됩니다.

## 회원정보 수정

대시보드 이용 계정의 정보를 변경하실 수 있습니다.

### 내 정보 수정

로그인한 계정의 정보를 확인하고 이름과 프로필 URL, 대시보드 시간대를 변경할 수 있습니다.

프로필 이미지는 채팅 시 사용됩니다.

### 비밀번호 변경

현재 비밀번호와 신규 비밀번호를 입력해 비밀번호를 변경할 수 있습니다.

## 로그아웃

현재 계정에서 로그아웃하고 로그인 페이지로 이동합니다.


# Javascript SDK

## Authentification

### 1. 대시보드에서 설정에서 프로젝트ID 를 확인 합니다.

[GameChat.min.js](https://kr.object.ncloudstorage.com/gamechat/gamechat.min.js) 을 다운로드 합니다.

를 사이에 추가 합니다.

게임챗을 사용하기전에 인스턴스를 초기화 해야 합니다. 대시보드에서 확인한 프로젝트ID 를 추가해 주세요.

```javascript
var gc = new gamechat.Chat();
gc.initialize(projectId);

// 싱가폴 리전 사용 시
gc.initialize(projectId, { region : 'sg' });
```

### 2. Connect to Game Chat Server

* 유저아이디를 통해, Game Chat 소켓 서버에 접속합니다.

```javascript
gc.setUser({
  id: 'userId',
  name: 'Nickname',
});

gc.connect(user_id, (err, res) => {
  if (err) console.log(err);
});
```

### 3. Disconnect from Game Chat Server

* 연결된 Game Chat 소켓서버와의 연결을 해제합니다.

```javascript
gc.disconnect();
```

## Communication

### 1. Subscribe / Unsubscribe

* 채널 아이디로, 특정 채널에 (un)subscribe 합니다

```javascript
gc.subscribe(CHANNEL_ID);
gc.unsubscribe(CHANNEL_ID);
```

| ID          | type   | desc   |
| ----------- | ------ | ------ |
| CHANNEL\_ID | string | 채널 아이디 |

### 2. SendMessage

* 채널 아이디로, 특정 채널에 메시지를 송신합니다.

```javascript
gc.sendMessage(CHANNEL_ID, MESSAGE);
```

| ID          | type   | desc       |
| ----------- | ------ | ---------- |
| CHANNEL\_ID | string | 채널 아이디     |
| MESSAGE     | string | 전송 메시지 텍스트 |

## Event

### Binding Event

* Game Chat 소켓서버로부터 수신하는 이벤트에 대해, 이벤트 핸들러를 등록/해제 할 수 있습니다,

```javascript
// 메시지 수신
gc.bind('onMessageReceived', function (channel, message) {});
// 오류 메시지
gc.bind('onErrorReceived', function (channel, message) {});
// 접속 성공
gc.bind('onConnected', function (channel, message) {});
// 접속 종료
gc.bind('onDisconnected', function (reason) {});
```

## Client API

### 1-1. Subscription

* Subscription Data Class (per Unit)

| ID          | type   | desc      |
| ----------- | ------ | --------- |
| id          | string | 유니크 아이디   |
| channel\_id | string | 채널 아이디    |
| user\_id    | string | 유저 고유 아이디 |
| created\_at | string | 생성 일자     |

### 1-2. getSubscriptions

* (특정 채널에 대해) Subscription 데이터를 리스트 형태로 가져올 수 있습니다.

```javascript
gc.getSubscriptions(CHANNEL_ID, OFFSET, LIMIT, function(err, subscriptions)
{
    console.log(subscriptions);
}));
```

| ID          | type   | desc                             |
| ----------- | ------ | -------------------------------- |
| CHANNEL\_ID | string | 채널 아이디                           |
| OFFSET      | int    | Subscrtiption 데이터 시작 위치 (0: 첫번째) |
| LIMIT       | int    | 가져올 Subscrtiption 데이터 갯수         |

### 2-1. Channel

* Channel Data Class (per Unit)

```csharp
public class Channel
{
    public string id;
    public string project_id;
    public string unique_id;
    public string name;
    public string created_at;
    public string updated_at;
}
```

| ID          | type   | desc                         |
| ----------- | ------ | ---------------------------- |
| id          | string | 채널 아이디(unique)               |
| project\_id | string | 프로젝트 아이디                     |
| unique\_id  | string | 개발사에서 설정 가능한 채널 아이디 (unique) |
| name        | string | 채널 이름                        |
| created\_at | string | 생성 일자                        |
| updated\_at | string | 갱신 일자                        |

### 2-2. getChannels

* (프로젝트 내) Channel 데이터를 리스트 형태로 가져올 수 있습니다.

```csharp
gc.getChannels(OFFSET, LIMIT, function(err, channels) {
});
```

| ID     | type | desc                                 |
| ------ | ---- | ------------------------------------ |
| OFFSET | int  | (전체 채널 리스트로부터 가져올) 채널의 시작 위치 (index) |
| LIMIT  | int  | (가져올) 채널의 갯수                         |

### 2-4. create / update / delete Channel

* (프로젝트 내) 새로운 Channel Instance를 생성 / 갱신 / 삭제할 수 있습니다.

> 보안상의 이슈로, SDK를 통한 채널의 CRUD 기능은 제거되었습니다. Open API를 통해, Server to Server로 채널의 CRUD를 사용하실 수 있습니다.

[Guide => \[ Open API - Channel Create / Update / Delete \]](https://docs.gamechat.kr/undefined/gamechat_api#api)

### 2-5. getMessages

* (특정 채널에 대해) Message 데이터를 리스트 형태로 가져올 수 있습니다.

```javascript
gc.getMessages( {channelId:CHANNEL_ID, offset:OFFSET, limit:LIMIT, search:SEARCH, query:QUERY, sort:SORT, sortId:SORTID},
  function (err, messages) {}
);
```

| ID          | type   | desc                                                          |
| ----------- | ------ | ------------------------------------------------------------- |
| CHANNEL\_ID | string | 채널 아이디                                                        |
| OFFSET      | int    | (전체 메시지 리스트로부터 가져올) 메세지의 시작 위치                                |
| LIMIT       | int    | (가져올) 메세지의 갯수                                                 |
| SEARCH      | string | (메시지 검색 시) 검색 기준 key (ex> content.text) 빈 문자열 전달 시, full scan |
| QUERY       | string | (메시지 검색 시) 검색 value. 완전 일치만 검색 가능. 빈 문자열 전달 시, full scan      |
| SORT        | string | 메시지 리스트 정렬순서 (default : desc - 가장 최근순) (optional : asc)       |
| SORTID      | string | 해당 sort id 다음으로 메시지를 가져온다. ( 이전 목록 보기 )                       |

### 3-3. translateMessage

* (자동번역 기능이 활성화 되어 있을 경우) 임의의 텍스트를 (지정한 언어로) 번역할 수 있습니다.

> 해당 기능은, NaverCloud PAPAGO NMT 상품을 함께 연동할 경우 사용 가능합니다. [\[NCP Papago NMT\]](https://www.ncloud.com/product/aiService/papagoTranslation)

* (Received) Translation Data Class (per Unit)

```javascript
const tr_message = gc.translateMessage(
  CHANNEL_ID,
  SORCE_LANG,
  TARTGET_LANG,
  MESSAGE
);
```


# Unity SDK

## Authentification

### 1. Initializing with Project ID

* 생성한 Game Chat 프로젝트 아이디를 통해, Game Chat 인스턴스를 초기화합니다.

```csharp
GameChat.initialize(PROJECT_ID);

// 싱가폴 리전 사용 시
GameChat.setRegion("sg");
GameChat.initialize(PROJECT_ID);
```

| ID          | type   | desc     |
| ----------- | ------ | -------- |
| PROJECT\_ID | string | 프로젝트 아이디 |

### 2. Connect to Game Chat Server

* 유저아이디를 통해, Game Chat 소켓 서버에 접속합니다.

  \=> Game Chat 프로젝트 내에서, 유저아이디는 Unique 한 값입니다.
* api를 사용하기 위한 토큰값을 획득합니다.

  \=> (GameChat.connect 이후 시점) 갱신된 토큰값을 확인할 수 있습니다.
* (토큰값 획득과 함께) 현재 접속 디바이스에 대한 유저정보가 갱신됩니다.

  \=> GameChat.connect의 콜백으로 전달받는 Member는 갱신된 데이터입니다.

```csharp
GameChat.connect(USER_ID, (Member User, GameChatException Exception)=> {

    if(Exception != null)
    {
        // Error 핸들링
        return;
    }
});
```

| ID       | type   | desc      |
| -------- | ------ | --------- |
| USER\_ID | string | 유저 고유 아이디 |

### 3. Disconnect from Game Chat Server

* 연결된 Game Chat 소켓서버와의 연결을 해제합니다.

```csharp
GameChat.disconnect();
```

### 4. User Information

* 유저정보가 저장/갱신됩니다.

```csharp
// (connect 이후 시점) 갱신됩니다.

string Adid = GameChat.getAdid();

string MemberId = GameChat.getMemberId();

string NickName = GameChat.getNickName();

string ProfileUrl = GameChat.getProfileUrl();

string Token = GameChat.getToken();
```

| ID         | type   | desc                     |
| ---------- | ------ | ------------------------ |
| Adid       | string | 광고아이디(Unique identifier) |
| MemberId   | string | 유저 고유 아이디                |
| NickName   | string | 유저 닉네임                   |
| ProfileUrl | string | 프로필 이미지 url              |
| Token      | string | Authentification Token   |

```csharp
// (initialize 이후 시점) 갱신됩니다.

GameChatDeviceInfo GameChat.getDeviceInfo();

GameChatDeviceInfo
{
    public string AppVersion = "";
    public string DeviceModel = "";
    public string DeviceOSVersion = "";
    public string NetworkType = "";
}
```

| ID              | type   | desc                                                    |
| --------------- | ------ | ------------------------------------------------------- |
| AppVersion      | string | 앱 버전(Edit > Project Settings > Player > Other Settings) |
| DeviceModel     | string | 접속 디바이스 모델                                              |
| DeviceOSVersion | string | 접속 디바이스 환경                                              |
| NetworkType     | string | 접속 네트워크 타입 (CELLULAR, WIFI)                             |

## Communication

### 1. Subscribe / Unsubscribe

* 채널 아이디로, 특정 채널에 (un)subscribe 합니다

```csharp
GameChat.subscribe(CHANNEL_ID);

GameChat.unsubscribe(CHANNEL_ID);
```

| ID          | type   | desc   |
| ----------- | ------ | ------ |
| CHANNEL\_ID | string | 채널 아이디 |

### 2. SendMessage

* 채널 아이디로, 특정 채널에 메시지를 송신합니다.

```csharp
GameChat.sendMessage(CHANNEL_ID, MESSAGE);
```

| ID          | type   | desc       |
| ----------- | ------ | ---------- |
| CHANNEL\_ID | string | 채널 아이디     |
| MESSAGE     | string | 전송 메시지 텍스트 |

## Event

### Binding Event

* Game Chat 소켓서버로부터 수신하는 이벤트에 대해, 커스텀 핸들러를 등록/해제 할 수 있습니다,

```csharp
GameChat.dispatcher.(EVENT_NAME) += (CALLBACK_FUNCTION);

GameChat.dispatcher.(EVENT_NAME) -= (CALLBACK_FUNCTION);
```

```csharp
public delegate void onConnectedCallback(string data);
public onConnectedCallback onConnected;
//'connect' Event에 대한, callback

public delegate void onDisconnectedCallback(string reason);
public onDisconnectedCallback onDisconnected;
//'disconnect' Event에 대한, callback

public delegate void onMessageReceivedCallback(Message message);
public onMessageReceivedCallback onMessageReceived;
//'message' Event에 대한, callback

public delegate void onErrorReceivedCallback(string result, GameChatException exception);
public onErrorReceivedCallback onErrorReceived;
//'error' Event에 대한, callback
```

## Exception

* Game Chat API 사용 중에 발생하는, Exception에 대한 공통 처리 Class 입니다.

```csharp
public class GameChatException
{
    // Detail Error Code

    // 알 수 없는 Error
    public static readonly int CODE_UNKNOWN_ERROR           = 0;
    // 초기화 실패
    public static readonly int CODE_NOT_INITALIZE           = 1;
    // 파라미터가 올바르지 않은 경우
    public static readonly int CODE_INVAILD_PARAM           = 2;
    // 소켓서버로부터 발생한 오류
    public static readonly int CODE_SOCKET_SERVER_ERROR     = 500;
     //소켓으로부터 발생한 오류
    public static readonly int CODE_SOCKET_ERROR = -501;
    // 네트웍 연결 오류 및 타임아웃 발생 시
    public static readonly int CODE_SERVER_NETWORK_ERROR    = 4002;
    // 서버에서 받은 데이터를 파싱할 때 오류
    public static readonly int CODE_SERVER_PARSING_ERROR    = 4003;

    // HTTP 에러의 경우, 해당 상태코드가 응답코드로 전달됩니다. (400, 403 ...)

    // Error Code
    public int code { get; set; }
    // Error Message
    public string message { get; set; }
}
```

## Client API

### 1-1. Subscription

* Subscription Data Class (per Unit)

```csharp
public class Subscription
{
    public string id;
    public string channel_id;
    public string user_id;
    public string created_at;
}
```

| ID          | type   | desc      |
| ----------- | ------ | --------- |
| id          | string | 유니크 아이디   |
| channel\_id | string | 채널 아이디    |
| user\_id    | string | 유저 고유 아이디 |
| created\_at | string | 생성 일자     |

### 1-2. getSubscriptions

* (특정 채널에 대해) Subscription 데이터를 리스트 형태로 가져올 수 있습니다.

```csharp
GameChat.getSubscriptions(CHANNEL_ID, OFFSET, LIMIT, (List<Subscription> Subscriptions, GameChatException Exception) => {

    if(Exception != null)
    {
        // Error 핸들링
        return;
    }

    foreach(Subscription elem in Subscriptions)
    {
        //handling each subscription instance
    }
}));
```

### 2-1. Channel

* Channel Data Class (per Unit)

```csharp
public class Channel
{
    public string id;
    public string project_id;
    public string unique_id;
    public string name;
    public string user_id;
    public string created_at;
    public string updated_at;
}
```

| ID          | type   | desc                         |
| ----------- | ------ | ---------------------------- |
| id          | string | 채널 아이디(unique)               |
| project\_id | string | 프로젝트 아이디                     |
| unique\_id  | string | 개발사에서 설정 가능한 채널 아이디 (unique) |
| name        | string | 채널 이름                        |
| user\_id    | string | (채널 생성한) 유저 아이디              |
| created\_at | string | 생성 일자                        |
| updated\_at | string | 갱신 일자                        |

### 2-2. getChannels

* (프로젝트 내) Channel 데이터를 리스트 형태로 가져올 수 있습니다.

```csharp
GameChat.getChannels(OFFSET, LIMIT, (List<Channel> Channels, GameChatException Exception) => {

    if(Exception != null)
    {
        // Error 핸들링
        return;
    }

    foreach(Channel elem in Channels)
    {
        //handling each channelInfo instance
    }
});
```

| ID     | type | desc                                 |
| ------ | ---- | ------------------------------------ |
| OFFSET | int  | (전체 채널 리스트로부터 가져올) 채널의 시작 위치 (index) |
| LIMIT  | int  | (가져올) 채널의 갯수                         |

### 2-3. getChannel

* (Channel) ID / UniqueID를 통해, Channel 데이터를 가져올 수 있습니다.

```csharp
//CHANNEL_ID로만 Search 할 경우, CHANNEL_UNIQUE_ID 파라메터에 null을 넣어주세요.

//CHANNEL_ID와 CHANNEL_UNIQUE_ID값이 함께 존재할 경우, CHANNEL_UNIQUE_ID 값을 우선으로 Search합니다.

GameChat.getChannel(CHANNEL_ID, CHANNEL_UNIQUE_ID,  (Channel Channel, GameChatException Exception) => {

    if(Exception != null)
    {
        // Error 핸들링
        return;
    }

    //handling channelInfo instance
});
```

```csharp
GameChat.getChannel(CHANNEL_UNIQUE_ID, (Channel Channel, GameChatException Exception) => {

    if(Exception != null)
    {
        // Error 핸들링
        return;
    }

    //handling channelInfo instance
});
```

| ID                  | type   | desc                                |
| ------------------- | ------ | ----------------------------------- |
| CHANNEL\_ID         | string | 채널 아이디 (auto generated)             |
| CHANNEL\_UNIQUE\_ID | string | 채널 (고유) 아이디 (customizing available) |

### 2-4. create / update / delete Channel

* (프로젝트 내) 새로운 Channel Instance를 생성 / 갱신 / 삭제할 수 있습니다.

> 보안상의 이슈로, SDK를 통한 채널의 CRUD 기능은 제거되었습니다. Open API를 통해, Server to Server로 채널의 CRUD를 사용하실 수 있습니다.

[Guide => \[ Open API - Channel Create / Update / Delete \]](https://docs.gamechat.kr/undefined/gamechat_api#api)

### 3-1. Message

* (Received) Message Data Class (per Unit)

```csharp
public class Message
{
    public class User
    {
        public string id;
        public string name;
        public string profile;
    }

    public string message_id;
    public string channel_id;
    public string message_type;
    public string content;

    public string mentions;
    public bool mentions_everyone;
    public User sender;
    public string created_at;
}
```

| ID                 |            | type      | desc                 |
| ------------------ | ---------- | --------- | -------------------- |
| message\_id        |            | string    | 메시지 유니크 아이디          |
| channel\_id        |            | string    | 채널 아이디               |
| message\_type      |            | string    | 메세지 타입               |
| content            |            | string    | 메세지 내용 (json string) |
| mentions           |            | string    | 멘션(태그)               |
| mentions\_everyone |            | string    | 전체 메세지 여부            |
|                    | **sender** | **Class** |                      |
|                    | id         | string    | (송신한) 유저 고유 아이디      |
|                    | name       | string    | (송신한) 유저 닉네임         |
|                    | profile    | string    | (송신한) 유저 이미지 프로필 url |
| created\_at        |            | string    | 메세지 생성 일자            |

### 3-2. getMessages

* (특정 채널에 대해) Message 데이터를 리스트 형태로 가져올 수 있습니다.

```csharp
GameChat.getMessages(CHANNEL_ID, OFFSET, LIMIT, SEARCH, QUERY, SORT, (List<Message> Messages, GameChatException Exception) => {

    if(Exception != null)
    {
        // Error 핸들링
        return;
    }

    foreach(Message elem in Messages)
    {
        //handling each message instance
    }
});
```

| ID          | type   | desc                                                          |
| ----------- | ------ | ------------------------------------------------------------- |
| CHANNEL\_ID | string | 채널 아이디                                                        |
| OFFSET      | string | (전체 메시지 리스트로부터 가져올) 메세지의 시작 위치                                |
| LIMIT       | string | (가져올) 메세지의 갯수                                                 |
| SEARCH      | string | (메시지 검색 시) 검색 기준 key (ex> content.text) 빈 문자열 전달 시, full scan |
| QUERY       | string | (메시지 검색 시) 검색 value. 완전 일치만 검색 가능. 빈 문자열 전달 시, full scan      |
| SORT        | string | 메시지 리스트 정렬순서 (default : desc - 가장 최근순) (optional : asc)       |

### 3-3. translateMessage

* (자동번역 기능이 활성화 되어 있을 경우) 임의의 텍스트를 (지정한 언어로) 번역할 수 있습니다.

> 해당 기능은, NaverCloud PAPAGO NMT 상품을 함께 연동할 경우 사용 가능합니다. [\[ NCP Papago NMT \]](https://www.ncloud.com/product/aiService/papagoTranslation)

* (Received) Translation Data Class (per Unit)

```csharp
public class Translation
{
    public string detectLang = "";
    public string lang = "";
    public bool translated = false;
    public string message = "";
}
```

| ID         | type   | desc                                                                                      |
| ---------- | ------ | ----------------------------------------------------------------------------------------- |
| detectLang | string | 출발 언어 코드 [\[API Guide\]](https://api.ncloud-docs.com/docs/ai-naver-papagonmt-translation) |
| lang       | string | 도착 언어 코드 [\[API Guide\]](https://api.ncloud-docs.com/docs/ai-naver-papagonmt-translation) |
| translated | bool   | 번역 성공 여부                                                                                  |
| message    | string | 결과 메세지 내용 (json string)                                                                   |

```csharp
GameChat.translateMessage(CHANNEL_ID, SORCE_LANG, TARTGET_LANG, TEXT, (List<Translation> Translations, GameChatException Exception) => {

    if(Exception != null)
    {
        // Error 핸들링
        return;
    }

    foreach(Translation elem in Translations)
    {
        //handling each Translation instance
    }
});

GameChat.translateMessage(SORCE_LANG, TARTGET_LANG, TEXT, (List<Translation> Translations, GameChatException Exception) => {

    if(Exception != null)
    {
        // Error 핸들링
        return;
    }

    foreach(Translation elem in Translations)
    {
        //handling each Translation instance
    }
});
```

| ID            | type   | desc                                                                                                                                        |
| ------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------- |
| CHANNEL\_ID   | string | 채널 아이디                                                                                                                                      |
| SORCE\_LANG   | string | (송신 할) 텍스트 언어명 (auto : 자동감지) [\[API Guide\]](https://api.ncloud-docs.com/docs/ai-naver-papagonmt-translation)                               |
| TARTGET\_LANG | string | (번역 수신 할) 텍스트 언어 코드 ("," 구분하여 복수 입력 가능 - ex> "en, fr, th") [\[API Guide\]](https://api.ncloud-docs.com/docs/ai-naver-papagonmt-translation) |
| TEXT          | string | (송신 할) 텍스트                                                                                                                                  |

### 4-1. Member

* (Received) Member Data Class (per Unit)

```csharp
public class Member
{
    public string id = "";
    public string project_id = "";
    public string nickname = "";
    public string profile_url = "";
    public string country = "";
    public string remoteip = "";
    public string adid = "";
    public string device = "";
    public string network = "";
    public string version = "";
    public string model = "";
    public string logined_at = "";
    public string created_at = "";
    public string updated_at = "";
}
```

| ID           | type   | desc                       |
| ------------ | ------ | -------------------------- |
| id           | string | 유저 고유 아이디                  |
| project\_id  | string | (로그인한) Game Chat 프로젝트 아이디  |
| nickname     | string | 유저 닉네임                     |
| profile\_url | string | (이미지) 프로필 Url              |
| country      | string | 접속 국가                      |
| remoteip     | string | 접속 IP                      |
| adid         | string | 광고 식별자                     |
| device       | string | 접속 디바이스 환경                 |
| network      | string | 접속 네트워크 타입(CELLULAR, WIFI) |
| version      | string | 접속 앱 버전                    |
| model        | string | 접속 디바이스 모델                 |
| logined\_at  | string | 로그인한 일자                    |
| created\_at  | string | 유저 생성 일자                   |
| updated\_at  | string | 유저 정보 갱신 일자                |

### 4-2. updateMember

* 채팅 서버의 유저 정보를 갱신할 수 있습니다.

```csharp
// 유저 닉네임 업데이트
// 닉네임 허용 문자열은 whitespace(spaces, tabs, line breaks)를 포함하지 않는 2~128자 입니다.
GameChat.setNickname(MEMBER_ID, NICKNAME, (Member member, GameChatException Exception) => {

    if(Exception != null)
    {
        // Error 핸들링
        return;
    }
    //handling updated Member instance
});

//유저 프로필 이미지 url 업데이트
GameChat.setProfileUrl(MEMBER_ID, PROFILE, (Member member, GameChatException Exception) => {

    if(Exception != null)
    {
        // Error 핸들링
        return;
    }
    //handling updated Member instance
});
```

| ID         | type   | desc        |
| ---------- | ------ | ----------- |
| MEMBER\_ID | string | 유저 고유 아이디   |
| NICKNAME   | string | 유저 닉네임      |
| PROFILE    | string | 프로필 이미지 url |

## GameChatExtension (Emoji, HyperLink)

* 수신 메시지에 포함된, Emoji와 HyperLink 텍스트를 다루기 쉽게 도와주는 Helper Class 입니다.
* TMP\_GameChatTextUGUI는 Unity Built-In Asset 인 TextMeshPro를 확장한 클래스 입니다. 사용하기 위해서는, 먼저 Package Manager를 이용해 TextMeshPro가 설치되었는지 확인해주세요.

> TextMeshPro Asset의 경우, Unity 2018.2 이상의 버전부터 Built-In Asset으로 포함됩니다.

> Unity 에디터 상에서, Window > TextMeshPro > Import TMP Essential Resources를 눌러, 기본 리소스까지 import 해 주세요.

> Emoji Sprite Sheet의 경우, Emoji version 13(Android)를 기준으로 기본 출력되며 Sprite Sheet를 변경하여 커스터마이징이 가능합니다.

```csharp
namespace GameChatUnity.Extension
{
    public class TMP_GameChatTextUGUI : TextMeshProUGUI
    {
        public bool isHyperLinked { get; set; }    // link 형태 주소를 hyperlink 처리 여부 (append html tag)
        public string LinkTextColor { get; set; }  // hyperlink text color
    }
}
```

Case

```csharp
using GameChatUnity.Extension;

TMP_GameChatTextUGUI message = msgObject.GetComponent<TMP_GameChatTextUGUI>();

//hyperlink 인식 및 처리를 위해, text는 setMessage를 통해 넣어주세요.
message.setMessage(MESSAGE_CONTENT);
message.color = Color.green;
message.isHyperLinked = true;

...

msgObject = Instantiate(msgObject) as GameObject;

...

// hyperlink에 대한 click event listener는, 직접 구현해주세요.

//Handling with TMP_LinkInfo
TMP_LinkInfo linkInfoArr = message.textInfo.linkInfo[LINK_INDEX];

...
```


# OPEN API

Game Chat의 몇몇 기능을 규정 된 API로 호출할 수 있는 기능입니다.

> 대시보드에서 발급한 허용된 API Key를 사용해야 호출이 가능합니다.

## API Key 확인

API Key는 **대시보드 > 설정 > 프로젝트 설정 > API Key** 에서 생성할 수 있습니다.

> 재발급 버튼을 누르면 키가 재발급 되며, 이전 키는 사용할 수 없으니 주의하세요.

## Open API 사용하기

### Base URL

```
https://dashboard-api.gamechat.naverncp.com/v1/api/project/{projectId}

- {projectId}부분에는 Game Chat의 project id를 적용
```

### 공통 Error code

Open API 요청시 발생하는 공통 에러코드입니다.

| Code | Description                |
| ---- | -------------------------- |
| -1   | 대시보드에 없는 키를 사용한 경우         |
| -2   | 대시보드의 키와 헤더의 키가 다른경우       |
| -3   | 대시보드에서 삭제한 키를 사용한 경우       |
| -4   | 대시보드에서 미사용으로 처리된 키를 사용한 경우 |
| -5   | 키가 만료된 경우                  |
| -6   | 프로젝트 아이디가 없는 경우            |

### 채널 생성 API

채널을 생성합니다.

#### Request

* Method : POST
* URI : /channel

```
POST
url : https://dashboard-api.gamechat.naverncp.com/v1/api/project/{projectId}/channel
Header : 'x-api-key: {API Key}'
Header : 'content-type: application/json'
data: '{
    "name":"#All"
}'
```

| Header    | Type   | Required | Description                   |
| --------- | ------ | -------- | ----------------------------- |
| x-api-key | String | O        | 대시보드 > 설정 > 프로젝트 설정 > API Key |

| Attribute   | Type    | Required | Description                              |
| ----------- | ------- | -------- | ---------------------------------------- |
| projectId   | String  | O        | 프로젝트 아이디 (대시보드 > 설정 > 프로젝트 설정 > 프로젝트 ID) |
| name        | String  | O        | 채널 명                                     |
| translation | Boolean | X        | 번역 가능 여부                                 |
| uniqueId    | String  | X        | 임의로 지정할 수 있는 고유 아이디                      |

#### Response

```javascript
{
    "status": 1,
    "result": "1a51af0d-f464-4440-8ad6-ce69e0bdaba8"
}
```

| Attribute | Type   | Description                    |
| --------- | ------ | ------------------------------ |
| status    | Int    | 결과값 (1: 성공, 실패는 Error code 참고) |
| result    | String | 생성된 채널 아이디                     |

#### Error code

| Code | Description    |
| ---- | -------------- |
| -100 | 필수 파라미터가 없는 경우 |

### 채널 수정 API

채널의 정보를 수정합니다.

#### Request

* Method : PUT
* URI : /channel/{channelId}

```
PUT
url : https://dashboard-api.gamechat.naverncp.com/v1/api/project/{projectId}/channel/{channelId}
Header : 'x-api-key: {API Key}'
data: '{
    "name":"#GUILD"
}'
```

| Header    | Type   | Required | Description                   |
| --------- | ------ | -------- | ----------------------------- |
| x-api-key | String | O        | 대시보드 > 설정 > 프로젝트 설정 > API Key |

| Attribute  | Type    | Required | Description                              |
| ---------- | ------- | -------- | ---------------------------------------- |
| projectId  | String  | O        | 프로젝트 아이디 (대시보드 > 설정 > 프로젝트 설정 > 프로젝트 ID) |
| channelId  | String  | O        | 채널 아이디                                   |
| name       | String  | X        | 채널 명                                     |
| traslation | Boolean | X        | 번역 가능 여부                                 |

#### Response

성공

```javascript
{
    "status": 1,
    "message": "success"
}
```

| Attribute | Type   | Description                    |
| --------- | ------ | ------------------------------ |
| status    | Int    | 결과값 (1: 성공, 실패는 Error code 참고) |
| message   | String | 결과 메시지                         |

### 채널 삭제 API

채널을 삭제합니다.

#### Request

* Method : DELETE
* URI : /channel/{channelId}

```
DELETE
url : https://dashboard-api.gamechat.naverncp.com/v1/api/project/{projectId}/channel/{channelId}
Header : 'x-api-key: {API Key}'
```

| Header    | Type   | Required | Description                   |
| --------- | ------ | -------- | ----------------------------- |
| x-api-key | String | O        | 대시보드 > 설정 > 프로젝트 설정 > API Key |

| Attribute | Type   | Required | Description                              |
| --------- | ------ | -------- | ---------------------------------------- |
| projectId | String | O        | 프로젝트 아이디 (대시보드 > 설정 > 프로젝트 설정 > 프로젝트 ID) |
| channelId | String | O        | 채널 아이디                                   |

#### Response

성공

```javascript
{
    "status": 1,
    "message": "success"
}
```

| Attribute | Type   | Description                    |
| --------- | ------ | ------------------------------ |
| status    | Int    | 결과값 (1: 성공, 실패는 Error code 참고) |
| message   | String | 결과 메시지                         |


