mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 04:57:26 +00:00
refactor(test): share telegram message ctx setup
This commit is contained in:
@@ -2,11 +2,14 @@ import { describe, expect, it, vi } from "vitest";
|
|||||||
import { buildTelegramMessageContext } from "./bot-message-context.js";
|
import { buildTelegramMessageContext } from "./bot-message-context.js";
|
||||||
|
|
||||||
describe("buildTelegramMessageContext sender prefix", () => {
|
describe("buildTelegramMessageContext sender prefix", () => {
|
||||||
it("prefixes group bodies with sender label", async () => {
|
async function buildCtx(params: {
|
||||||
const ctx = await buildTelegramMessageContext({
|
messageId: number;
|
||||||
|
options?: Record<string, unknown>;
|
||||||
|
}): Promise<Awaited<ReturnType<typeof buildTelegramMessageContext>>> {
|
||||||
|
return await buildTelegramMessageContext({
|
||||||
primaryCtx: {
|
primaryCtx: {
|
||||||
message: {
|
message: {
|
||||||
message_id: 1,
|
message_id: params.messageId,
|
||||||
chat: { id: -99, type: "supergroup", title: "Dev Chat" },
|
chat: { id: -99, type: "supergroup", title: "Dev Chat" },
|
||||||
date: 1700000000,
|
date: 1700000000,
|
||||||
text: "hello",
|
text: "hello",
|
||||||
@@ -16,7 +19,7 @@ describe("buildTelegramMessageContext sender prefix", () => {
|
|||||||
} as never,
|
} as never,
|
||||||
allMedia: [],
|
allMedia: [],
|
||||||
storeAllowFrom: [],
|
storeAllowFrom: [],
|
||||||
options: {},
|
options: params.options ?? {},
|
||||||
bot: {
|
bot: {
|
||||||
api: {
|
api: {
|
||||||
sendChatAction: vi.fn(),
|
sendChatAction: vi.fn(),
|
||||||
@@ -43,6 +46,10 @@ describe("buildTelegramMessageContext sender prefix", () => {
|
|||||||
topicConfig: undefined,
|
topicConfig: undefined,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
it("prefixes group bodies with sender label", async () => {
|
||||||
|
const ctx = await buildCtx({ messageId: 1 });
|
||||||
|
|
||||||
expect(ctx).not.toBeNull();
|
expect(ctx).not.toBeNull();
|
||||||
const body = ctx?.ctxPayload?.Body ?? "";
|
const body = ctx?.ctxPayload?.Body ?? "";
|
||||||
@@ -50,91 +57,16 @@ describe("buildTelegramMessageContext sender prefix", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("sets MessageSid from message_id", async () => {
|
it("sets MessageSid from message_id", async () => {
|
||||||
const ctx = await buildTelegramMessageContext({
|
const ctx = await buildCtx({ messageId: 12345 });
|
||||||
primaryCtx: {
|
|
||||||
message: {
|
|
||||||
message_id: 12345,
|
|
||||||
chat: { id: -99, type: "supergroup", title: "Dev Chat" },
|
|
||||||
date: 1700000000,
|
|
||||||
text: "hello",
|
|
||||||
from: { id: 42, first_name: "Alice" },
|
|
||||||
},
|
|
||||||
me: { id: 7, username: "bot" },
|
|
||||||
} as never,
|
|
||||||
allMedia: [],
|
|
||||||
storeAllowFrom: [],
|
|
||||||
options: {},
|
|
||||||
bot: {
|
|
||||||
api: {
|
|
||||||
sendChatAction: vi.fn(),
|
|
||||||
setMessageReaction: vi.fn(),
|
|
||||||
},
|
|
||||||
} as never,
|
|
||||||
cfg: {
|
|
||||||
agents: { defaults: { model: "anthropic/claude-opus-4-5", workspace: "/tmp/openclaw" } },
|
|
||||||
channels: { telegram: {} },
|
|
||||||
messages: { groupChat: { mentionPatterns: [] } },
|
|
||||||
} as never,
|
|
||||||
account: { accountId: "default" } as never,
|
|
||||||
historyLimit: 0,
|
|
||||||
groupHistories: new Map(),
|
|
||||||
dmPolicy: "open",
|
|
||||||
allowFrom: [],
|
|
||||||
groupAllowFrom: [],
|
|
||||||
ackReactionScope: "off",
|
|
||||||
logger: { info: vi.fn() },
|
|
||||||
resolveGroupActivation: () => undefined,
|
|
||||||
resolveGroupRequireMention: () => false,
|
|
||||||
resolveTelegramGroupConfig: () => ({
|
|
||||||
groupConfig: { requireMention: false },
|
|
||||||
topicConfig: undefined,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(ctx).not.toBeNull();
|
expect(ctx).not.toBeNull();
|
||||||
expect(ctx?.ctxPayload?.MessageSid).toBe("12345");
|
expect(ctx?.ctxPayload?.MessageSid).toBe("12345");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("respects messageIdOverride option", async () => {
|
it("respects messageIdOverride option", async () => {
|
||||||
const ctx = await buildTelegramMessageContext({
|
const ctx = await buildCtx({
|
||||||
primaryCtx: {
|
messageId: 12345,
|
||||||
message: {
|
|
||||||
message_id: 12345,
|
|
||||||
chat: { id: -99, type: "supergroup", title: "Dev Chat" },
|
|
||||||
date: 1700000000,
|
|
||||||
text: "hello",
|
|
||||||
from: { id: 42, first_name: "Alice" },
|
|
||||||
},
|
|
||||||
me: { id: 7, username: "bot" },
|
|
||||||
} as never,
|
|
||||||
allMedia: [],
|
|
||||||
storeAllowFrom: [],
|
|
||||||
options: { messageIdOverride: "67890" },
|
options: { messageIdOverride: "67890" },
|
||||||
bot: {
|
|
||||||
api: {
|
|
||||||
sendChatAction: vi.fn(),
|
|
||||||
setMessageReaction: vi.fn(),
|
|
||||||
},
|
|
||||||
} as never,
|
|
||||||
cfg: {
|
|
||||||
agents: { defaults: { model: "anthropic/claude-opus-4-5", workspace: "/tmp/openclaw" } },
|
|
||||||
channels: { telegram: {} },
|
|
||||||
messages: { groupChat: { mentionPatterns: [] } },
|
|
||||||
} as never,
|
|
||||||
account: { accountId: "default" } as never,
|
|
||||||
historyLimit: 0,
|
|
||||||
groupHistories: new Map(),
|
|
||||||
dmPolicy: "open",
|
|
||||||
allowFrom: [],
|
|
||||||
groupAllowFrom: [],
|
|
||||||
ackReactionScope: "off",
|
|
||||||
logger: { info: vi.fn() },
|
|
||||||
resolveGroupActivation: () => undefined,
|
|
||||||
resolveGroupRequireMention: () => false,
|
|
||||||
resolveTelegramGroupConfig: () => ({
|
|
||||||
groupConfig: { requireMention: false },
|
|
||||||
topicConfig: undefined,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(ctx).not.toBeNull();
|
expect(ctx).not.toBeNull();
|
||||||
|
|||||||
Reference in New Issue
Block a user