mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 16:03:43 +00:00
fix: enforce telegram shared outbound chunking
This commit is contained in:
@@ -160,6 +160,30 @@ describe("deliverOutboundPayloads", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("clamps telegram text chunk size to protocol max even with higher config", async () => {
|
||||
const sendTelegram = vi.fn().mockResolvedValue({ messageId: "m1", chatId: "c1" });
|
||||
const cfg: OpenClawConfig = {
|
||||
channels: { telegram: { botToken: "tok-1", textChunkLimit: 10_000 } },
|
||||
};
|
||||
const text = "<".repeat(3_000);
|
||||
await withEnvAsync({ TELEGRAM_BOT_TOKEN: "" }, async () => {
|
||||
await deliverOutboundPayloads({
|
||||
cfg,
|
||||
channel: "telegram",
|
||||
to: "123",
|
||||
payloads: [{ text }],
|
||||
deps: { sendTelegram },
|
||||
});
|
||||
});
|
||||
|
||||
expect(sendTelegram.mock.calls.length).toBeGreaterThan(1);
|
||||
const sentHtmlChunks = sendTelegram.mock.calls
|
||||
.map((call) => call[1])
|
||||
.filter((message): message is string => typeof message === "string");
|
||||
expect(sentHtmlChunks.length).toBeGreaterThan(1);
|
||||
expect(sentHtmlChunks.every((message) => message.length <= 4096)).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps payload replyToId across all chunked telegram sends", async () => {
|
||||
const sendTelegram = vi.fn().mockResolvedValue({ messageId: "m1", chatId: "c1" });
|
||||
await withEnvAsync({ TELEGRAM_BOT_TOKEN: "" }, async () => {
|
||||
|
||||
@@ -40,6 +40,7 @@ export type { NormalizedOutboundPayload } from "./payloads.js";
|
||||
export { normalizeOutboundPayloads } from "./payloads.js";
|
||||
|
||||
const log = createSubsystemLogger("outbound/deliver");
|
||||
const TELEGRAM_TEXT_LIMIT = 4096;
|
||||
|
||||
type SendMatrixMessage = (
|
||||
to: string,
|
||||
@@ -314,11 +315,15 @@ async function deliverOutboundPayloadsCore(
|
||||
silent: params.silent,
|
||||
mediaLocalRoots,
|
||||
});
|
||||
const textLimit = handler.chunker
|
||||
const configuredTextLimit = handler.chunker
|
||||
? resolveTextChunkLimit(cfg, channel, accountId, {
|
||||
fallbackLimit: handler.textChunkLimit,
|
||||
})
|
||||
: undefined;
|
||||
const textLimit =
|
||||
channel === "telegram" && typeof configuredTextLimit === "number"
|
||||
? Math.min(configuredTextLimit, TELEGRAM_TEXT_LIMIT)
|
||||
: configuredTextLimit;
|
||||
const chunkMode = handler.chunker ? resolveChunkMode(cfg, channel, accountId) : "length";
|
||||
const isSignalChannel = channel === "signal";
|
||||
const signalTableMode = isSignalChannel
|
||||
|
||||
Reference in New Issue
Block a user