訊息¶
聊天功能支援向使用者已加入的頻道傳送頻道訊息,以及向特定對象直接傳送私訊。
傳送頻道訊息¶
若要向已加入的頻道傳送訊息,請建立ChannelSendMessageParams物件,並作為參數呼叫Chat類別的sendMessage()方法。
sendMessage() 方法返回傳輸結果以及用於發送的 ChannelSendMessageParams 作為 retryParam。 如果傳輸失敗,您可以嘗試使用 retryParams 重新發送。
Channelsendmessageparams¶
ChannelSendMessageParams物件指定目標頻道、訊息內容、回覆對象及提及對象。
| 字段名稱 | 描述 | 類型 | 必填 |
|---|---|---|---|
| channelId | 訊息傳送目標頻道ID | string | Y |
| message | 要發送到頻道的消息 (最多200個字符) | 字串 | 是 |
| extraData | 頻道訊息附加資訊 以UTF-8計,最多256位元組 | string | N |
| replyMessageId | 正在回覆的消息ID | 字串 | 否 |
| mentionedPlayerIds | 提及對象的Hive Player ID | list <long> | N |
此範例向已加入的頻道傳送基本訊息。
using hive;
ChannelSendMessageParams channelSendMessageParams = new ChannelSendMessageParams();
channelSendMessageParams.channelId = "CHANNEL_ID";
channelSendMessageParams.message = "你好 Hive";
channelSendMessageParams.extraData = "EXTRA_DATA";
Chat.sendMessage(channelSendMessageParams, (ResultAPI result, ChannelSendMessageParams retryParams) => {
if (!result.isSuccess()) {
// 發送消息失敗,嘗試使用 `retryParams` 重新發送
}
});
#include "HiveChat.h"
FHiveChatChannelSendMessageParams ChannelSendMessageParams;
ChannelSendMessageParams.ChannelId = TEXT("CHANNEL_ID");
ChannelSendMessageParams.Message = TEXT("你好 Hive");
ChannelSendMessageParams.ExtraData = TEXT("EXTRA_DATA");
FHiveChat::SendMessageWithChannelSendMessageParams(ChannelSendMessageParams, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FHiveChatChannelSendMessageParams& RetryParams) {
if (!Result.IsSuccess) {
// 消息发送失败,尝试使用`RetryParams`重新发送
}
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;
ChannelSendMessageParams params;
params.channelId = "CHANNEL_ID";
params.message = "你好 Hive";
params.extraData = "EXTRA_DATA";
Chat::sendMessageWithChannelSendMessageParams(params, [=](ResultAPI const & result, ChannelSendMessageParams const & retryParams) {
if (!result.isSuccess()) {
// Message Send Failed, Try resnding using `retryParams`
}
});
import com.hive.Chat;
import com.hive.ResultAPI;
val params = Chat.ChannelSendMessageParams(
channelId = "CHANNEL_ID",
message = "你好 Hive",
extraData = "EXTRA_DATA"
)
Chat.sendMessage(params, object: Chat.SendMessageListener {
override fun onResult(
result: ResultAPI,
retryParams: Chat.ChannelSendMessageParams?
) {
if (!result.isSuccess) {
// 訊息發送失敗,嘗試使用 `retryParams` 重新發送
}
}
})
#import "HIVEService.h"
HiveChatChannelSendMessageParams* sendMessageParams = [[HiveChatChannelSendMessageParams alloc] init];
sendMessageParams.channelId = "CHANNEL_ID";
sendMessageParams.message = "你好 Hive";
sendMessageParams.extraData = "EXTRA_DATA";
[HiveChat sendMessageWithChannelSendMessageParams:sendMessageParams handler:^(HIVEResultAPI * result, HiveChatChannelSendMessageParams * retryParams) {
if (![result isSuccess]) {
// 消息发送失败。尝试使用 `retryParams` 重新发送
}
}];
此範例回覆已加入頻道中的特定訊息。
using hive;
ChannelSendMessageParams channelSendMessageParams = new ChannelSendMessageParams();
channelSendMessageParams.channelId = "CHANNEL_ID";
channelSendMessageParams.message = "你好 Hive";
channelSendMessageParams.replyMessageId = "TARGET_MESSAGE_ID";
Chat.sendMessage(channelSendMessageParams, (ResultAPI result, ChannelSendMessageParams retryParams) => {
if (!result.isSuccess()) {
// 訊息發送失敗,嘗試使用 `retryParams` 重新發送
}
});
#include "HiveChat.h"
FHiveChatChannelSendMessageParams ChannelSendMessageParams;
ChannelSendMessageParams.ChannelId = TEXT("CHANNEL_ID");
ChannelSendMessageParams.Message = TEXT("你好 Hive");
ChannelSendMessageParams.ReplyMessageId = TEXT("TARGET_MESSAGE_ID");
FHiveChat::SendMessageWithChannelSendMessageParams(ChannelSendMessageParams, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FHiveChatChannelSendMessageParams& RetryParams) {
if (!Result.IsSuccess) {
// 消息发送失败,尝试使用 `RetryParams` 重新发送
}
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;
ChannelSendMessageParams params;
params.channelId = "CHANNEL_ID";
params.message = "你好 Hive";
params.replyMessageId = "TARGET_MESSAGE_ID";
Chat::sendMessageWithChannelSendMessageParams(params, [=](ResultAPI const & result, ChannelSendMessageParams const & retryParams) {
if (!result.isSuccess()) {
// Message Send Failed, Try resnding using `retryParams`
}
});
import com.hive.Chat;
import com.hive.ResultAPI;
val params = Chat.ChannelSendMessageParams(
channelId = "CHANNEL_ID",
message = "你好 Hive",
replyMessageId = "TARGET_MESSAGE_ID"
)
Chat.sendMessage(params, object: Chat.SendMessageListener {
override fun onResult(
result: ResultAPI,
retryParams: Chat.ChannelSendMessageParams?
) {
if (!result.isSuccess) {
// 訊息發送失敗,嘗試使用 `retryParams` 重新發送
}
}
})
import com.hive.Chat;
Chat.ChannelSendMessageParams params = new Chat.ChannelSendMessageParams(
"CHANNEL_ID",
"Hello Hive",
"EXTRA_DATA",
"TARGET_MESSAGE_ID"
);
Chat.sendMessage(params, (result, retryParams) -> {
if(!result.isSuccess()) {
// Message Send Failed, Try resending using `retryParams`
}
});
#import "HIVEService.h"
HiveChatChannelSendMessageParams* sendMessageParams = [[HiveChatChannelSendMessageParams alloc] init];
sendMessageParams.channelId = "CHANNEL_ID";
sendMessageParams.message = "你好 Hive";
sendMessageParams.replyMessageId = "TARGET_MESSAGE_ID";
[HiveChat sendMessageWithChannelSendMessageParams:sendMessageParams handler:^(HIVEResultAPI * result, HiveChatChannelSendMessageParams * retryParams) {
if (![result isSuccess]) {
// 消息发送失败。尝试使用 `retryParams` 重新发送
}
}];
此範例在已加入的頻道中傳送提及特定使用者的訊息。
using hive;
ChannelSendMessageParams channelSendMessageParams = new ChannelSendMessageParams();
channelSendMessageParams.channelId = "CHANNEL_ID";
channelSendMessageParams.message = "你好 Hive";
List<long> playerIds = new List<long>();
playerIds.Add(1234); // 使用者1的Hive Player ID
playerIds.Add(5678); // 使用者2的Hive Player ID
channelSendMessageParams.mentionedPlayerIds = playerIds;
Chat.sendMessage(channelSendMessageParams, (ResultAPI result, ChannelSendMessageParams retryParams) => {
if (!result.isSuccess()) {
// 訊息發送失敗,嘗試使用 `retryParams` 重新發送
}
});
#include "HiveChat.h"
FHiveChatChannelSendMessageParams ChannelSendMessageParams;
ChannelSendMessageParams.ChannelId = TEXT("CHANNEL_ID");
ChannelSendMessageParams.Message = TEXT("你好 Hive");
TArray<int64> PlayerIds;
PlayerIds.Add(1234); // 使用者1的Hive Player ID
PlayerIds.Add(5678); // 使用者2的Hive Player ID
ChannelSendMessageParams.MentionedPlayerIds = PlayerIds;
FHiveChat::SendMessageWithChannelSendMessageParams(ChannelSendMessageParams, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FHiveChatChannelSendMessageParams& RetryParams) {
if (!Result.IsSuccess) {
// 消息发送失败,尝试使用 `RetryParams` 重新发送
}
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;
ChannelSendMessageParams params;
params.channelId = "CHANNEL_ID";
params.message = "你好 Hive";
std::vector<int64_t> playerIds;
playerIds.push_back(1234); // 使用者1的Hive Player ID
playerIds.push_back(5678); // 使用者2的Hive Player ID
params.mentionedPlayerIds = playerIds;
Chat::sendMessageWithChannelSendMessageParams(params, [=](ResultAPI const & result, ChannelSendMessageParams const & retryParams) {
if (!result.isSuccess()) {
// Message Send Failed, Try resnding using `retryParams`
}
});
import com.hive.Chat;
import com.hive.ResultAPI;
val playerIds = listOf(1234L, 5678L) // 使用者1、2的Hive Player ID
val params = Chat.ChannelSendMessageParams(
channelId = "CHANNEL_ID",
message = "Hello Hive",
replyMessageId = "TARGET_MESSAGE_ID",
mentionedPlayerIds = playerIds
)
Chat.sendMessage(params, object: Chat.SendMessageListener {
override fun onResult(
result: ResultAPI,
retryParams: Chat.ChannelSendMessageParams?
) {
if (!result.isSuccess) {
// 訊息發送失敗,嘗試使用 `retryParams` 重新發送
}
}
})
import com.hive.Chat;
List<Long> mentionedPlayerIds = new ArrayList<>();
mentionedPlayerIds.add(1234L); // 使用者1的Hive Player ID
mentionedPlayerIds.add(5678L); // 使用者2的Hive Player ID
Chat.ChannelSendMessageParams params = new Chat.ChannelSendMessageParams(
"CHANNEL_ID",
"Hello Hive",
"EXTRA_DATA"
);
params.mentionedPlayerIds = mentionedPlayerIds;
Chat.sendMessage(params, (result, retryParams) -> {
if(!result.isSuccess()) {
// Message Send Failed, Try resending using `retryParams`
}
});
import HIVEService
var playerIds: [Int64] = [1234, 5678] // 使用者1、2的Hive Player ID
let params = HiveChatParams.ChannelSendMessageParams(
channelId = "CHANNEL_ID",
message = "Hello Hive",
mentionedPlayerIds = playerIds
)
ChatInterface.sendMessage(params) { result, retryParams in
if !result.isSuccess() {
// 訊息發送失敗,嘗試使用 `retryParams` 重新發送
}
}
#import "HIVEService.h"
HiveChatChannelSendMessageParams* sendMessageParams = [[HiveChatChannelSendMessageParams alloc] init];
sendMessageParams.channelId = @"CHANNEL_ID";
sendMessageParams.message = @"你好 Hive";
NSMutableArray<NSNumber *> *playerIds = [NSMutableArray array];
[playerIds addObject:@(1234)]; // 使用者1的Hive Player ID
[playerIds addObject:@(5678)]; // 使用者2的Hive Player ID
sendMessageParams.mentionedPlayerIds = playerIds;
[HiveChat sendMessageWithChannelSendMessageParams:sendMessageParams handler:^(HIVEResultAPI * result, HiveChatChannelSendMessageParams * retryParams) {
if (![result isSuccess]) {
// 訊息發送失敗。嘗試使用 `retryParams` 重新發送
}
}];
設定與清除頻道訊息反應¶
頻道訊息反應表示使用者對訊息的回應。使用setReaction()和clearReaction()設定或清除反應,並透過頻道事件接收變更以更新畫面。
反應類型透過1~200的reactionIndex區分。Hive僅傳遞編號。請在應用程式中定義各編號對應的表情、貼圖等含義。
設定反應的條件¶
使用者可對已加入頻道的訊息留下反應,每位使用者每則訊息僅能留下一個反應,不能對公告訊息留下反應。
對已留下反應的訊息使用不同編號呼叫setReaction()會替換原反應;使用相同編號則保持不變。clearReaction()無需指定編號即可清除自己的反應。
處理結果與事件¶
setReaction()和clearReaction()的結果不包含反應統計。變更透過onSetReaction和onClearReaction傳遞給所有頻道成員,也包括操作者本人。請接收事件並更新畫面的反應資訊。
替換反應時僅傳遞包含新編號的onSetReaction事件,不傳遞onClearReaction。請參閱事件管理 > 頻道事件。
區分按讚與反應統計¶
反應與按讚(Like)分別統計。同時使用時,一則訊息會同時存在兩種統計,應用程式需分別顯示。
設定與清除範例¶
此範例設定或清除已加入頻道中訊息的反應。
using hive;
String messageId = "TARGET_MESSAGE_ID";
int reactionIndex = 5; // 遊戲定義的反應編號(1~200)
// 設定反應(替換已有反應)
channel.setReaction(messageId, reactionIndex, (ResultAPI result) => {
if (result.isSuccess()) {
// API Call Success
}
});
// 清除反應
channel.clearReaction(messageId, (ResultAPI result) => {
if (result.isSuccess()) {
// API Call Success
}
});
#include "HiveChat.h"
FString MessageId = TEXT("TARGET_MESSAGE_ID");
int32 ReactionIndex = 5; // 遊戲定義的反應編號(1~200)
// 設定反應(替換已有反應)
channel.SetReaction(MessageId, ReactionIndex, FHiveChannelSetReactionDelegate([this](const FHiveResultAPI& Result) {
if (Result.IsSuccess()) {
// API Call Success
}
}));
// 清除反應
channel.ClearReaction(MessageId, FHiveChannelClearReactionDelegate([this](const FHiveResultAPI& Result) {
if (Result.IsSuccess()) {
// API Call Success
}
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;
std::string messageId = "TARGET_MESSAGE_ID";
int reactionIndex = 5; // 遊戲定義的反應編號(1~200)
// 設定反應(替換已有反應)
channel.setReaction(messageId, reactionIndex, [=](ResultAPI const & result) {
if (result.isSuccess()) {
// API Call Success
}
});
// 清除反應
channel.clearReaction(messageId, [=](ResultAPI const & result) {
if (result.isSuccess()) {
// API Call Success
}
});
import com.hive.Chat
import com.hive.ResultAPI
val messageId = "TARGET_MESSAGE_ID"
val reactionIndex = 5 // 遊戲定義的反應編號(1~200)
// 設定反應(替換已有反應)
channel.setReaction(messageId, reactionIndex, object: Chat.ReactionResultListener {
override fun onResult(result: ResultAPI, reactionIndex: Int) {
if (result.isSuccess) {
// API Call Success
}
}
})
// 清除反應
channel.clearReaction(messageId, object: Chat.ReactionResultListener {
override fun onResult(result: ResultAPI, reactionIndex: Int) {
if (result.isSuccess) {
// API Call Success
}
}
})
import com.hive.Chat;
import com.hive.ResultAPI;
String messageId = "TARGET_MESSAGE_ID";
int reactionIndex = 5; // 遊戲定義的反應編號(1~200)
// 設定反應(替換已有反應)
channel.setReaction(messageId, reactionIndex, new Chat.ReactionResultListener() {
@Override
public void onResult(@NonNull ResultAPI result, int reactionIndex) {
if (result.isSuccess()) {
// API Call Success
}
}
});
// 清除反應
channel.clearReaction(messageId, new Chat.ReactionResultListener() {
@Override
public void onResult(@NonNull ResultAPI result, int reactionIndex) {
if (result.isSuccess()) {
// API Call Success
}
}
});
import HIVEService
let messageId = "TARGET_MESSAGE_ID"
let reactionIndex = 5 // 遊戲定義的反應編號(1~200)
// 設定反應(替換已有反應)
channel.setReaction(messageId: messageId, reactionIndex: reactionIndex) { result in
if result.isSuccess() {
// API Call Success
}
}
// 清除反應
channel.clearReaction(messageId: messageId) { result in
if result.isSuccess() {
// API Call Success
}
}
#import "HIVEService.h"
NSString *messageId = @"TARGET_MESSAGE_ID";
NSInteger reactionIndex = 5; // 遊戲定義的反應編號(1~200)
// 設定反應(替換已有反應)
[channel setReactionWithMessageId:messageId reactionIndex:reactionIndex listener:^(HIVEResultAPI *result) {
if ([result isSuccess]) {
// API Call Success
}
}];
// 清除反應
[channel clearReactionWithMessageId:messageId listener:^(HIVEResultAPI *result) {
if ([result isSuccess]) {
// API Call Success
}
}];
查詢頻道訊息反應¶
在頻道訊息歷史查詢結果的各ChannelMessage中,透過messageReaction查看反應統計。反應較多時伺服器會簡化統計,因此需單獨查詢詳細資訊或自己的反應狀態。
簡化統計中simplified為true,各編號對應的Hive Player ID列表playerIds為空,但仍傳遞總數totalCount和各編號數量count。
選擇查詢方法¶
若要按編號查看訊息的全部反應,請呼叫getReactions()。此方法傳回包含Hive Player ID列表的MessageReaction,且simplified一律為false。
若要僅查看已登入使用者的反應,請呼叫getMyReaction(),此方法傳回PlayerReaction。可在重新連線後或歷史統計已簡化、無法確認自身反應時使用,不能查詢其他使用者的反應。
MessageReaction¶
訊息的完整反應統計。透過reactions查看各編號的統計,並保持伺服器傳遞的列表順序顯示。
| 欄位名稱 | 說明 | 類型 | 值與條件 |
|---|---|---|---|
| simplified | 是否簡化統計 | boolean | 為true時省略各編號的playerIds,僅傳遞count |
| totalCount | 訊息反應總數 | integer | 留下反應的使用者數 |
| reactions | 按反應編號統計的列表 | list<ReactionSummary> | 從最近新增的反應編號開始排序 |
ReactionSummary¶
特定反應編號對應的使用者數及Hive Player ID列表,作為MessageReaction.reactions中的各項傳遞。
| 欄位名稱 | 說明 | 類型 | 值與條件 |
|---|---|---|---|
| reactionIndex | 反應編號 | integer | 1~200 |
| count | 留下該反應的使用者數 | integer | 按該反應編號統計 |
| playerIds | 留下該反應的Hive Player ID列表 | list<long> | simplified為true時為空列表 |
PlayerReaction¶
表示已登入使用者是否對特定訊息留下反應。請先檢查reacted,再使用reactionIndex。
| 欄位名稱 | 說明 | 類型 | 值與條件 |
|---|---|---|---|
| messageId | 訊息ID | string | 查詢的訊息 |
| playerId | Hive Player ID | long | 已登入使用者 |
| reacted | 是否已留下反應 | boolean | 自己的反應狀態 |
| reactionIndex | 已留下的反應編號 | integer | 已留下時為1~200,未留下時的值不是有效編號 |
查詢反應範例¶
此範例查詢特定訊息的全部反應及自己的反應。
using hive;
String messageId = "TARGET_MESSAGE_ID";
// 查詢訊息的全部反應
channel.getReactions(messageId, (ResultAPI result, MessageReaction messageReaction) => {
if (result.isSuccess() && messageReaction != null) {
foreach (ReactionSummary summary in messageReaction.reactions) {
// summary.reactionIndex, summary.count, summary.playerIds
}
}
});
// 查詢自己的反應
channel.getMyReaction(messageId, (ResultAPI result, PlayerReaction playerReaction) => {
if (result.isSuccess() && playerReaction != null && playerReaction.reacted) {
// playerReaction.reactionIndex
}
});
#include "HiveChat.h"
FString MessageId = TEXT("TARGET_MESSAGE_ID");
// 查詢訊息的全部反應
channel.GetReactions(MessageId, FHiveChannelGetReactionsDelegate([this](const FHiveResultAPI& Result, const FHiveMessageReaction& MessageReaction) {
if (Result.IsSuccess()) {
for (const FHiveReactionSummary& Summary : MessageReaction.reactions) {
// Summary.reactionIndex, Summary.count, Summary.playerIds
}
}
}));
// 查詢自己的反應
channel.GetMyReaction(MessageId, FHiveChannelGetMyReactionDelegate([this](const FHiveResultAPI& Result, const FHivePlayerReaction& PlayerReaction) {
if (Result.IsSuccess() && PlayerReaction.reacted) {
// PlayerReaction.reactionIndex
}
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;
std::string messageId = "TARGET_MESSAGE_ID";
// 查詢訊息的全部反應
channel.getReactions(messageId, [=](ResultAPI const & result, MessageReaction const & messageReaction) {
if (result.isSuccess()) {
for (auto const & summary : messageReaction.reactions) {
// summary.reactionIndex, summary.count, summary.playerIds
}
}
});
// 查詢自己的反應
channel.getMyReaction(messageId, [=](ResultAPI const & result, PlayerReaction const & playerReaction) {
if (result.isSuccess() && playerReaction.reacted) {
// playerReaction.reactionIndex
}
});
import com.hive.Chat
import com.hive.ResultAPI
val messageId = "TARGET_MESSAGE_ID"
// 查詢訊息的全部反應
channel.getReactions(messageId, object: Chat.GetReactionsListener {
override fun onResult(result: ResultAPI, messageId: String, messageReaction: Chat.MessageReaction?) {
if (result.isSuccess && messageReaction != null) {
messageReaction.reactions.forEach { entry ->
// entry.reactionIndex, entry.count, entry.playerIds
}
}
}
})
// 查詢自己的反應
channel.getMyReaction(messageId, object: Chat.GetMyReactionListener {
override fun onResult(result: ResultAPI, playerReaction: Chat.PlayerReaction?) {
if (result.isSuccess && playerReaction?.reacted == true) {
// playerReaction.reactionIndex
}
}
})
import com.hive.Chat;
import com.hive.ResultAPI;
String messageId = "TARGET_MESSAGE_ID";
// 查詢訊息的全部反應
channel.getReactions(messageId, new Chat.GetReactionsListener() {
@Override
public void onResult(@NonNull ResultAPI result, @NonNull String messageId, Chat.MessageReaction messageReaction) {
if (result.isSuccess() && messageReaction != null) {
for (Chat.ReactionSummary entry : messageReaction.getReactions()) {
// entry.getReactionIndex(), entry.getCount(), entry.getPlayerIds()
}
}
}
});
// 查詢自己的反應
channel.getMyReaction(messageId, new Chat.GetMyReactionListener() {
@Override
public void onResult(@NonNull ResultAPI result, Chat.PlayerReaction playerReaction) {
if (result.isSuccess() && playerReaction != null && playerReaction.getReacted()) {
// playerReaction.getReactionIndex()
}
}
});
import HIVEService
let messageId = "TARGET_MESSAGE_ID"
// 查詢訊息的全部反應
channel.getReactions(messageId: messageId) { result, reaction in
if result.isSuccess(), let reaction {
reaction.reactions.forEach { summary in
// summary.reactionIndex, summary.count, summary.playerIds
}
}
}
// 查詢自己的反應
channel.getMyReaction(messageId: messageId) { result, reaction in
if result.isSuccess(), let reaction, reaction.reacted {
// reaction.reactionIndex
}
}
#import "HIVEService.h"
NSString *messageId = @"TARGET_MESSAGE_ID";
// 查詢訊息的全部反應
[channel getReactionsWithMessageId:messageId listener:^(HIVEResultAPI *result, HiveChatMessageReaction *reaction) {
if ([result isSuccess] && reaction) {
for (HiveChatReactionSummary *summary in reaction.reactions) {
// summary.reactionIndex, summary.count, summary.playerIds
}
}
}];
// 查詢自己的反應
[channel getMyReactionWithMessageId:messageId listener:^(HIVEResultAPI *result, HiveChatPlayerReaction *reaction) {
if ([result isSuccess] && reaction.reacted) {
// reaction.reactionIndex
}
}];
新增與移除頻道訊息按讚¶
addReaction()和removeReaction()用於新增或移除已加入頻道中訊息的按讚。這是使用ReactionType.Like的按讚專用功能,即將停止支援。
實作新反應功能時,請使用設定與清除反應中的setReaction()和clearReaction()。
此範例新增或移除已加入頻道中訊息的按讚。
using hive;
String messageId = "TARGET_MESSAGE_ID";
ReactionType type = ReactionType.Like;
channel.addReaction(messageId, type, (ResultAPI result, ReactionType reactionType) => {
if (result.isSuccess()) {
// API Call Success
}
});
channel.removeReaction(messageId, type, (ResultAPI result, ReactionType reactionType) => {
if (result.isSuccess()) {
// API Call Success
}
});
#include "HiveChat.h"
FString MessageId = TEXT("TARGET_MESSAGE_ID");
EReactionType Type = EReactionType::Like;
channel.AddReaction(MessageId, Type, FHiveChatOnReactionDelegate::CreateLambda([this](const FHiveResultAPI& Result, EReactionType Type) {
if (Result.IsSuccess()) {
// API Call Success
}
}));
channel.RemoveReaction(MessageId, Type, FHiveChatOnReactionDelegate::CreateLambda([this](const FHiveResultAPI& Result, EReactionType Type) {
if (Result.IsSuccess()) {
// API Call Success
}
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;
std::string messageId = "TARGET_MESSAGE_ID";
ReactionType type = ReactionType::Like;
channel.addReaction(messageId, type, [=](ResultAPI const & result, ReactionType type) {
if (result.isSuccess()) {
// API Call Success
}
});
channel.removeReaction(messageId, type, [=](ResultAPI const & result, ReactionType type) {
if (result.isSuccess()) {
// API Call Success
}
});
import com.hive.Chat;
import com.hive.ResultAPI;
val messageId = "TARGET_MESSAGE_ID"
val type = Chat.ReactionType.Like;
channel.addReaction(messageId, type, object: Chat.ReactionListener {
override fun onResult(result: ResultAPI, type: Chat.ReactionType) {
if (result.isSuccess()) {
// API Call Success
}
}
})
channel.removeReaction(messageId, type, object: Chat.ReactionListener {
override fun onResult(result: ResultAPI, type: Chat.ReactionType) {
if (result.isSuccess()) {
// API Call Success
}
}
})
import com.hive.Chat;
String messageId = "TARGET_MESSAGE_ID";
Chat.ReactionType type = Chat.ReactionType.Like;
Chat.addReaction(messageId, type, new Chat.ReactionListener() {
@Override
public void onResult(ResultAPI result, ReactionType type) {
if (result.isSuccess()) {
// API Call Success
}
}
});
Chat.removeReaction(messageId, type, new Chat.ReactionListener() {
@Override
public void onResult(ResultAPI result, ReactionType type) {
if (result.isSuccess()) {
// API Call Success
}
}
});
import HIVEService
let messageId = "TARGET_MESSAGE_ID"
let reactionType: ReactionType = .like
ChatInterface.addReaction(messageId: messageId, type: reactionType) { result, type in
if result.isSuccess() {
// API Call Success
}
}
ChatInterface.removeReaction(messageId: messageId, type: reactionType) { result, type in
if result.isSuccess() {
// API Call Success
}
}
#import "HIVEService.h"
NSString *messageId = @"TARGET_MESSAGE_ID";
HiveChatReactionType reactionType = HiveChatReactionTypeLike;
[channel addReactionWithMessageId:messageId type:reactionType handler:^(ResultAPI *result, HiveChatReactionType type) {
if ([result isSuccess]) {
// API Call Success
}
}];
[channel removeReactionWithMessageId:messageId type:reactionType handler:^(ResultAPI *result, HiveChatReactionType type) {
if ([result isSuccess]) {
// API Call Success
}
}];
頻道訊息事件管理¶
透過addChannelListener事件處理器的onChannelMessage事件接收已傳送訊息。請參閱事件管理 > 頻道事件。
直接訊息傳送¶
若要向特定對象傳送私訊,請建立DirectSendMessageParams物件,並作為參數呼叫Chat類別的sendMessage()方法。
sendMessage() 方法返回傳輸結果以及在傳輸過程中使用的 DirectSendMessageParams,名稱為 retryParam。 如果傳輸失敗,您可以嘗試使用 retryParams 重新發送。
直接發送消息參數¶
DirectSendMessageParams物件指定接收使用者及訊息內容。
| 欄位名稱 | 描述 | 類型 | 是否必填 |
|---|---|---|---|
| toPlayerId | 目標使用者的Hive Player ID | long | Y |
| message | 傳送給目標使用者的訊息 (最多200個字元) | string | Y |
| extraData | 私訊附加資訊 以UTF-8計,最多256位元組 | string | N |
此範例向特定對象直接傳送訊息。
using hive;
DirectSendMessageParams directSendMessageParams = new DirectSendMessageParams();
directSendMessageParams.toPlayerId = 12345678;
directSendMessageParams.message = "你好 Hive";
directSendMessageParams.extraData = "EXTRA_DATA";
Chat.sendMessage(directSendMessageParams, (ResultAPI result, DirectSendMessageParams retryParams) => {
if (!result.isSuccess()) {
// 訊息發送失敗,嘗試使用 `retryParams` 重新發送
}
});
#include "HiveChat.h"
FHiveChatDirectSendMessageParams DirectSendMessageParams = FHiveChatDirectSendMessageParams();
DirectSendMessageParams.ToPlayerId = 12345678l;
DirectSendMessageParams.Message = TEXT("Hello Hive");
DirectSendMessageParams.ExtraData = TEXT("EXTRA_DATA");
FHiveChat::SendMessageWithDirectSendMessageParams(DirectSendMessageParams, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FHiveChatDirectSendMessageParams& RetryParams) {
if (!Result.IsSuccess) {
// 訊息發送失敗,嘗試使用 `RetryParams` 重新發送
}
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;
DirectSendMessageParams params;
params.toPlayerId = 12345678;
params.message = "Hello Hive";
params.extraData = "EXTRA_DATA";
Chat::sendMessageWithDirectSendMessageParams(params, [=](ResultAPI const & result, DirectSendMessageParams const & retryParams) {
if (!result.isSuccess()) {
// 訊息發送失敗,嘗試使用 `retryParams` 重新發送
}
});
import com.hive.Chat;
import com.hive.ResultAPI;
val params = Chat.DirectSendMessageParams(
toPlayerId = 12345678,
message = "你好 Hive",
extraData = "EXTRA_DATA"
)
Chat.sendMessage(params, object: Chat.SendMessageListener {
override fun onResult(
result: ResultAPI,
retryParams: Chat.DirectSendMessageParams?
) {
if (!result.isSuccess) {
// 訊息發送失敗,嘗試使用 `retryParams` 重新發送
}
}
})
import HIVEService
let params = HiveChatParams.DirectSendMessageParams(toPlayerId: Int64(12345678), message: "Hello Hive", extraData: "EXTRA_DATA")
ChatInterface.sendMessage(sendMessageParams: params) { result, retryParams in
if !result.isSuccess() {
// Message Send Failed, Try resending using `retryParams`
}
}
#import "HIVEService.h"
HiveChatDirectSendMessageParams* sendMessageParams = [[HiveChatDirectSendMessageParams alloc] init];
sendMessageParams.toPlayerId = 12345678;
sendMessageParams.message = "你好 Hive";
sendMessageParams.extraData = "EXTRA_DATA";
[HiveChat sendDirectMessageWithSendMessageParams:sendMessageParams handler:^(HIVEResultAPI * result, HiveChatDirectSendMessageParams * retryParams) {
if (![result isSuccess]) {
// 消息发送失败。尝试使用 `retryParams` 重新发送
}
}];
直接訊息事件管理¶
透過addUserListener事件處理器的onDirectMessage事件接收私訊。請參閱事件管理 > 使用者事件。
訊息翻譯請求¶
嘗試請求該消息的翻譯。 語言代碼基於 ISO 639 alpha-2 標準。
翻譯參數¶
TranslateParams物件指定待翻譯訊息、來源語言及目標語言。
| 欄位名稱 | 描述 | 類型 | 必填 |
|---|---|---|---|
| message | 訊息 | 字串 | 是 |
| sourceLanguage | 訊息語言代碼。省略時使用auto偵測語言。 | string | N |
| targetLanguages | 目標語言代碼陣列 | string array | Y |
using hive;
List<String> targetLanguages = new List<String>();
targetLanguages.Add("ko");
targetLanguages.Add("ja");
targetLanguages.Add("ar");
TranslateParams translateParams = new TranslateParams("hello", "auto", targetLanguages);
Chat.translate(translateParams, (ResultAPI result, TranslationData data) => {
if (result.isSuccess() && data != null) {
// data is translate languages
}
});
#include "HiveChat.h"
TArray<FString> TargetLanguages;
TargetLanguages.Add(TEXT("ko"));
TargetLanguages.Add(TEXT("ja"));
TargetLanguages.Add(TEXT("ar"));
FHiveChatTranslateParams TranslateParams = FHiveChatTranslateParams(TEXT("你好"), TEXT("auto"), TargetLanguages);
FHiveChat::Translate(TranslateParams, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FHiveChatTranslationData& data) {
if (Result.ISSuccess && data != null) {
// data 是翻譯的語言消息
}
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;
std::vector<std::string> targetLanguages = { "ko", "ja", "ar" };
Chat::TranslateParams translateParams = new Chat::TranslateParams("hello", "auto", targetLanguages);
Chat::translate(translateParams, [=](ResultAPI const & result, Chat::TranslationData const & data) {
if (!result.isSuccess() && data != null ) {
// data is translate language messages
}
});
import com.hive.Chat;
import com.hive.ResultAPI;
var translateParams = Chat.TranslateParams(
message = "hello",
sourceLanguage = "auto",
targetLanguages = ["ko", "ja", "ar"]
)
Chat.translate(translateParams, object: Chat.TranslateParamsListener {
override fun onResult(
result: ResultAPI,
data: Chat.TranslationData?
) {
if (!result.isSuccess && data != null) {
// data is translate language maessages
}
}
})
#import "HIVEService.h"
NSArray<NSString *> *targetLanguages = @[@"ko", @"ja", @"ar"];
HiveChatTranslateParams translateParams = [[HiveChatTranslateParams alloc] message: @"hello"
sourceLanguage: @"auto"
targetLanguages: targetLanguages];
[HiveChat translateWithParams: translateParams
handler:^(HIVEResultAPI * result, HiveChatTranslationData * data) {
if ([result isSuccess] && data) {
// data is translate language messages
}
}];
頻道訊息檢舉¶
若要檢舉訊息,請建立ReportMessageParams物件,並作為參數呼叫Chat類別的reportMessage()方法。
ReportMessageParams¶
ReportMessageParams物件指定要檢舉的訊息、作者及檢舉原因。
| 欄位名稱 | 說明 | 類型 | 是否必填 |
|---|---|---|---|
| channelId | 要檢舉的訊息所在頻道 ID | string | Y |
| messageId | 要檢舉的訊息 ID | string | Y |
| reporteePlayerId | 被檢舉訊息作者的Hive Player ID | long | Y |
| reasonType | 檢舉原因 (INSULT, FRAUD, SPAM, ETC) | enum | Y |
| reasonDetail | 詳細檢舉原因(reasonType 為 ETC 時輸入,其他情況可填 null 或省略) | string | N |
基本檢舉請求範例¶
若因辱罵而檢舉訊息,請使用以下呼叫方式。
using hive;
ReportMessageParams reportMessageParams = new ReportMessageParams();
reportMessageParams.channelId = "abc";
reportMessageParams.messageId = "x8LIIIDbuVentUdL";
reportMessageParams.reporteePlayerId = 12345678;
reportMessageParams.reasonType = ReasonType.INSULT;
Chat.reportMessage(reportMessageParams, (ResultAPI result) => {
if (result.isSuccess()) {
// API Call Success
}
});
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;
ReportMessageParams reportMessageParams;
reportMessageParams.channelId = "abc";
reportMessageParams.messageId = "x8LIIIDbuVentUdL";
reportMessageParams.reporteePlayerId = 12345678;
reportMessageParams.reasonType = ReasonType.INSULT;
Chat::reportMessage(params, [=](ResultAPI const & result) {
if (result.isSuccess()) {
// API Call Success
}
});
val params = Chat.ReportMessageParam(
channelId = "abc",
messageId = "x8LIIIDbuVentUdL",
reporteePlayerId = 12345678,
reasonType = ReasonType.INSULT,
reasonDetail = null
)
Chat.reportMessage(params, object : Chat.ReportMessageListener {
override fun onResult(result: ResultAPI) {
if(result.isSuccess) {
// API Call Success
}
}
})
#import "HIVEService.h"
HiveChatReportMessageParams* reportMessageParams = [[HiveChatReportMessageParams alloc] init];
reportMessageParams.channelId = "abc";
reportMessageParams.messageId = "x8LIIIDbuVentUdL";
reportMessageParams.reporteePlayerId = 12345678;
reportMessageParams.reasonType = ReasonType.INSULT;
[HiveChat reportMessageWithReportMessageParams:reportMessageParams handler:^(HIVEResultAPI * result) {
if ([result isSuccess]) {
// API Call Success
}
}];
以其他原因檢舉¶
若選擇其他原因(reasonType 為 ETC)來檢舉訊息,請一併輸入詳細原因(reasonDetail)。若選擇預先定義的檢舉原因,則可將詳細原因留空或省略。