2026-01-08 15:16:53 +01:00
|
|
|
import { Bot, type ApiClientOptions } from "grammy";
|
2026-01-08 04:40:29 +01:00
|
|
|
import { resolveTelegramFetch } from "./fetch.js";
|
2025-12-07 22:46:02 +01:00
|
|
|
|
|
|
|
|
export async function setTelegramWebhook(opts: {
|
|
|
|
|
token: string;
|
|
|
|
|
url: string;
|
|
|
|
|
secret?: string;
|
|
|
|
|
dropPendingUpdates?: boolean;
|
|
|
|
|
}) {
|
2026-01-08 08:10:10 +01:00
|
|
|
const fetchImpl = resolveTelegramFetch();
|
2026-01-08 20:18:17 +01:00
|
|
|
const client: ApiClientOptions | undefined = fetchImpl
|
|
|
|
|
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
|
|
|
|
|
: undefined;
|
2026-01-08 15:16:53 +01:00
|
|
|
const bot = new Bot(
|
|
|
|
|
opts.token,
|
|
|
|
|
client ? { client } : undefined,
|
|
|
|
|
);
|
2025-12-07 22:46:02 +01:00
|
|
|
await bot.api.setWebhook(opts.url, {
|
|
|
|
|
secret_token: opts.secret,
|
|
|
|
|
drop_pending_updates: opts.dropPendingUpdates ?? false,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteTelegramWebhook(opts: { token: string }) {
|
2026-01-08 08:10:10 +01:00
|
|
|
const fetchImpl = resolveTelegramFetch();
|
2026-01-08 20:18:17 +01:00
|
|
|
const client: ApiClientOptions | undefined = fetchImpl
|
|
|
|
|
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
|
|
|
|
|
: undefined;
|
2026-01-08 15:16:53 +01:00
|
|
|
const bot = new Bot(
|
|
|
|
|
opts.token,
|
|
|
|
|
client ? { client } : undefined,
|
|
|
|
|
);
|
2025-12-07 22:46:02 +01:00
|
|
|
await bot.api.deleteWebhook();
|
|
|
|
|
}
|