# 消息功能

## 消息功能

Game Chat 提供的消息功能包括支持用户间有效沟通的多种服务。该平台适用于个人对话以及群组对话，使发送和接收消息的过程变得简单快捷。以下是 Game Chat 的主要消息功能及其特点：

### 1. **即时消息**

* **实时沟通**：用户可以实时发送和接收消息，从而将沟通延迟降至最低。
* **多设备支持**：用户可以在智能手机、平板电脑、PC 等多种设备上进行消息的发送和接收。

### 2. **群组聊天**

* **多个参与者**：用户可以创建多个参与者的群组聊天，以便共享信息并简化团队内部的沟通。
* **频道管理**：管理员可以通过群组聊天添加或删除成员，并调整群组的设置。

### 3. **文件共享**

* **支持多种文件格式**：可以通过聊天轻松共享文本、图片、视频、文档等多种格式的文件。
* **安全的文件存储**：Ncloud Chat 将文件保存在客户拥有的 Object Storage 中，从而防止信息外泄。

### 4. **消息搜索**

* **关键词搜索**：在聊天中使用特定关键词来搜索过去的对话内容。
* **高级过滤选项**：可以应用日期、参与者、文件类型等各种过滤器，以快速找到所需的消息。

### **5. 通知与通知调整**

* **推送通知**：当有新消息或重要更新时，会向用户发送通知，以防止信息遗漏。
* **通知设置**：用户可以调整通知的类型和频率，以便以所需的方式接收信息。

### **6. 安全与隐私保护**

* **数据加密**：所有消息在传输和存储过程中都进行加密，以防止数据泄露。
* **隐私保护**：用户的个人信息和对话内容受到严格保护，未经用户同意不会向第三方公开。

Game Chat 的消息功能使用户的沟通变得顺畅和高效，在工作和日常生活中发挥了重要作用。这些功能帮助用户更轻松地进行沟通，并在增强团队合作方面做出了巨大贡献。

## 消息传递

创建并加入频道后，可以通过以下方式发送新消息。

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


// 回复消息时
await nc.sendMessage(
        channelId: CHANNEL_ID, 
        type:"text", 
        content: message, 
        parentMessageId: [MESSAGE_ID]
        );

// 如果需要对消息进行自动翻译
await nc.sendMessage(
        channelId: CHANNEL_ID, 
        type:"text", 
        content: message, 
        translate: true
        );

