refactor(telegram): tighten chat action typings

This commit is contained in:
Ayaan Zaidi
2026-03-28 09:39:33 +05:30
parent 4018d04d56
commit efef319496
2 changed files with 8 additions and 9 deletions

View File

@@ -491,11 +491,7 @@ export function createTelegramBot(opts: TelegramBotOptions) {
// from ANY chat are tracked together — prevents infinite retry storms.
const sendChatActionHandler = createTelegramSendChatActionHandler({
sendChatActionFn: (chatId, action, threadParams) =>
bot.api.sendChatAction(
chatId,
action,
threadParams as Parameters<typeof bot.api.sendChatAction>[2],
),
bot.api.sendChatAction(chatId, action, threadParams),
logger: (message) => logVerbose(`telegram: ${message}`),
});

View File

@@ -1,3 +1,4 @@
import type { Bot } from "grammy";
import {
computeBackoff,
sleepWithAbort,
@@ -19,11 +20,13 @@ type ChatAction =
| "upload_video_note"
| "choose_sticker";
type TelegramSendChatActionParams = Parameters<Bot["api"]["sendChatAction"]>[2];
type SendChatActionFn = (
chatId: number | string,
action: ChatAction,
threadParams?: unknown,
) => Promise<unknown>;
threadParams?: TelegramSendChatActionParams,
) => Promise<true>;
export type TelegramSendChatActionHandler = {
/**
@@ -33,7 +36,7 @@ export type TelegramSendChatActionHandler = {
sendChatAction: (
chatId: number | string,
action: ChatAction,
threadParams?: unknown,
threadParams?: TelegramSendChatActionParams,
) => Promise<void>;
isSuspended: () => boolean;
reset: () => void;
@@ -85,7 +88,7 @@ export function createTelegramSendChatActionHandler({
const sendChatAction = async (
chatId: number | string,
action: ChatAction,
threadParams?: unknown,
threadParams?: TelegramSendChatActionParams,
): Promise<void> => {
if (suspended) {
return;