MCPcopy Create free account
hub / github.com/CreminiAI/skillpack / splitMessage

Method splitMessage

src/runtime/adapters/feishu.ts:342–372  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

340 for (const chunk of this.splitMessage(text)) {
341 await this.sendSafe(chatId, chunk, replyTo);
342 }
343 }
344
345 private splitMessage(text: string): string[] {
346 if (text.length <= MAX_MESSAGE_LENGTH) {
347 return [text];
348 }
349
350 const chunks: string[] = [];
351 let remaining = text;
352
353 while (remaining.length > 0) {
354 if (remaining.length <= MAX_MESSAGE_LENGTH) {
355 chunks.push(remaining);
356 break;
357 }
358
359 let splitAt = remaining.lastIndexOf("\n\n", MAX_MESSAGE_LENGTH);
360 if (splitAt < MAX_MESSAGE_LENGTH * 0.5) {
361 splitAt = remaining.lastIndexOf("\n", MAX_MESSAGE_LENGTH);
362 }
363 if (splitAt < MAX_MESSAGE_LENGTH * 0.3) {
364 splitAt = remaining.lastIndexOf(" ", MAX_MESSAGE_LENGTH);
365 }
366 if (splitAt < 1) {
367 splitAt = MAX_MESSAGE_LENGTH;
368 }
369
370 chunks.push(remaining.slice(0, splitAt));
371 remaining = remaining.slice(splitAt).trimStart();
372 }
373
374 return chunks;
375 }

Callers 1

sendLongMessageMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected