Fix Telegram multi-line message truncation#26
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug in the Telegram message parsing logic that previously led to the truncation of multi-line messages. The updated implementation ensures that the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively resolves the issue of multi-line message truncation in Telegram by adjusting the parsing logic to capture all lines after the content: field. The logic is sound and the inclusion of a break statement is a good performance improvement. I have one suggestion regarding the implementation to enhance its efficiency and robustness.
src/services/TelegramService.ts
Outdated
| const contentIndex = lines.indexOf(line); | ||
| const firstLine = trimmed.replace("content:", "").trim(); | ||
| const remainingLines = lines.slice(contentIndex + 1); | ||
| messageText = [firstLine, ...remainingLines].join("\n").trim(); |
There was a problem hiding this comment.
Using lines.indexOf(line) inside this loop can be inefficient, as it performs a search on each iteration where the content: line is checked. This could lead to O(n^2) complexity in a worst-case scenario. It might also be brittle if a previous line in the message has the exact same content as the content: line.
A more robust and efficient approach would be to use a for loop that provides an index, which avoids the need for indexOf.
Example:
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const trimmed = line.trim();
// ... other if/else if branches
if (trimmed.startsWith("content:")) {
const firstLine = trimmed.replace("content:", "").trim();
const remainingLines = lines.slice(i + 1);
messageText = [firstLine, ...remainingLines].join('\n').trim();
foundContent = true;
break;
}
}This would require changing the for...of loop on line 44. While this is outside the current diff, it's a recommended improvement for robustness and performance.
Replace for-of + indexOf with indexed for-loop to avoid O(n^2) lookup and potential mismatches on duplicate line content.
Summary
Fixed
parseTelegramMessage()in TelegramService to preserve multi-line messages from MCP Telegram.Previously, when a multi-line message was sent via Telegram, only the first line after the
content:field was captured. All subsequent lines were silently discarded.Changes
content:field parser to capture all lines after the prefixTesting