* Converts fetched messages into a single document content string. * Each line: "[ISO timestamp] username: message text"
(messages: TeamsMessage[])
| 137 | * Each line: "[ISO timestamp] username: message text" |
| 138 | */ |
| 139 | function formatMessages(messages: TeamsMessage[]): string { |
| 140 | const lines: string[] = [] |
| 141 | |
| 142 | // Process in reverse so oldest messages come first |
| 143 | const chronological = [...messages].reverse() |
| 144 | |
| 145 | for (const msg of chronological) { |
| 146 | const bodyText = |
| 147 | msg.body.contentType === 'html' ? htmlToPlainText(msg.body.content) : msg.body.content |
| 148 | |
| 149 | if (!bodyText.trim()) continue |
| 150 | |
| 151 | const timestamp = msg.createdDateTime |
| 152 | const userName = msg.from?.user?.displayName || msg.from?.application?.displayName || 'unknown' |
| 153 | |
| 154 | lines.push(`[${timestamp}] ${userName}: ${bodyText}`) |
| 155 | } |
| 156 | |
| 157 | return lines.join('\n') |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Resolves a channel name or ID to a channel object within the given team. |
no test coverage detected