(msg: WeFlowMessage)
| 479 | const pipeline = chain([readStream, parser(), pick({ filter: /^messages\.\d+$/ }), streamValues()]) |
| 480 | |
| 481 | const processMessage = (msg: WeFlowMessage): ParsedMessage | null => { |
| 482 | // 验证必要字段 |
| 483 | if (!msg.senderUsername || msg.createTime === undefined) { |
| 484 | return null |
| 485 | } |
| 486 | |
| 487 | const platformId = msg.senderUsername |
| 488 | |
| 489 | // 跳过群"成员"(群ID以 @chatroom 结尾的消息) |
| 490 | // 这些通常是系统消息,发送者是群本身,不是真正的成员 |
| 491 | if (platformId.endsWith('@chatroom')) { |
| 492 | return null |
| 493 | } |
| 494 | |
| 495 | const accountName = msg.senderDisplayName || platformId |
| 496 | |
| 497 | // 获取头像(通过 senderAvatarKey 从 avatarsMap 查找) |
| 498 | const avatarKey = msg.senderAvatarKey || msg.senderUsername |
| 499 | const avatar = avatarsMap.get(avatarKey) |
| 500 | |
| 501 | // 更新成员信息 |
| 502 | if (!memberMap.has(platformId)) { |
| 503 | memberMap.set(platformId, { |
| 504 | platformId, |
| 505 | accountName, |
| 506 | avatar, |
| 507 | }) |
| 508 | } else { |
| 509 | // 更新为最新的显示名 |
| 510 | const existing = memberMap.get(platformId)! |
| 511 | existing.accountName = accountName |
| 512 | // 头像使用最新的(覆盖更新) |
| 513 | if (avatar) { |
| 514 | existing.avatar = avatar |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | // 转换消息类型 |
| 519 | const type = convertMessageType(msg.type) |
| 520 | |
| 521 | // 确保 content 是字符串类型(防止某些消息类型的 content 是对象) |
| 522 | // 同时去除开头和结尾的空白字符 |
| 523 | let content: string | null = null |
| 524 | if (msg.content != null) { |
| 525 | const rawContent = typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content) |
| 526 | content = rawContent.trim() || null |
| 527 | } |
| 528 | |
| 529 | return { |
| 530 | platformMessageId: String(msg.localId), // 消息的平台原始 ID(用于回复关联查询) |
| 531 | senderPlatformId: platformId, |
| 532 | senderAccountName: accountName, |
| 533 | // WeFlow 格式没有单独的群昵称字段 |
| 534 | senderGroupNickname: undefined, |
| 535 | timestamp: msg.createTime, |
| 536 | type, |
| 537 | content, |
| 538 | // 注意:WeFlow 导出格式不包含被引用消息的 ID,所以 replyToMessageId 为空 |
no test coverage detected