wip
This commit is contained in:
@@ -1,8 +1,14 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
import type { ClawdbotConfig } from "../../config/config.js";
|
||||||
|
|
||||||
const mocks = vi.hoisted(() => ({
|
const mocks = vi.hoisted(() => ({
|
||||||
sendMessageDiscord: vi.fn(async () => ({ messageId: "m1", channelId: "c1" })),
|
sendMessageDiscord: vi.fn(async () => ({ messageId: "m1", channelId: "c1" })),
|
||||||
sendMessageIMessage: vi.fn(async () => ({ messageId: "ok" })),
|
sendMessageIMessage: vi.fn(async () => ({ messageId: "ok" })),
|
||||||
|
sendMessageMSTeams: vi.fn(async () => ({
|
||||||
|
messageId: "m1",
|
||||||
|
conversationId: "c1",
|
||||||
|
})),
|
||||||
sendMessageSignal: vi.fn(async () => ({ messageId: "t1" })),
|
sendMessageSignal: vi.fn(async () => ({ messageId: "t1" })),
|
||||||
sendMessageSlack: vi.fn(async () => ({ messageId: "m1", channelId: "c1" })),
|
sendMessageSlack: vi.fn(async () => ({ messageId: "m1", channelId: "c1" })),
|
||||||
sendMessageTelegram: vi.fn(async () => ({ messageId: "m1", chatId: "c1" })),
|
sendMessageTelegram: vi.fn(async () => ({ messageId: "m1", chatId: "c1" })),
|
||||||
@@ -15,6 +21,9 @@ vi.mock("../../discord/send.js", () => ({
|
|||||||
vi.mock("../../imessage/send.js", () => ({
|
vi.mock("../../imessage/send.js", () => ({
|
||||||
sendMessageIMessage: mocks.sendMessageIMessage,
|
sendMessageIMessage: mocks.sendMessageIMessage,
|
||||||
}));
|
}));
|
||||||
|
vi.mock("../../msteams/send.js", () => ({
|
||||||
|
sendMessageMSTeams: mocks.sendMessageMSTeams,
|
||||||
|
}));
|
||||||
vi.mock("../../signal/send.js", () => ({
|
vi.mock("../../signal/send.js", () => ({
|
||||||
sendMessageSignal: mocks.sendMessageSignal,
|
sendMessageSignal: mocks.sendMessageSignal,
|
||||||
}));
|
}));
|
||||||
@@ -143,4 +152,25 @@ describe("routeReply", () => {
|
|||||||
expect.objectContaining({ accountId: "acc-1", verbose: false }),
|
expect.objectContaining({ accountId: "acc-1", verbose: false }),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("routes MS Teams via proactive sender", async () => {
|
||||||
|
mocks.sendMessageMSTeams.mockClear();
|
||||||
|
const cfg = {
|
||||||
|
msteams: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
} as unknown as ClawdbotConfig;
|
||||||
|
await routeReply({
|
||||||
|
payload: { text: "hi" },
|
||||||
|
channel: "msteams",
|
||||||
|
to: "conversation:19:abc@thread.tacv2",
|
||||||
|
cfg,
|
||||||
|
});
|
||||||
|
expect(mocks.sendMessageMSTeams).toHaveBeenCalledWith({
|
||||||
|
cfg,
|
||||||
|
to: "conversation:19:abc@thread.tacv2",
|
||||||
|
text: "hi",
|
||||||
|
mediaUrl: undefined,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -153,8 +153,12 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
const fetchImpl = resolveTelegramFetch(opts.proxyFetch);
|
const fetchImpl = resolveTelegramFetch(opts.proxyFetch);
|
||||||
|
const isBun = "Bun" in globalThis || Boolean(process?.versions?.bun);
|
||||||
|
const shouldProvideFetch = Boolean(opts.proxyFetch) || isBun;
|
||||||
const client: ApiClientOptions | undefined = fetchImpl
|
const client: ApiClientOptions | undefined = fetchImpl
|
||||||
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
|
? shouldProvideFetch
|
||||||
|
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
|
||||||
|
: undefined
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const bot = new Bot(opts.token, client ? { client } : undefined);
|
const bot = new Bot(opts.token, client ? { client } : undefined);
|
||||||
|
|||||||
Reference in New Issue
Block a user