(msg: TelegramMessage)
| 120 | * 构建消息内容 |
| 121 | */ |
| 122 | export function buildContent(msg: TelegramMessage): string | null { |
| 123 | const text = extractText(msg.text) |
| 124 | |
| 125 | // Service 消息 |
| 126 | if (msg.type === 'service') { |
| 127 | const action = msg.action || '' |
| 128 | const members = msg.members?.join(', ') || '' |
| 129 | if (members) return `[${action}] ${members}` |
| 130 | // action 为空时回退到文本,避免常量表达式触发 lint 规则。 |
| 131 | if (action) return `[${action}]` |
| 132 | return text || null |
| 133 | } |
| 134 | |
| 135 | // 贴纸:使用 emoji 表示 |
| 136 | if (msg.media_type === 'sticker' && msg.sticker_emoji) { |
| 137 | return text ? `[sticker ${msg.sticker_emoji}] ${text}` : `[sticker ${msg.sticker_emoji}]` |
| 138 | } |
| 139 | |
| 140 | // 媒体消息带文字说明 |
| 141 | if (msg.photo || msg.file || msg.media_type) { |
| 142 | const mediaLabel = msg.media_type || (msg.photo ? 'photo' : 'file') |
| 143 | if (text) return `[${mediaLabel}] ${text}` |
| 144 | return `[${mediaLabel}]` |
| 145 | } |
| 146 | |
| 147 | return text || null |
| 148 | } |
no test coverage detected