fix(telegram): resolve grammY fetch type mismatch (#512)
Co-authored-by: Yuri Chukhlib <yuri.v.chu@gmail.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import type { ApiClientOptions } from "grammy";
|
||||
import { Bot } from "grammy";
|
||||
import { resolveTelegramFetch } from "./fetch.js";
|
||||
|
||||
@@ -8,10 +9,10 @@ export async function setTelegramWebhook(opts: {
|
||||
dropPendingUpdates?: boolean;
|
||||
}) {
|
||||
const fetchImpl = resolveTelegramFetch();
|
||||
const bot = new Bot(
|
||||
opts.token,
|
||||
fetchImpl ? { client: { fetch: fetchImpl } } : undefined,
|
||||
);
|
||||
const client: ApiClientOptions | undefined = fetchImpl
|
||||
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
|
||||
: undefined;
|
||||
const bot = new Bot(opts.token, client ? { client } : undefined);
|
||||
await bot.api.setWebhook(opts.url, {
|
||||
secret_token: opts.secret,
|
||||
drop_pending_updates: opts.dropPendingUpdates ?? false,
|
||||
@@ -20,9 +21,9 @@ export async function setTelegramWebhook(opts: {
|
||||
|
||||
export async function deleteTelegramWebhook(opts: { token: string }) {
|
||||
const fetchImpl = resolveTelegramFetch();
|
||||
const bot = new Bot(
|
||||
opts.token,
|
||||
fetchImpl ? { client: { fetch: fetchImpl } } : undefined,
|
||||
);
|
||||
const client: ApiClientOptions | undefined = fetchImpl
|
||||
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
|
||||
: undefined;
|
||||
const bot = new Bot(opts.token, client ? { client } : undefined);
|
||||
await bot.api.deleteWebhook();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user