feat(import): 增强Telegram JSON导出格式支持#245
Conversation
…e bundle support - Add EnableLocalBotAPI, TelegramBotApiId, TelegramBotApiHash, LocalBotApiPort to Config/Env - Auto-set BaseUrl and IsLocalAPI when EnableLocalBotAPI is true - Launch telegram-bot-api.exe as a ChildProcessManager-managed process in GeneralBootstrap - Add conditional Content entry for telegram-bot-api.exe in .csproj - Build telegram-bot-api from source via cmake+vcpkg in GitHub Actions push workflow Co-authored-by: ModerRAS <28183976+ModerRAS@users.noreply.github.com>
- 扩展ChatExport模型支持更多消息类型 - 添加Video、Voice、VideoNote字段 - 添加Sticker、Contact、Poll、Location模型 - 添加ForwardedFrom、Reactions、ViaBot字段 - 添加Caption和Caption_Entities支持 - 添加服务消息(Actor、Action)支持 - 增强ChatImportService文本提取 - 支持简单的Text数组(不仅限Text_Entities) - 添加贴纸、语音、视频等媒体类型标记 - 添加投票、联系人、位置等消息类型处理 - 添加服务消息处理 Fixes #81
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 42 minutes and 19 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughExtended Telegram chat export support by adding comprehensive JSON model mappings for diverse message types (media, reactions, forwarding), introducing a custom text converter for flexible deserialization, enhancing message text composition logic to include captions and metadata, and adding validation with an integration test demonstrating import of text-only exports. Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test
participant Service as ChatImportService
participant Parser as JSON Parser
participant DB as DataDbContext
participant Converter as TextItemListConverter
Test->>Service: ImportFromFileAsync(jsonFilePath)
Service->>Parser: Read & Deserialize JSON
Parser->>Converter: Normalize Message.Text variants
Converter-->>Parser: List<TextItem>
Parser-->>Service: ChatExport object
Service->>Service: Validate ChatExport not null
Service->>DB: Create messages from export
loop For each message
Service->>Service: Parse FromUserId (From_Id or ActorId)
Service->>Service: Check HasEmbeddedFile for media
Service->>Service: Compose text (captions + entities + metadata)
Service->>DB: Insert message with formatted content
end
DB-->>Service: Persisted messages
Service-->>Test: Import complete
Test->>DB: Query & verify 4 messages, entities, markdown
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔍 PR检查报告📋 检查概览
🧪 测试结果
📊 代码质量
📁 测试产物
🔗 相关链接此报告由GitHub Actions自动生成 |
Fix whitespace formatting issues detected by CI on Windows
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
TelegramSearchBot/Model/ChatExport/ChatExport.cs (1)
133-189: SetCanWritetofalseonTextItemListConverterto prevent infinite recursion during serialization.The
WriteJsonmethod currently delegates toserializer.Serialize(writer, value). Because the converter is attached toMessage.Textvia[JsonConverter(typeof(TextItemListConverter))], Newtonsoft will re-invoke this same converter during serialization, causing infinite recursion. While the current code only deserializes, serializing aChatExport(for caching, logging, or round-tripping) will stack-overflow. SettingCanWrite = falsedisables the custom write logic and lets the default serializer handle it.♻️ Proposed change
public class TextItemListConverter : JsonConverter { + public override bool CanWrite => false; + public override bool CanConvert(Type objectType) { return objectType == typeof(List<TextItem>); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@TelegramSearchBot/Model/ChatExport/ChatExport.cs` around lines 133 - 189, The JsonConverter TextItemListConverter currently implements WriteJson and calls serializer.Serialize, which causes infinite recursion when this converter is applied to Message.Text; to fix, override the converter's CanWrite property to return false (in the TextItemListConverter class) so Newtonsoft will skip the converter for writing and use the default serialization path, leaving ReadJson as-is and preventing stack overflows during serialization.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@TelegramSearchBot/Service/Manage/ChatImportService.cs`:
- Around line 226-242: FormatEntity can throw NullReferenceException because
branches like "mention", "bot_command", and "email" use entity.Text (and call
TrimStart) without null checks; update FormatEntity to short-circuit when
entity.Text is null or empty (similar to FormatItem) before using TrimStart or
interpolating, e.g., for the "mention" / "bot_command" / "email" cases check
string.IsNullOrEmpty(entity.Text) and return entity.Text ?? "" (or the plain
fallback) instead of calling TrimStart on a null value; keep changes confined to
the FormatEntity method and only guard the branches that access entity.Text
directly.
---
Nitpick comments:
In `@TelegramSearchBot/Model/ChatExport/ChatExport.cs`:
- Around line 133-189: The JsonConverter TextItemListConverter currently
implements WriteJson and calls serializer.Serialize, which causes infinite
recursion when this converter is applied to Message.Text; to fix, override the
converter's CanWrite property to return false (in the TextItemListConverter
class) so Newtonsoft will skip the converter for writing and use the default
serialization path, leaving ReadJson as-is and preventing stack overflows during
serialization.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e7d33891-ceb7-4e59-bcb2-2bb9f8443334
📒 Files selected for processing (3)
TelegramSearchBot.Test/Service/Manage/ChatImportServiceTests.csTelegramSearchBot/Model/ChatExport/ChatExport.csTelegramSearchBot/Service/Manage/ChatImportService.cs
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
实现Issue #81 - 增加Telegram官方JSON格式导出历史记录适配
增强功能
扩展ChatExport模型
增强文本提取
文件变更
Fixes #81
Summary by CodeRabbit
New Features
Bug Fixes
Tests