mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-29 15:01:48 +03:00
fix(telegram): add DM allowFrom regression tests
This commit is contained in:
@@ -266,7 +266,8 @@ export const buildTelegramMessageContext = async ({
|
|||||||
if (created) {
|
if (created) {
|
||||||
logger.info(
|
logger.info(
|
||||||
{
|
{
|
||||||
chatId: candidate,
|
chatId: String(chatId),
|
||||||
|
senderUserId: senderUserId ?? undefined,
|
||||||
username: from?.username,
|
username: from?.username,
|
||||||
firstName: from?.first_name,
|
firstName: from?.first_name,
|
||||||
lastName: from?.last_name,
|
lastName: from?.last_name,
|
||||||
|
|||||||
+55
@@ -274,6 +274,61 @@ describe("createTelegramBot", () => {
|
|||||||
|
|
||||||
expect(replySpy).toHaveBeenCalledTimes(1);
|
expect(replySpy).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
it("matches direct message allowFrom against sender user id when chat id differs", async () => {
|
||||||
|
onSpy.mockReset();
|
||||||
|
const replySpy = replyModule.__replySpy as unknown as ReturnType<typeof vi.fn>;
|
||||||
|
replySpy.mockReset();
|
||||||
|
loadConfig.mockReturnValue({
|
||||||
|
channels: {
|
||||||
|
telegram: {
|
||||||
|
allowFrom: ["123456789"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
createTelegramBot({ token: "tok" });
|
||||||
|
const handler = getOnHandler("message") as (ctx: Record<string, unknown>) => Promise<void>;
|
||||||
|
|
||||||
|
await handler({
|
||||||
|
message: {
|
||||||
|
chat: { id: 777777777, type: "private" },
|
||||||
|
from: { id: 123456789, username: "testuser" },
|
||||||
|
text: "hello",
|
||||||
|
date: 1736380800,
|
||||||
|
},
|
||||||
|
me: { username: "openclaw_bot" },
|
||||||
|
getFile: async () => ({ download: async () => new Uint8Array() }),
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(replySpy).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
it("falls back to direct message chat id when sender user id is missing", async () => {
|
||||||
|
onSpy.mockReset();
|
||||||
|
const replySpy = replyModule.__replySpy as unknown as ReturnType<typeof vi.fn>;
|
||||||
|
replySpy.mockReset();
|
||||||
|
loadConfig.mockReturnValue({
|
||||||
|
channels: {
|
||||||
|
telegram: {
|
||||||
|
allowFrom: ["123456789"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
createTelegramBot({ token: "tok" });
|
||||||
|
const handler = getOnHandler("message") as (ctx: Record<string, unknown>) => Promise<void>;
|
||||||
|
|
||||||
|
await handler({
|
||||||
|
message: {
|
||||||
|
chat: { id: 123456789, type: "private" },
|
||||||
|
text: "hello",
|
||||||
|
date: 1736380800,
|
||||||
|
},
|
||||||
|
me: { username: "openclaw_bot" },
|
||||||
|
getFile: async () => ({ download: async () => new Uint8Array() }),
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(replySpy).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
it("allows group messages with wildcard in allowFrom when groupPolicy is 'allowlist'", async () => {
|
it("allows group messages with wildcard in allowFrom when groupPolicy is 'allowlist'", async () => {
|
||||||
onSpy.mockReset();
|
onSpy.mockReset();
|
||||||
const replySpy = replyModule.__replySpy as unknown as ReturnType<typeof vi.fn>;
|
const replySpy = replyModule.__replySpy as unknown as ReturnType<typeof vi.fn>;
|
||||||
|
|||||||
Reference in New Issue
Block a user