添加开关是否开启允许@不在会话中的机器人

This commit is contained in:
heavyrian2012
2025-09-06 23:29:09 +08:00
parent 06d168935d
commit fe15a32499
6 changed files with 32 additions and 3 deletions
+4
View File
@@ -170,6 +170,10 @@ robot.callback_with_sender_info false
## 机器人回调信息是否带上目标的信息,单聊时是对方用户信息,群聊时是群组信息,频道时是频道信息
robot.callback_with_target_info false
## 是否允许@会话外的机器人。如果为true,单聊或者群聊时,可以@不在会话中的机器人。当机器人收到消息后,可以回复消息。
## 如果为false,不能@不在会话中的机器人。机器人不在会话中时,也不能回复消息。
robot.mention_external_robot true
## 频道回调信息是否带上用户clientId和平台类型。
channel.callback_with_client_info false
@@ -55,6 +55,15 @@ public class ReplyMessageAction extends RobotAction {
errorCode = ErrorCode.ERROR_CODE_NOT_IMPLEMENT;
} else if(System.currentTimeMillis() - message.getServerTimestamp() > 15*60*1000) {
errorCode = ErrorCode.ERROR_CODE_RECALL_TIME_EXPIRED;
} else if(!messagesStore.isRobotMentionExternalRobot()) {
if(message.getConversation().getType() != ProtoConstants.ConversationType.ConversationType_Group) {
errorCode = ErrorCode.ERROR_CODE_NOT_IMPLEMENT;
} else {
WFCMessage.GroupMember member = messagesStore.getGroupMember(message.getConversation().getTarget(), robot.getUid());
if(member == null || member.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Removed) {
errorCode = ErrorCode.ERROR_CODE_NOT_IMPLEMENT;
}
}
}
if(errorCode != null) {
@@ -173,6 +173,8 @@ public final class BrokerConstants {
public static final String ROBOT_Callback_With_Client_Info = "robot.callback_with_client_info";
public static final String ROBOT_Callback_With_Sender_Info = "robot.callback_with_sender_info";
public static final String ROBOT_Callback_With_Target_Info = "robot.callback_with_target_info";
public static final String ROBOT_Mention_External_Robot = "robot.mention_external_robot";
public static final String CHANNEL_Callback_With_Client_Info = "channel.callback_with_client_info";
public static final String CHANNEL_Callback_With_Sender_Info = "channel.callback_with_sender_info";
@@ -213,6 +213,7 @@ public class MemoryMessagesStore implements IMessagesStore {
private boolean mRobotCallbackWithClientInfo = false;
private boolean mRobotCallbackWithSenderInfo = false;
private boolean mRobotCallbackWithTargetInfo = false;
private boolean mRobotMentionExternalRobot = false;
private boolean mChannelCallbackWithClientInfo = false;
private boolean mChannelCallbackWithSenderInfo = false;
@@ -646,6 +647,9 @@ public class MemoryMessagesStore implements IMessagesStore {
try {
mRobotCallbackWithTargetInfo = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.ROBOT_Callback_With_Target_Info, "false"));
} catch (Exception e) {}
try {
mRobotMentionExternalRobot = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.ROBOT_Mention_External_Robot, "false"));
} catch (Exception e) {}
try {
mChannelCallbackWithClientInfo = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.CHANNEL_Callback_With_Client_Info, "false"));
@@ -741,7 +745,7 @@ public class MemoryMessagesStore implements IMessagesStore {
int type = message.getConversation().getType();
int pullType = ProtoConstants.PullType.Pull_Normal;
if (type == ProtoConstants.ConversationType.ConversationType_Private) {
if (mRobotMentionExternalRobot && type == ProtoConstants.ConversationType.ConversationType_Private) {
if(message.getConversation().getTarget().contains("|")) {
String[] ss = message.getConversation().getTarget().split("\\|");
notifyReceivers.add(ss[0]);
@@ -761,7 +765,7 @@ public class MemoryMessagesStore implements IMessagesStore {
notifyReceivers.add(message.getConversation().getTarget());
}
}
if (message.getContent().getMentionedTargetCount() > 0) {
if (mRobotMentionExternalRobot && message.getContent().getMentionedTargetCount() > 0) {
for (String mentioned : message.getContent().getMentionedTargetList()) {
if (!notifyReceivers.contains(mentioned)) {
WFCMessage.User user = getUserInfo(mentioned);
@@ -799,7 +803,7 @@ public class MemoryMessagesStore implements IMessagesStore {
}
}
}
if (message.getContent().getMentionedTargetCount() > 0) {
if (mRobotMentionExternalRobot && message.getContent().getMentionedTargetCount() > 0) {
for (String mentioned : message.getContent().getMentionedTargetList()) {
if (!notifyReceivers.contains(mentioned)) {
WFCMessage.User user = getUserInfo(mentioned);
@@ -4922,6 +4926,11 @@ public class MemoryMessagesStore implements IMessagesStore {
return mRobotCallbackWithTargetInfo;
}
@Override
public boolean isRobotMentionExternalRobot() {
return mRobotMentionExternalRobot;
}
@Override
public boolean isChannelCallbackWithClientInfo() {
return mChannelCallbackWithClientInfo;
@@ -254,6 +254,7 @@ public interface IMessagesStore {
boolean isRobotCallbackWithClientInfo();
boolean isRobotCallbackWithSenderInfo();
boolean isRobotCallbackWithTargetInfo();
boolean isRobotMentionExternalRobot();
boolean isChannelCallbackWithClientInfo();
boolean isChannelCallbackWithSenderInfo();
@@ -167,6 +167,10 @@ robot.callback_with_sender_info false
## 机器人回调信息是否带上目标的信息,单聊时是对方用户信息,群聊时是群组信息,频道时是频道信息
robot.callback_with_target_info false
## 是否允许@会话外的机器人。如果为true,单聊或者群聊时,可以@不在会话中的机器人。当机器人收到消息后,可以回复消息。
## 如果为false,不能@不在会话中的机器人。机器人不在会话中时,也不能回复消息。
robot.mention_external_robot true
## 频道回调信息是否带上用户clientId和平台类型。
channel.callback_with_client_info false