(task: SummaryTask)
| 788 | : `[文件: ${fileName}]`; |
| 789 | } |
| 790 | |
| 791 | if (textContent) { |
| 792 | messageData.push({ |
| 793 | text: `[${time}] ${sender}: ${textContent}`, |
| 794 | content: message.message || "", |
| 795 | telegramLink: link, |
| 796 | urls, |
| 797 | fileName: fileName || undefined, |
| 798 | }); |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | return messageData.reverse(); |
| 803 | } |
| 804 | |
| 805 | // 格式化消息数据为文本 |
| 806 | function formatMessagesForAI(messageData: MessageData[]): string { |
| 807 | // 消息正文,每条消息附带 Telegram 链接 |
| 808 | const messageTexts = messageData.map( |
| 809 | (m) => `${m.text} [来源](${m.telegramLink})`, |
| 810 | ); |
| 811 | |
| 812 | // 提取所有外部 URL 及其对应的 Telegram 消息链接 |
| 813 | // 优先使用 entities 中提取的 URL,其次使用文本中的 URL |
| 814 | const urlMappings: { url: string; telegramLink: string }[] = []; |
| 815 | for (const m of messageData) { |
| 816 | // 合并两种来源的 URL |
| 817 | const allUrls = [...m.urls, ...extractUrlsFromText(m.content)]; |
| 818 | for (const url of allUrls) { |
| 819 | // 去重:检查是否已存在相同 URL |
| 820 | if (!urlMappings.some((u) => u.url === url)) { |
| 821 | urlMappings.push({ url, telegramLink: m.telegramLink }); |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | // 提取所有附件文件 |
| 827 | const fileMappings: { fileName: string; telegramLink: string }[] = []; |
| 828 | for (const m of messageData) { |
| 829 | if (m.fileName) { |
no test coverage detected