Files
openclaw/extensions/telegram/src/bot-message-dispatch.sticker-media.test.ts
scoootscooob e5bca0832f refactor: move Telegram channel implementation to extensions/ (#45635)
* refactor: move Telegram channel implementation to extensions/telegram/src/

Move all Telegram channel code (123 files + 10 bot/ files + 8 channel plugin
files) from src/telegram/ and src/channels/plugins/*/telegram.ts to
extensions/telegram/src/. Leave thin re-export shims at original locations so
cross-cutting src/ imports continue to resolve.

- Fix all relative import paths in moved files (../X/ -> ../../../src/X/)
- Fix vi.mock paths in 60 test files
- Fix inline typeof import() expressions
- Update tsconfig.plugin-sdk.dts.json rootDir to "." for cross-directory DTS
- Update write-plugin-sdk-entry-dts.ts for new rootDir structure
- Move channel plugin files with correct path remapping

* fix: support keyed telegram send deps

* fix: sync telegram extension copies with latest main

* fix: correct import paths and remove misplaced files in telegram extension

* fix: sync outbound-adapter with main (add sendTelegramPayloadMessages) and fix delivery.test import path
2026-03-14 02:50:17 -07:00

73 lines
2.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { pruneStickerMediaFromContext } from "./bot-message-dispatch.js";
type MediaCtx = {
MediaPath?: string;
MediaUrl?: string;
MediaType?: string;
MediaPaths?: string[];
MediaUrls?: string[];
MediaTypes?: string[];
};
function expectSingleImageMedia(ctx: MediaCtx, mediaPath: string) {
expect(ctx.MediaPath).toBe(mediaPath);
expect(ctx.MediaUrl).toBe(mediaPath);
expect(ctx.MediaType).toBe("image/jpeg");
expect(ctx.MediaPaths).toEqual([mediaPath]);
expect(ctx.MediaUrls).toEqual([mediaPath]);
expect(ctx.MediaTypes).toEqual(["image/jpeg"]);
}
describe("pruneStickerMediaFromContext", () => {
it("preserves appended reply media while removing primary sticker media", () => {
const ctx: MediaCtx = {
MediaPath: "/tmp/sticker.webp",
MediaUrl: "/tmp/sticker.webp",
MediaType: "image/webp",
MediaPaths: ["/tmp/sticker.webp", "/tmp/replied.jpg"],
MediaUrls: ["/tmp/sticker.webp", "/tmp/replied.jpg"],
MediaTypes: ["image/webp", "image/jpeg"],
};
pruneStickerMediaFromContext(ctx);
expectSingleImageMedia(ctx, "/tmp/replied.jpg");
});
it("clears media fields when sticker is the only media", () => {
const ctx: MediaCtx = {
MediaPath: "/tmp/sticker.webp",
MediaUrl: "/tmp/sticker.webp",
MediaType: "image/webp",
MediaPaths: ["/tmp/sticker.webp"],
MediaUrls: ["/tmp/sticker.webp"],
MediaTypes: ["image/webp"],
};
pruneStickerMediaFromContext(ctx);
expect(ctx.MediaPath).toBeUndefined();
expect(ctx.MediaUrl).toBeUndefined();
expect(ctx.MediaType).toBeUndefined();
expect(ctx.MediaPaths).toBeUndefined();
expect(ctx.MediaUrls).toBeUndefined();
expect(ctx.MediaTypes).toBeUndefined();
});
it("does not prune when sticker media is already omitted from context", () => {
const ctx: MediaCtx = {
MediaPath: "/tmp/replied.jpg",
MediaUrl: "/tmp/replied.jpg",
MediaType: "image/jpeg",
MediaPaths: ["/tmp/replied.jpg"],
MediaUrls: ["/tmp/replied.jpg"],
MediaTypes: ["image/jpeg"],
};
pruneStickerMediaFromContext(ctx, { stickerMediaIncluded: false });
expectSingleImageMedia(ctx, "/tmp/replied.jpg");
});
});