Skip to content

Commit 22006b3

Browse files
committed
refactor: clean up messageManager and utils imports
- Handling all text/* documents. - Removed commented-out code and unnecessary comments in `MessageManager` for improved readability. - Updated import statements in `utils.ts` to use type imports for better clarity and performance.
1 parent 953ba95 commit 22006b3

2 files changed

Lines changed: 3 additions & 12 deletions

File tree

src/messageManager.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export class MessageManager {
8686
this.runtime = runtime;
8787
}
8888

89-
// Process image messages and generate descriptions
9089
/**
9190
* Process an image from a Telegram message to extract the image URL and description.
9291
*
@@ -129,10 +128,6 @@ export class MessageManager {
129128
* @param {Message} message - The Telegram message object containing the document.
130129
* @returns {Promise<{ description: string } | null>} The description of the processed document or null if no document found.
131130
*/
132-
/**
133-
* Process a document from a Telegram message and extract its content.
134-
* Handles PDFs, text files, and other document types centrally.
135-
*/
136131
async processDocument(
137132
message: Message,
138133
): Promise<DocumentProcessingResult | null> {
@@ -177,8 +172,7 @@ export class MessageManager {
177172

178173
const processors = {
179174
"application/pdf": this.processPdfDocument.bind(this),
180-
"text/plain": this.processTextDocument.bind(this),
181-
"text/csv": this.processTextDocument.bind(this),
175+
"text/": this.processTextDocument.bind(this), // covers text/plain, text/csv, text/markdown, etc.
182176
"application/json": this.processTextDocument.bind(this),
183177
};
184178

@@ -371,7 +365,6 @@ export class MessageManager {
371365
return { processedContent, attachments };
372366
}
373367

374-
// Send long messages in chunks
375368
/**
376369
* Sends a message in chunks, handling attachments and splitting the message if necessary
377370
*
@@ -515,7 +508,6 @@ export class MessageManager {
515508
}
516509
}
517510

518-
// Split message into smaller parts
519511
/**
520512
* Splits a given text into an array of strings based on the maximum message length.
521513
*
@@ -541,7 +533,6 @@ export class MessageManager {
541533
return chunks;
542534
}
543535

544-
// Main handler for incoming messages
545536
/**
546537
* Handle incoming messages from Telegram and process them accordingly.
547538
* @param {Context} ctx - The context object containing information about the message.

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Markup } from 'telegraf';
2-
import { InlineKeyboardButton } from '@telegraf/types';
3-
import { Button } from './types';
2+
import type { Button } from './types';
3+
import type { InlineKeyboardButton } from '@telegraf/types';
44

55
// A list of Telegram MarkdownV2 reserved characters that must be escaped
66
const TELEGRAM_RESERVED_REGEX = /([_*[\]()~`>#+\-=|{}.!\\])/g;

0 commit comments

Comments
 (0)