跳轉至

訊息

Hive 聊天功能支持 頻道消息發送,以向用戶參與的頻道發送消息,以及 1:1 消息發送,以直接向特定個人發送消息。

頻道訊息發送

要向用户参与的频道发送消息,请创建一个 ChannelSendMessageParams 对象,然后将其作为参数传递给 Chat 类的 sendMessage() 方法以调用它。

Channelsendmessageparams

欄位名稱 描述 類型 必填
channelId 發送頻道消息的頻道 ID 字串
message 要發送到頻道的消息
(最多 200 個字符)
字串

這是一段示範程式碼,用於向用戶參與的頻道發送消息。

using hive;

ChannelSendMessageParams channelSendMessageParams = new ChannelSendMessageParams();
channelSendMessageParams.channelId = "CHANNEL_ID";
channelSendMessageParams.message = "你好 Hive";

Chat.sendMessage(channelSendMessageParams);
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

ChannelSendMessageParams params;
params.channelId = "CHANNEL_ID";
params.message = "Hello Hive";

Chat::sendMessageWithChannelSendMessageParams(params, [=](ResultAPI const & result) {
    if (result.isSuccess()) {
        // API Call Success
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val params = Chat.ChannelSendMessageParams(
    channelId = "CHANNEL_ID",
    message = "你好 Hive"
)
Chat.sendMessage(params)
import com.hive.Chat;

Chat.ChannelSendMessageParams params = new Chat.ChannelSendMessageParams(
    "CHANNEL_ID",
    "Hello Hive"
);

Chat.sendMessage(params);
import HIVEService

let params = HiveChatParams.ChannelSendMessageParams(
    channelId = "CHANNEL_ID",
    message = "Hello Hive"
)
ChatInterface.sendMessage(params)
#import "HIVEService.h"

HiveChatChannelSendMessageParams* sendMessageParams = [[HiveChatChannelSendMessageParams alloc] init];
sendMessageParams.channelId = "CHANNEL_ID";
sendMessageParams.message = "Hello Hive";

[HiveChat sendMessageWithChannelSendMessageParams:sendMessageParams handler:nil];

頻道消息事件管理

發送的消息可以被onChannelMessage事件處理程序接收,該事件由addChannelListener事件觸發。有關事件處理的更多詳細信息,請參閱事件管理 > 通道事件文檔。

1:1 訊息發送

要向特定收件人發送直接消息,使用者創建一個 DirectSendMessageParams 物件,然後將其作為參數傳遞給 Chat 類的 sendMessage() 方法。

直接發送消息參數

欄位名稱 描述 類型 必填
toPlayerId 目標用戶的 Hive 玩家 ID long Y
message 要發送到頻道的訊息
(最多 200 個字元)
string Y

以下是一個用戶向特定收件人發送直接消息的示例代碼。

using hive;

DirectSendMessageParams directSendMessageParams = new DirectSendMessageParams();
directSendMessageParams.toPlayerId = 12345678;
directSendMessageParams.message = "Hello Hive";

Chat.sendMessage(directSendMessageParams);
import com.hive.Chat;
import com.hive.ResultAPI;

val params = Chat.DirectSendMessageParams(
    toPlayerId = 12345678,
    message = message
)

Chat.sendMessage(params)
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

DirectSendMessageParams params;
params.toPlayerId = 12345678;
params.message = "Hello Hive";

Chat::sendMessageWithDirectSendMessageParams(params);
import com.hive.Chat;

Chat.DirectSendMessageParams params = new Chat.DirectSendMessageParams(
        12345678,
        "Hello Hive"
);

Chat.sendMessage(params);
import HIVEService

let params = HiveChatParams.DirectSendMessageParams(toPlayerId: Int64(12345678), message: "Hello Hive")

ChatInterface.sendMessage(sendMessageParams: params)
#import "HIVEService.h"

HiveChatDirectSendMessageParams* sendMessageParams = [[HiveChatDirectSendMessageParams alloc] init];
sendMessageParams.toPlayerId = 12345678;
sendMessageParams.message = "你好 Hive";

[HiveChat sendDirectMessageWithSendMessageParams:sendMessageParams handler:nil];

1:1 消息事件管理

透過 1:1 訊息傳輸發送的訊息可以通過 addDirectMessageListener 事件處理器 onDirectMessage 事件接收。欲了解詳細的事件處理方法,請參閱 事件管理 > 1:1 訊息事件 文件。