mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 15:24:58 +00:00
telegram: centralize api error logging
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { type ApiClientOptions, Bot } from "grammy";
|
||||
import type { TelegramNetworkConfig } from "../config/types.telegram.js";
|
||||
import { resolveTelegramFetch } from "./fetch.js";
|
||||
import { withTelegramApiErrorLogging } from "./api-logging.js";
|
||||
|
||||
export async function setTelegramWebhook(opts: {
|
||||
token: string;
|
||||
@@ -14,9 +15,13 @@ export async function setTelegramWebhook(opts: {
|
||||
? { 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,
|
||||
await withTelegramApiErrorLogging({
|
||||
operation: "setWebhook",
|
||||
fn: () =>
|
||||
bot.api.setWebhook(opts.url, {
|
||||
secret_token: opts.secret,
|
||||
drop_pending_updates: opts.dropPendingUpdates ?? false,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -29,5 +34,8 @@ export async function deleteTelegramWebhook(opts: {
|
||||
? { fetch: fetchImpl as unknown as ApiClientOptions["fetch"] }
|
||||
: undefined;
|
||||
const bot = new Bot(opts.token, client ? { client } : undefined);
|
||||
await bot.api.deleteWebhook();
|
||||
await withTelegramApiErrorLogging({
|
||||
operation: "deleteWebhook",
|
||||
fn: () => bot.api.deleteWebhook(),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user