# messages

## Message <a href="#undefined" id="undefined"></a>

The message function provided by Game Chat includes various services supporting efficient communication between users. This platform is suitable for group chat as well as personal chat, and it enables a simple, fast process of sending and receiving messages. The following describes Game Chat's main message functions and their features.

### 1. Instant messaging <a href="#id-1" id="id-1"></a>

* **Real-time communication**: you can send and receive messages in real time, which minimizes communication delay.
* **Supporting multiple devices**: you can send and receive messages on various devices such as smartphones, tablets, PCs, and so on.

### 2. Group chat <a href="#id-2" id="id-2"></a>

* **Multiple participants**: you can create a group chat that many people can participate in to share information and enhance communication within the team.
* **Manage channel**: the admin can add or delete members through the group chat, and adjust the group settings.

### 3. File sharing <a href="#id-3" id="id-3"></a>

* **Supporting various file formats**: you can easily share files in diverse formats such as texts, images, videos, and documents through the chat.
* **Safe file storage**: Game Chat saves and manages files in your Object Storage, preventing any information leaks.

### 4. Message search <a href="#id-4" id="id-4"></a>

* **Keywords search**: you can use a specific keyword to search for the past conversation content in the chat.
* **Advanced filter options**: you can quickly find the messages you want to search for by applying various filters, such as date, participant, and file format.

### 5. Notification adjustments <a href="#id-5" id="id-5"></a>

* **Push notifications**: when a new message or an important update occurs, a notification is sent to the user to prevent information omission.
* **Notification setting**: you can adjust the type and frequency of notification to receive the information in a desired way.

### 6. Security and personal information protection <a href="#id-6" id="id-6"></a>

* **Data encryption**: all messages are encrypted during transmission and storage to prevent data leaks from the outside.
* **Protecting personal information**: personal information and dialogs of the user are strictly protected, and are not disclosed to any third party without the consent of the user.

The message function of Game Chat promotes easy and efficient communication of the user, and has an important role in business and daily life. These functions promote easy user communication, and enhance teamwork.

## Forward message <a href="#undefined" id="undefined"></a>

If you have created and joined a channel, you can send a new message by calling the following:

```csharp
const message = 'Hello !!!';
await nc.sendMessage(
        channelId: CHANNEL_ID,
        type:"text",
        content: message
);


// When replying to a message
await nc.sendMessage(
        channelId: CHANNEL_ID,
        type:"text",
        content: message,
        parentMessageId: [MESSAGE_ID]
        );

// When an automatic translation is required for a message
await nc.sendMessage(
        channelId: CHANNEL_ID,
        type:"text",
        content: message,
        translate: true
        );

// In a new message, the contents of the parent message are reinforced and sent with parent_message as shown below.
{
    "id": "message_id",
    "text": "Message",
    "parent_message_id": "first_message_id",
    "parent_message": {
        "id": "message_id",
        "text": "message_name",
        "sender" : {
            "id" : "Sender",
             "name" : "Sender Nickname",
             "profile" : "profile url"
        }
    }
}
```

> Note
>
> If you send/receive messages in JSON format, you can use various user-defined values.

```csharp
Hashtable messageArray = new Hashtable
{
    { "channel_id", "channelId" },
    { "state", 1 },
    { "desc" , "Desc" }
};
// Convert the message to plain text.
const jsonString = JsonConvert.SerializeObject(messageArray);
// Convert the received message to an array.
Hashtable hashtable = JsonConvert.DeserializeObject<Hashtable>(jsonString);
```

<table><thead><tr><th width="177">ID</th><th width="96">Type</th><th>Description</th></tr></thead><tbody><tr><td>CHANNEL_ID</td><td>string</td><td>Channel ID</td></tr><tr><td>type</td><td>string</td><td>Type of the message to send (text or image)</td></tr><tr><td>MESSAGE</td><td>string</td><td>Transfer message text; can be used in various ways if utilizing JSON String</td></tr><tr><td>MENTIONS</td><td>array</td><td>ID of the user to mention</td></tr></tbody></table>

* Using Express Message: this function is only for sending messages at high speed. By removing all parts that may cause a delay, messages can be transferred 10 times faster than with the previous method. The difference from normal sendMessage is as follows:

<table><thead><tr><th width="212">Function</th><th width="230">Description</th><th width="95">Filtering</th><th width="86">Block</th><th>Translate</th></tr></thead><tbody><tr><td>sendMessage</td><td>Send normal messages</td><td>O</td><td>O</td><td>O</td></tr><tr><td>sendExpressMessage</td><td>Send express messages</td><td>X</td><td>X</td><td>X</td></tr></tbody></table>

Available to use for any service that requires real-time PvP production or high-speed broadcasting within the game.

## Upload files <a href="#undefined" id="undefined"></a>

* You can transfer files to a specific channel.
* You can only upload allowed file types by navigating to Dashboard > Settings > Security.

```csharp
await nc.sendFile([CHANNEL_ID],file);
```

<table><thead><tr><th width="220">ID</th><th width="187">Type</th><th>Description</th></tr></thead><tbody><tr><td>CHANNEL_ID</td><td>string</td><td>Channel ID</td></tr><tr><td>file</td><td>string</td><td>File information</td></tr></tbody></table>

