Skip to main content
Home

Built and signed on GitHub Actions

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.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
76%
Published
2 months ago (0.0.1)

@gramio/split

npm npm downloads JSR JSR Score

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 sendPhoto caption next splits to sendMessage text)
Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@gramio/split

Import symbol

import * as split from "@gramio/split";
or

Import directly with a jsr specifier

import * as split from "jsr:@gramio/split";

Add Package

pnpm i jsr:@gramio/split
or (using pnpm 10.8 or older)
pnpm dlx jsr add @gramio/split

Import symbol

import * as split from "@gramio/split";

Add Package

yarn add jsr:@gramio/split
or (using Yarn 4.8 or older)
yarn dlx jsr add @gramio/split

Import symbol

import * as split from "@gramio/split";

Add Package

vlt install jsr:@gramio/split

Import symbol

import * as split from "@gramio/split";

Add Package

npx jsr add @gramio/split

Import symbol

import * as split from "@gramio/split";

Add Package

bunx jsr add @gramio/split

Import symbol

import * as split from "@gramio/split";