Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
gramiojs/splitWorks with
•JSR Score76%•This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers




Published11 months ago (0.0.1)
This package can split messages which reach the Telegram limit into multiple parts (messages). This package also split entities so you don't need to do it manually.
@gramio/split
This package can split messages which reach the Telegram limit into multiple parts (messages). This package also split entities so you don't need to do it manually.
Usage
import { splitMessage } from "@gramio/split"; const bot = new Bot(process.env.BOT_TOKEN!).command( "start", async (context) => { const messages = await splitMessage( format`${bold("a".repeat(4096 * 2))}`, (str) => context.send(str) // be worry. if u wants provide an context.send without function wrapper // you should use context.send.bind(context) it is required because otherwise it will lose context data ); console.log(messages); // messages is array of second argument results } ); await bot.start();
You can also use it in other frameworks.
import { splitMessage } from "@gramio/split"; const messages = await splitMessage( format`${bold("a".repeat(4096 * 2))}`, ({ text, entities }) => { return someOtherFramework.sendMessage(text, { entities }); } );
Configuration
You can also configure maximum text length. By default it's 4096 symbols, but sendPhoto caption has limit 1024 symbols.
const messages = await splitMessage( format`${bold("a".repeat(4096))}`, ({ text, entities }) => { return context.sendPhoto(PHOTO, { caption: text, caption_entities: entities, }); }, 1024 );
Note
This package mostly in the WIP stage.
TODO:
- More tests
- Plugin with auto-split
- Split mode by entities
- Auto split action strategies (like
sendPhotocaption next splits tosendMessagetext)
Built and signed on
GitHub Actions
Add Package
deno add jsr:@gramio/split
Import symbol
import * as split from "@gramio/split";
Import directly with a jsr specifier
import * as split from "jsr:@gramio/split";