Add accountId and config support to Telegram webhook
The Telegram webhook and monitor now accept and pass through accountId and config parameters, enabling routing and configuration per Telegram account. Tests have been updated to verify correct bot instantiation and DM routing based on accountId bindings.
This commit is contained in:
committed by
Peter Steinberger
parent
ab993904d7
commit
ecb91bbb1a
@@ -14,25 +14,33 @@ const handlerSpy = vi.fn(
|
||||
const setWebhookSpy = vi.fn();
|
||||
const stopSpy = vi.fn();
|
||||
|
||||
const createTelegramBotSpy = vi.fn(() => ({
|
||||
api: { setWebhook: setWebhookSpy },
|
||||
stop: stopSpy,
|
||||
}));
|
||||
|
||||
vi.mock("grammy", () => ({
|
||||
webhookCallback: () => handlerSpy,
|
||||
}));
|
||||
|
||||
vi.mock("./bot.js", () => ({
|
||||
createTelegramBot: () => ({
|
||||
api: { setWebhook: setWebhookSpy },
|
||||
stop: stopSpy,
|
||||
}),
|
||||
createTelegramBot: (...args: unknown[]) => createTelegramBotSpy(...args),
|
||||
}));
|
||||
|
||||
describe("startTelegramWebhook", () => {
|
||||
it("starts server, registers webhook, and serves health", async () => {
|
||||
createTelegramBotSpy.mockClear();
|
||||
const abort = new AbortController();
|
||||
const { server } = await startTelegramWebhook({
|
||||
token: "tok",
|
||||
accountId: "opie",
|
||||
config: { bindings: [] },
|
||||
port: 0, // random free port
|
||||
abortSignal: abort.signal,
|
||||
});
|
||||
expect(createTelegramBotSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ accountId: "opie" }),
|
||||
);
|
||||
const address = server.address();
|
||||
if (!address || typeof address === "string") throw new Error("no address");
|
||||
const url = `http://127.0.0.1:${address.port}`;
|
||||
@@ -46,9 +54,12 @@ describe("startTelegramWebhook", () => {
|
||||
|
||||
it("invokes webhook handler on matching path", async () => {
|
||||
handlerSpy.mockClear();
|
||||
createTelegramBotSpy.mockClear();
|
||||
const abort = new AbortController();
|
||||
const { server } = await startTelegramWebhook({
|
||||
token: "tok",
|
||||
accountId: "opie",
|
||||
config: { bindings: [] },
|
||||
port: 0,
|
||||
abortSignal: abort.signal,
|
||||
path: "/hook",
|
||||
|
||||
Reference in New Issue
Block a user