Skip to content

Fix Telegram multi-line message truncation#26

Merged
MarvelNwachukwu merged 2 commits intomainfrom
fix-multiline-telegram
Mar 18, 2026
Merged

Fix Telegram multi-line message truncation#26
MarvelNwachukwu merged 2 commits intomainfrom
fix-multiline-telegram

Conversation

@MarvelNwachukwu
Copy link
Copy Markdown
Contributor

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

  • Modified the content: field parser to capture all lines after the prefix
  • Added early break after finding content since it's the last field
  • Preserves existing fallback behavior for blank-line separator format

Testing

  • Build succeeds (pnpm build)
  • Manual Telegram test recommended: send multi-line message and verify full text arrives at agent

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 parseTelegramMessage function now correctly captures and processes all lines of a message, thereby preserving the full content and improving the reliability of message delivery and interpretation.

Highlights

  • Multi-line Message Truncation Fix: Resolved an issue where multi-line messages from MCP Telegram were truncated, capturing only the first line after the 'content:' field.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +52 to +55
const contentIndex = lines.indexOf(line);
const firstLine = trimmed.replace("content:", "").trim();
const remainingLines = lines.slice(contentIndex + 1);
messageText = [firstLine, ...remainingLines].join("\n").trim();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.
@MarvelNwachukwu MarvelNwachukwu merged commit d205308 into main Mar 18, 2026
1 check passed
@MarvelNwachukwu MarvelNwachukwu linked an issue Mar 18, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: multi-line telegram messages truncated to first line

1 participant