2025-12-07 22:46:02 +01:00
|
|
|
import { Bot } 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 04:40:29 +01:00
|
|
|
const bot = new Bot(opts.token, {
|
|
|
|
|
client: { fetch: resolveTelegramFetch() },
|
|
|
|
|
});
|
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 04:40:29 +01:00
|
|
|
const bot = new Bot(opts.token, {
|
|
|
|
|
client: { fetch: resolveTelegramFetch() },
|
|
|
|
|
});
|
2025-12-07 22:46:02 +01:00
|
|
|
await bot.api.deleteWebhook();
|
|
|
|
|
}
|