mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-12-01 01:05:30 +08:00
feat(wecom): 支持企业微信插件会话的消息读取与检索
企业微信插件(Mac 微信 4.2)的群 @qy_g 与会话 @qy_u 消息落在 biz_message_*.db,群/成员元数据落在 bizchat/bizchat.db,而原实现 只把 gh_ 前缀路由到 biz_message_*.db,其余一律读 message_*.db, 导致这些会话在档案/会话列表/搜索中完全缺失。 核心改动: - wcdb4-client: isBizSession/isEnterpriseSession 判定;getMessageDatabasePaths 把 @qy_g/@qy_u 路由到 biz_message_*.db;企业会话跳过本库 Name2Id 联表 - wcdb4-client: parseEnterpriseSource 从 zstd 压缩的 source XML enterprise_info 解析 sender/nickname/bizchat_id - wcdb4-client: hydrateEnterpriseGroupNamesAsync 从 bizchat.chat_group 注入群名 - wcdb4-client: getEnterpriseGroupMembers(Async) 从 chat_group.user_list + user_info.user_name 构建成员列表 - message-parser: 企业图片 <img> 无 md5 但有 aeskey,按 aeskey 补判图片类型 - shared/wechat-identities: isGroupSession/isEnterpriseSession 统一判定 - chat-service/wechat-db/index/local-agent-api/agent-group-report/knowledge-search: 读取与展示链路改用 isGroupSession,覆盖会话列表、群快照、群成员统计、 群日报、知识检索、撤回归档映射 - .gitignore: 排除诊断产物、数据库快照、密钥派生脚本与消息正文 blob 只读改造,未触及发送/插入/退群监控/语音转写/群管理等写入链路。 普通微信好友、@chatroom 群、gh_ 公众号行为保持不变。 验证:4 个 @qy_g 群 + 2 个 @qy_u 单聊可读;chatlog/query-search/ group_snapshot/member-stats 全通过;typecheck:node EXIT=0。
This commit is contained in:
1 parent
518a9662a7
commit
eac16ad8a7
10 files changed
+347
-29
No files matched your search
@@ -3,6 +3,7 @@ import type { Contact, Message } from '../../shared/types'
|
||||
import type { GroupDailyReport, GroupReportMetadata } from '../../shared/group-report'
|
||||
import { exportGroupReport } from '../group-report-service'
|
||||
import { getGroupSnapshot, listMessages, resolveMd5 } from './chat-service'
|
||||
import { isGroupSession } from '../../shared/wechat-identities'
|
||||
import { AIProviderService } from './ai-provider-service'
|
||||
import type {
|
||||
ScheduledReportMemberNameMode,
|
||||
@@ -105,7 +106,7 @@ export async function generateAgentGroupReport(
|
||||
if (!query) return reportFailure('缺少群聊名称', 'data', 'CHAT_NOT_FOUND')
|
||||
const contact = resolveMd5(query)
|
||||
if (!contact) return reportFailure(`没有找到群聊“${query}”`, 'data', 'CHAT_NOT_FOUND')
|
||||
if (contact.type !== 'group' && !contact.m_nsUsrName.endsWith('@chatroom')) {
|
||||
if (contact.type !== 'group' && !isGroupSession(contact.m_nsUsrName)) {
|
||||
return reportFailure(`“${query}”不是群聊`, 'data', 'CHAT_NOT_FOUND')
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
filterContactSearchIndex,
|
||||
type ContactSearchIndex
|
||||
} from '../../shared/contact-search'
|
||||
import { isGroupSession } from '../../shared/wechat-identities'
|
||||
|
||||
/**
|
||||
* 谁在读消息。
|
||||
@@ -348,7 +349,7 @@ export function listContacts(filter?: string): FormattedContact[] {
|
||||
|
||||
for (const user of userList) {
|
||||
const md5 = dbRef.md5(user.m_nsUsrName)
|
||||
const isGroup = user.m_nsUsrName.endsWith('@chatroom')
|
||||
const isGroup = isGroupSession(user.m_nsUsrName)
|
||||
existingMd5s.add(md5)
|
||||
contacts.push({
|
||||
m_nsUsrName: user.m_nsUsrName,
|
||||
@@ -437,7 +438,7 @@ export async function getGroupNamesAsync(): Promise<Record<string, string>> {
|
||||
const sessions = await dbRef.getWcdb4Client().getSessionsAsync({ hydrateDisplayNames: false })
|
||||
const names: Record<string, string> = {}
|
||||
for (const session of sessions) {
|
||||
if (!session.username.endsWith('@chatroom')) continue
|
||||
if (!isGroupSession(session.username)) continue
|
||||
const name = String(session.nickname || '').trim()
|
||||
if (name) names[session.username] = name
|
||||
}
|
||||
@@ -1051,9 +1052,11 @@ export function getGroupSnapshot(userMd5: string): GroupSnapshot | null {
|
||||
if (!dbRef) return null
|
||||
const wcdb4Client = dbRef.getWcdb4Client()
|
||||
const roomId = wcdb4Client.getUsernameByMd5(userMd5)
|
||||
if (!roomId || !roomId.endsWith('@chatroom')) return null
|
||||
if (!roomId || !isGroupSession(roomId)) return null
|
||||
|
||||
const rawMembers = wcdb4Client.getGroupMembers(roomId)
|
||||
const rawMembers = roomId.endsWith('@qy_g')
|
||||
? wcdb4Client.getEnterpriseGroupMembers(roomId)
|
||||
: wcdb4Client.getGroupMembers(roomId)
|
||||
const members = (Array.isArray(rawMembers) ? rawMembers : [])
|
||||
.filter((member) => member?.m_nsUsrName)
|
||||
.map((member) => ({
|
||||
@@ -1072,9 +1075,11 @@ export async function getGroupSnapshotAsync(userMd5: string): Promise<GroupSnaps
|
||||
if (!dbRef) return null
|
||||
const wcdb4Client = dbRef.getWcdb4Client()
|
||||
const roomId = wcdb4Client.getUsernameByMd5(userMd5)
|
||||
if (!roomId || !roomId.endsWith('@chatroom')) return null
|
||||
if (!roomId || !isGroupSession(roomId)) return null
|
||||
|
||||
const rawMembers = await wcdb4Client.getGroupMembersAsync(roomId)
|
||||
const rawMembers = roomId.endsWith('@qy_g')
|
||||
? await wcdb4Client.getEnterpriseGroupMembersAsync(roomId)
|
||||
: await wcdb4Client.getGroupMembersAsync(roomId)
|
||||
const members = (Array.isArray(rawMembers) ? rawMembers : [])
|
||||
.filter((member) => member?.m_nsUsrName)
|
||||
.map((member) => ({
|
||||
@@ -1105,15 +1110,23 @@ export async function getGroupSnapshotAsync(userMd5: string): Promise<GroupSnaps
|
||||
export function resolveGroupRoomId(userMd5: string): string | null {
|
||||
if (!dbRef) return null
|
||||
const roomId = dbRef.getWcdb4Client().getUsernameByMd5(userMd5)
|
||||
return roomId && roomId.endsWith('@chatroom') ? roomId : null
|
||||
return roomId && isGroupSession(roomId) ? roomId : null
|
||||
}
|
||||
|
||||
/** 退群检测专用轻量读取,不执行成员名称或头像 hydration。 */
|
||||
export async function getGroupMemberIdsAsync(
|
||||
roomId: string
|
||||
): Promise<GroupMembershipSnapshot | null> {
|
||||
if (!dbRef || !roomId.endsWith('@chatroom')) return null
|
||||
const memberIds = await dbRef.getWcdb4Client().getGroupMemberIdsAsync(roomId)
|
||||
if (!dbRef) return null
|
||||
const wcdb4Client = dbRef.getWcdb4Client()
|
||||
// 企业群:成员清单走 bizchat.chat_group.user_list(native 只认 @chatroom)。
|
||||
if (roomId.endsWith('@qy_g')) {
|
||||
const members = await wcdb4Client.getEnterpriseGroupMembersAsync(roomId)
|
||||
const memberIds = members.map((member) => member.m_nsUsrName).filter(Boolean)
|
||||
return { roomId, memberIds }
|
||||
}
|
||||
if (!roomId.endsWith('@chatroom')) return null
|
||||
const memberIds = await wcdb4Client.getGroupMemberIdsAsync(roomId)
|
||||
return memberIds ? { roomId, memberIds } : null
|
||||
}
|
||||
|
||||
@@ -1134,7 +1147,7 @@ export async function getGroupMemberNamesAsync(
|
||||
if (requested.length === 0) return []
|
||||
const wcdb4Client = dbRef.getWcdb4Client()
|
||||
const roomId = wcdb4Client.getUsernameByMd5(userMd5)
|
||||
if (!roomId || !roomId.endsWith('@chatroom')) return []
|
||||
if (!roomId || !isGroupSession(roomId)) return []
|
||||
const members = await wcdb4Client.getGroupMemberNamesAsync(roomId, requested)
|
||||
return members.map((member) => ({
|
||||
wxid: member.m_nsUsrName,
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
type AutomationRuleType
|
||||
} from '../../shared/automation'
|
||||
import { resolveContact } from './contact-resolution-service'
|
||||
import { isGroupSession } from '../../shared/wechat-identities'
|
||||
import { validateAutomationDraftShape } from '../../shared/agent-api/automation-validation'
|
||||
import type {
|
||||
AgentAutomationExecution,
|
||||
@@ -459,7 +460,7 @@ export class LocalAgentApiService {
|
||||
if (contact.type !== 'group') {
|
||||
throw new LocalAgentApiError(422, 'NOT_GROUP_CONVERSATION', 'conversationId 不是群会话')
|
||||
}
|
||||
if (!contact.m_nsUsrName.endsWith('@chatroom')) {
|
||||
if (!isGroupSession(contact.m_nsUsrName)) {
|
||||
throw new LocalAgentApiError(422, 'NOT_GROUP_CONVERSATION', 'conversationId 不是有效的群会话 ID')
|
||||
}
|
||||
if (!this.deps.getGroupMemberStats) {
|
||||
|
||||
Reference in new issue
Block a user