> Note
>
> * Object Storage must be enabled.
> * You can use it after integrating with the [Object Storage](https://www.ncloud.com/product/storage/objectStorage) product.
> * When uploading, set the upload type and upload size, etc. in **Set Project > Security Settings** in the dashboard.
> * Supported file types: all general types such as images, videos, documents, and zips are supported. For an extension that needs to be supported additionally, send inquiries through Contact us, and we will add it after reviewing its security.
> * When using the file link, the Endpoint address is <https://apps.ncloudchat.naverncp.com.\\>
>   For example, <https://apps.ncloudchat.naverncp.com/archive/\\[archiveId>]

## Message information <a href="#undefined" id="undefined"></a>

* Message Data Class

<table><thead><tr><th width="239">ID</th><th width="132">Type</th><th>Description</th></tr></thead><tbody><tr><td>id</td><td>string</td><td>ID (unique)</td></tr><tr><td>message_id</td><td>string</td><td>Message ID</td></tr><tr><td>sort_id</td><td>string</td><td>ID for sorting messages</td></tr><tr><td>message_type</td><td>string</td><td>Message type</td></tr><tr><td>sender.id</td><td>string</td><td>Sender ID</td></tr><tr><td>sender.name</td><td>string</td><td>Sender name</td></tr><tr><td>sender.profile</td><td>string</td><td>Sender's profile image</td></tr><tr><td>metions</td><td>string</td><td>List of mentions</td></tr><tr><td>metions_everyone</td><td>string</td><td>Whether everyone's mentioned</td></tr><tr><td>content</td><td>string</td><td>Message</td></tr><tr><td>created_at</td><td>string</td><td>Creation date</td></tr><tr><td>sended_at</td><td>string</td><td>Sent date</td></tr></tbody></table>

### Individual message information <a href="#undefined" id="undefined"></a>

You can get information about individual messages.

```csharp
NBaseSDK.Message message = await nc.getMessage([CHANNEL_ID], [MESSAGE_ID]);
```

### All messages information <a href="#undefined" id="undefined"></a>

You can get information on all messages.

```csharp
Hashtable filter = new Hashtable
{
    { "channel_id", [CHANNEL_ID] }
};
Hashtable sort = new Hashtable
{
    { "sort_id", -1 }
};
Hashtable option = new Hashtable
{
    { "offset", 0 },
    { "per_page", 10 }
};
var messages = await nc.getMessages(filter, sort, option);
if (messages != null)
    {
            foreach (var message in messages.edges)
        {
            string id = message.Node.message_id.ToString();
            Console.WriteLine("[CloudChatSample] id={0}", id);
        }
    }
```

* Parameters

<table><thead><tr><th width="99">ID</th><th width="89">Type</th><th width="461">Description</th><th>Required</th></tr></thead><tbody><tr><td>filter</td><td>object</td><td>Search is available for all fields of a query through filtering</td><td>O</td></tr><tr><td>sort</td><td>object</td><td>Define a filter for the fields you want to sort</td><td>X</td></tr><tr><td>option</td><td>object</td><td>See the following when there are options</td><td>X</td></tr></tbody></table>

* Filter

  <table><thead><tr><th>ID</th><th width="207">Type</th><th>Description</th></tr></thead><tbody><tr><td>message_id</td><td>String</td><td>Message ID</td></tr><tr><td>channel_id</td><td>String</td><td>Channel ID</td></tr><tr><td>sort_id</td><td>String</td><td>Sort ID</td></tr><tr><td>message_type</td><td>String</td><td>Message Type입</td></tr><tr><td>embedProviders</td><td>String</td><td>Embed Provider</td></tr><tr><td>isExpress</td><td>Boolean</td><td>Immediate Message Status</td></tr><tr><td>bytes</td><td>Int</td><td>Message Byte Size</td></tr><tr><td>content</td><td>String</td><td>Message Content</td></tr><tr><td>sended_at</td><td>String</td><td>Message Send Time</td></tr><tr><td>created_at</td><td>String</td><td>Message Creation Time</td></tr></tbody></table>
* Sotr

  <table><thead><tr><th width="201">ID</th><th width="151">Type</th><th>Description</th></tr></thead><tbody><tr><td>created_at</td><td>number</td><td>Creation Date (Ascending '1', Descending '-1')</td></tr></tbody></table>
* Options

<table><thead><tr><th width="175">ID</th><th width="178">Type</th><th>Description</th></tr></thead><tbody><tr><td>offset</td><td>number</td><td>Start offset</td></tr><tr><td>per_page</td><td>number</td><td>Number of items returned (up to 100)</td></tr></tbody></table>

## Unread messages <a href="#undefined" id="undefined"></a>

Return the number of unread messages. Send the information of the last read message through markRead first.

```csharp
nc.markRead([CHANNEL_ID], new NBaseSDK.MarkInput
{
    user_id = USER_ID,
    message_id = MESSAGE_ID,
    sort_id = SORT_ID
});
// Return the number of unread messages after being marked.
var unread = nc.unreadCount([CHANNEL_ID]);
```

<table><thead><tr><th width="192">ID</th><th width="110">Type</th><th>Description</th></tr></thead><tbody><tr><td>USER_ID</td><td>string</td><td>Enter the user_id contained in the message</td></tr><tr><td>MESSAGE_ID</td><td>string</td><td>Enter the message_id contained in the message</td></tr><tr><td>SORT_ID</td><td>string</td><td>Enter the sort_id contained in the message</td></tr></tbody></table>

## Delete message <a href="#undefined" id="undefined"></a>

You can delete messages you sent within the channel.

```csharp
await nc.deleteMessage([CHANNEL_ID], [MESSAGE_ID]);
```

* Parameters

| ID          | Type   | Description |
| ----------- | ------ | ----------- |
| CHANNEL\_ID | string | Channel ID  |
| MESSAGE\_ID | string | Message ID  |
