feat: 实现指定回复消息功能
添加 replyMessage 方法,支持在指定房间内回复特定消息。当无法找到原消息进行回复时,会自动转换为直接发送消息到该房间,确保消息能成功送达。同时包含完整的参数校验和错误处理逻辑。
This commit is contained in:
@@ -69,6 +69,31 @@ object WeworkController {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 在房间内指定回复消息
|
||||
* @see WeworkMessageBean.REPLY_MESSAGE
|
||||
* @param message#titleList 房间名称
|
||||
* @param message#receivedName 原始消息的发送者姓名
|
||||
* @param message#originalContent 原始消息的内容
|
||||
* @param message#textType 原始消息的消息类型
|
||||
* @param message#receivedContent 回复内容
|
||||
* @see WeworkMessageBean.TEXT_TYPE
|
||||
*/
|
||||
@RequestMapping
|
||||
fun replyMessage(message: WeworkMessageBean): Boolean {
|
||||
LogUtils.d("REQUEST replyMessage(): ${message.messageId} ${message.receivedName} ${message.originalContent} ${message.textType} ${message.receivedContent}")
|
||||
val result = WeworkOperationImpl.replyMessage(
|
||||
message,
|
||||
message.titleList,
|
||||
message.receivedName,
|
||||
message.originalContent,
|
||||
message.textType,
|
||||
message.receivedContent
|
||||
)
|
||||
// 发送完成,通知等待结束
|
||||
waitingForReply = false
|
||||
return result
|
||||
}
|
||||
/**
|
||||
* 在房间内转发消息
|
||||
* @see WeworkMessageBean.RELAY_MESSAGE
|
||||
|
||||
@@ -99,30 +99,102 @@ object WeworkOperationImpl {
|
||||
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime, successList, failList)
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 在房间内指定回复消息
|
||||
* @see WeworkMessageBean.REPLY_MESSAGE
|
||||
* @param message#titleList 房间名称
|
||||
* @param message#receivedName 原始消息的发送者姓名
|
||||
* @param message#originalContent 原始消息的内容
|
||||
* @param message#textType 原始消息的消息类型
|
||||
* @param message#receivedContent 回复内容
|
||||
* @param titleList 房间名称
|
||||
* @param receivedName 原始消息的发送者姓名
|
||||
* @param originalContent 原始消息的内容
|
||||
* @param textType 原始消息的消息类型
|
||||
* @param receivedContent 回复内容
|
||||
* @see WeworkMessageBean.TEXT_TYPE
|
||||
*/
|
||||
@RequestMapping
|
||||
fun replyMessage(message: WeworkMessageBean): Boolean {
|
||||
LogUtils.d("REQUEST replyMessage(): ${message.messageId} ${message.receivedName} ${message.originalContent} ${message.textType} ${message.receivedContent}")
|
||||
val result = WeworkOperationImpl.replyMessage(
|
||||
message,
|
||||
message.titleList,
|
||||
message.receivedName,
|
||||
message.originalContent,
|
||||
message.textType,
|
||||
message.receivedContent
|
||||
)
|
||||
// 发送完成,通知等待结束
|
||||
waitingForReply = false
|
||||
return result
|
||||
fun replyMessage(
|
||||
message: WeworkMessageBean,
|
||||
titleList: List<String>,
|
||||
receivedName: String?,
|
||||
originalContent: String,
|
||||
textType: Int?,
|
||||
receivedContent: String?
|
||||
): Boolean {
|
||||
val startTime = System.currentTimeMillis()
|
||||
if (receivedContent.isNullOrEmpty()) {
|
||||
LogUtils.d("未发现回复内容")
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_ILLEGAL_DATA, "回复内容为空", startTime, listOf(), titleList)
|
||||
goHome()
|
||||
return false
|
||||
}
|
||||
|
||||
// 验证titleList是否在当前会话列表中存在
|
||||
val currentRoomList = WeworkRoomUtil.getRoomTitle(print = false)
|
||||
if (currentRoomList.isEmpty()) {
|
||||
LogUtils.d("无法获取当前会话列表")
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "无法获取当前会话列表,请确保在微信首页", startTime, listOf(), titleList)
|
||||
return false
|
||||
}
|
||||
val notFoundList = titleList.filter { title ->
|
||||
currentRoomList.none { it == title || it.replace(Constant.digitalRegex, "") == title || title.replace(Constant.digitalRegex, "") == it }
|
||||
}
|
||||
if (notFoundList.isNotEmpty()) {
|
||||
LogUtils.d("以下会话不存在: ${notFoundList.joinToString()}")
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "会话不存在: ${notFoundList.joinToString()}", startTime, listOf(), titleList)
|
||||
return false
|
||||
}
|
||||
|
||||
val successList = arrayListOf<String>()
|
||||
val failList = arrayListOf<String>()
|
||||
for (title in LinkedHashSet(titleList)) {
|
||||
if (WeworkRoomUtil.intoRoom(title) || WeworkRoomUtil.intoRoom(title, fastIn = false)) {
|
||||
if (textType?.let {
|
||||
WeworkTextUtil.longClickMessageItem(
|
||||
//聊天消息列表 1ListView 0RecycleView xViewGroup
|
||||
AccessibilityUtil.findOneByClazz(getRoot(), Views.ListView),
|
||||
it,
|
||||
receivedName,
|
||||
originalContent,
|
||||
"回复", "引用"
|
||||
)
|
||||
} == true
|
||||
) {
|
||||
LogUtils.v("开始回复")
|
||||
if (sendChatMessage(receivedContent, reply = true, title = title)) {
|
||||
LogUtils.d("$title: 回复成功")
|
||||
successList.add(title)
|
||||
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime, successList, failList)
|
||||
return true
|
||||
} else {
|
||||
LogUtils.d("$title: 回复发送失败")
|
||||
failList.add(title)
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "回复发送失败", startTime, successList, failList)
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
LogUtils.d("$title: 回复失败 直接发送答案")
|
||||
error("$title: 回复失败 直接发送答案 $receivedContent")
|
||||
val text = if (originalContent.isNotEmpty()) "【$originalContent】\n$receivedContent" else receivedContent
|
||||
if (sendChatMessage(text, receivedName, title = title)) {
|
||||
LogUtils.d("$title: 直接发送答案成功")
|
||||
successList.add(title)
|
||||
uploadCommandResult(message, ExecCallbackBean.SUCCESS, "", startTime, successList, failList)
|
||||
return true
|
||||
} else {
|
||||
LogUtils.d("$title: 直接发送答案失败")
|
||||
failList.add(title)
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_SEND_MESSAGE, "直接发送答案失败", startTime, successList, failList)
|
||||
return false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error("$title: 回复失败 $receivedContent")
|
||||
LogUtils.d("进入房间失败 $title")
|
||||
failList.add(title)
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_INTO_ROOM, "进入房间失败 $title", startTime, successList, failList)
|
||||
return false
|
||||
}
|
||||
}
|
||||
LogUtils.d("房间名为空")
|
||||
uploadCommandResult(message, ExecCallbackBean.ERROR_ILLEGAL_DATA, "房间名为空", startTime, listOf(), titleList)
|
||||
return false
|
||||
}
|
||||
/**
|
||||
* 在房间内转发消息
|
||||
|
||||
Reference in New Issue
Block a user