Telegram: cast fetch to grammy client type
This commit is contained in:
committed by
Peter Steinberger
parent
a0bb2bccaf
commit
897685a2de
@@ -1,6 +1,5 @@
|
|||||||
import type { ReactionType, ReactionTypeEmoji } from "@grammyjs/types";
|
import type { ReactionType, ReactionTypeEmoji } from "@grammyjs/types";
|
||||||
import type { ApiClientOptions } from "grammy";
|
import { Bot, InputFile, type ApiClientOptions } from "grammy";
|
||||||
import { Bot, InputFile } from "grammy";
|
|
||||||
import { loadConfig } from "../config/config.js";
|
import { loadConfig } from "../config/config.js";
|
||||||
import { formatErrorMessage } from "../infra/errors.js";
|
import { formatErrorMessage } from "../infra/errors.js";
|
||||||
import { recordProviderActivity } from "../infra/provider-activity.js";
|
import { recordProviderActivity } from "../infra/provider-activity.js";
|
||||||
@@ -123,7 +122,9 @@ export async function sendMessageTelegram(
|
|||||||
const client: ApiClientOptions | undefined = fetchImpl
|
const client: ApiClientOptions | undefined = fetchImpl
|
||||||
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
|
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
|
||||||
: undefined;
|
: undefined;
|
||||||
const api = opts.api ?? new Bot(token, client ? { client } : undefined).api;
|
const api =
|
||||||
|
opts.api ??
|
||||||
|
new Bot(token, client ? { client } : undefined).api;
|
||||||
const mediaUrl = opts.mediaUrl?.trim();
|
const mediaUrl = opts.mediaUrl?.trim();
|
||||||
|
|
||||||
// Build optional params for forum topics and reply threading.
|
// Build optional params for forum topics and reply threading.
|
||||||
@@ -295,7 +296,9 @@ export async function reactMessageTelegram(
|
|||||||
const client: ApiClientOptions | undefined = fetchImpl
|
const client: ApiClientOptions | undefined = fetchImpl
|
||||||
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
|
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
|
||||||
: undefined;
|
: undefined;
|
||||||
const api = opts.api ?? new Bot(token, client ? { client } : undefined).api;
|
const api =
|
||||||
|
opts.api ??
|
||||||
|
new Bot(token, client ? { client } : undefined).api;
|
||||||
const request = createTelegramRetryRunner({
|
const request = createTelegramRetryRunner({
|
||||||
retry: opts.retry,
|
retry: opts.retry,
|
||||||
configRetry: account.config.retry,
|
configRetry: account.config.retry,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import type { ApiClientOptions } from "grammy";
|
import { Bot, type ApiClientOptions } from "grammy";
|
||||||
import { Bot } from "grammy";
|
|
||||||
import { resolveTelegramFetch } from "./fetch.js";
|
import { resolveTelegramFetch } from "./fetch.js";
|
||||||
|
|
||||||
export async function setTelegramWebhook(opts: {
|
export async function setTelegramWebhook(opts: {
|
||||||
@@ -12,7 +11,10 @@ export async function setTelegramWebhook(opts: {
|
|||||||
const client: ApiClientOptions | undefined = fetchImpl
|
const client: ApiClientOptions | undefined = fetchImpl
|
||||||
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
|
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
|
||||||
: undefined;
|
: undefined;
|
||||||
const bot = new Bot(opts.token, client ? { client } : undefined);
|
const bot = new Bot(
|
||||||
|
opts.token,
|
||||||
|
client ? { client } : undefined,
|
||||||
|
);
|
||||||
await bot.api.setWebhook(opts.url, {
|
await bot.api.setWebhook(opts.url, {
|
||||||
secret_token: opts.secret,
|
secret_token: opts.secret,
|
||||||
drop_pending_updates: opts.dropPendingUpdates ?? false,
|
drop_pending_updates: opts.dropPendingUpdates ?? false,
|
||||||
@@ -24,6 +26,9 @@ export async function deleteTelegramWebhook(opts: { token: string }) {
|
|||||||
const client: ApiClientOptions | undefined = fetchImpl
|
const client: ApiClientOptions | undefined = fetchImpl
|
||||||
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
|
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
|
||||||
: undefined;
|
: undefined;
|
||||||
const bot = new Bot(opts.token, client ? { client } : undefined);
|
const bot = new Bot(
|
||||||
|
opts.token,
|
||||||
|
client ? { client } : undefined,
|
||||||
|
);
|
||||||
await bot.api.deleteWebhook();
|
await bot.api.deleteWebhook();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user