// 在新消息中，通过以下方式补充父消息的内容，并传递 parent_message。
{
    "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"
        }
    }
}
```

> 备注
>
> 消息以 JSON 格式发送/接收，可以使用各种自定义值。

```csharp
Hashtable messageArray = new Hashtable
{
    { "channel_id", "channelId" },
    { "state", 1 },
    { "desc" , "Desc" }
};
// 将消息转换为普通文本。
const jsonString = JsonConvert.SerializeObject(messageArray);
// 将接收到的消息转换为数组。
Hashtable hashtable = JsonConvert.DeserializeObject<Hashtable>(jsonString);
```

<table><thead><tr><th width="195">ID</th><th width="100">Type</th><th>Description</th></tr></thead><tbody><tr><td>CHANNEL_ID</td><td>string</td><td>频道 ID</td></tr><tr><td>type</td><td>string</td><td>发送的消息类型(text, image)</td></tr><tr><td>MESSAGE</td><td>string</td><td>发送消息时，可以使用文本或 JSON 字符串以实现多种用途。</td></tr><tr><td>MENTIONS</td><td>array</td><td>提及的用户 ID</td></tr></tbody></table>

* 使用 Express Message \
  Express Message 函数专门用于快速发送消息。它跳过所有可能导致时间延迟的部分，使消息发送速度比常规 sendMessage 快 10 倍。其与常规 sendMessage 的区别如下：

<table><thead><tr><th width="209">Function</th><th width="165">Description</th><th>过滤</th><th>屏蔽</th><th>翻译</th></tr></thead><tbody><tr><td>sendMessage</td><td>常规消息发送</td><td>O</td><td>O</td><td>O</td></tr><tr><td>sendExpressMessage</td><td>快速消息发送</td><td>X</td><td>X</td><td>X</td></tr></tbody></table>

可以用于游戏中的实时 PvP 制作或任何需要高速广播的服务。

## 文件上传

* 您可以将文件发送到特定的频道。
* 在大屏幕中选择设置 > 安全 > 允许的文件类型，仅允许上传被允许的文件类型。

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

| ID          | Type   | Description |
| ----------- | ------ | ----------- |
| CHANNEL\_ID | string | 频道 ID       |
| file        | string | 文件信息        |

> 备注
>
> * 必须启用对象存储功能。
> * 仅在与[对象存储](https://www.ncloud.com/product/storage/objectStorage)服务集成后可以使用。
> * 在上传时，请在大屏幕项目设置 > 安全设置中配置上传类型和上传大小等设置。
> * 支持的文件类型：支持所有常见类型，包括图像、视频、文档、压缩文件等。如需支持额外的扩展名，请通过“<cs@nbase.io>”进行询问，我们会在安全审查后添加支持。
> * 使用文件链接时，端点地址为 <https://apps.ncloudchat.naverncp.com。> 例如: <https://apps.ncloudchat.naverncp.com/archive/\\[archiveId>]

## 消息信息 <a href="#undefined" id="undefined"></a>

* Message Data Class

<table><thead><tr><th width="269">ID</th><th width="170">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>消息 ID</td></tr><tr><td>sort_id</td><td>string</td><td>消息排序 ID</td></tr><tr><td>message_type</td><td>string</td><td>消息类型</td></tr><tr><td>sender.id</td><td>string</td><td>发件人 ID</td></tr><tr><td>sender.name</td><td>string</td><td>发件人姓名</td></tr><tr><td>sender.profile</td><td>string</td><td>发件人头像</td></tr><tr><td>metions</td><td>string</td><td>提及列表</td></tr><tr><td>metions_everyone</td><td>string</td><td>是否全体提及</td></tr><tr><td>content</td><td>string</td><td>消息内容</td></tr><tr><td>created_at</td><td>string</td><td>创建日期</td></tr><tr><td>sended_at</td><td>string</td><td>发送日期</td></tr></tbody></table>

### 单条消息信息

可以获取单条消息的详细信息。

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

### 全部消息信息

可以获取所有消息的详细信息。

```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="161">ID</th><th width="113">Type</th><th width="346">Description</th><th>Required</th></tr></thead><tbody><tr><td>filter</td><td>object</td><td>可以对所有字段进行搜索。</td><td>O</td></tr><tr><td>sort</td><td>object</td><td>定义要排序字段的过滤器</td><td>X</td></tr><tr><td>option</td><td>object</td><td>如有可选项，请参阅下方参考内容。</td><td>X</td></tr></tbody></table>

* Options

<table><thead><tr><th width="200">ID</th><th width="160">Type</th><th>Description</th></tr></thead><tbody><tr><td>offset</td><td>number</td><td>起始 offset</td></tr><tr><td>per_page</td><td>number</td><td>返回的数量（最多 100 个）</td></tr></tbody></table>

## 未读消息

返回未读消息的数量。 \
首先通过 markRead 传递最后一条已读消息的信息。

```csharp
nc.markRead([CHANNEL_ID], new NBaseSDK.Mark 
{
    user_id = USER_ID, 
    message_id = MESSAGE_ID,
    sort_id = SORT_ID
});
// 返回标记之后的所有未读消息的总数。
var unread = nc.unreadCount([CHANNEL_ID]);
```

<table><thead><tr><th width="219">ID</th><th width="188">Type</th><th>Description</th></tr></thead><tbody><tr><td>USER_ID</td><td>string</td><td>消息中包含的 user_id 输入</td></tr><tr><td>MESSAGE_ID</td><td>string</td><td>消息中包含的 message_id 输入</td></tr><tr><td>SORT_ID</td><td>string</td><td>消息中包含的 sort_id 输入</td></tr></tbody></table>

## 消息删除

可以删除我在该频道内发送的消息。

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

* Parameters

| ID          | Type   | Description |
| ----------- | ------ | ----------- |
| CHANNEL\_ID | string | 频道 ID       |
| MESSAGE\_ID | string | 消息 ID       |


---

# 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://docs.gamechat.me/basics/game-chat-v3/game-chat-zhong-wen/kai-shi-shi-yong-v3/xiao-xi-gong-neng.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.
