refactor: use shared pairing store for telegram

This commit is contained in:
Ayaan Zaidi
2026-02-01 14:55:41 +05:30
committed by Ayaan Zaidi
parent ca92597e1f
commit 24fbafa9a7
23 changed files with 95 additions and 288 deletions

View File

@@ -13,6 +13,7 @@ import { resolveChannelConfigWrites } from "../channels/plugins/config-writes.js
import { loadConfig } from "../config/config.js";
import { writeConfigFile } from "../config/io.js";
import { danger, logVerbose, warn } from "../globals.js";
import { readChannelAllowFromStore } from "../pairing/pairing-store.js";
import { withTelegramApiErrorLogging } from "./api-logging.js";
import { firstDefined, isSenderAllowed, normalizeAllowFromWithStore } from "./bot-access.js";
import { RegisterTelegramHandlerParams } from "./bot-native-commands.js";
@@ -21,7 +22,6 @@ import { resolveMedia } from "./bot/delivery.js";
import { resolveTelegramForumThreadId } from "./bot/helpers.js";
import { migrateTelegramGroupConfig } from "./group-migration.js";
import { resolveTelegramInlineButtonsScope } from "./inline-buttons.js";
import { readTelegramAllowFromStore } from "./pairing-store.js";
import { buildInlineKeyboard } from "./send.js";
export const registerTelegramHandlers = ({
@@ -142,7 +142,7 @@ export const registerTelegramHandlers = ({
}
}
const storeAllowFrom = await readTelegramAllowFromStore().catch(() => []);
const storeAllowFrom = await readChannelAllowFromStore("telegram").catch(() => []);
await processMessage(primaryEntry.ctx, allMedia, storeAllowFrom);
} catch (err) {
runtime.error?.(danger(`media group handler failed: ${String(err)}`));
@@ -173,7 +173,7 @@ export const registerTelegramHandlers = ({
date: last.msg.date ?? first.msg.date,
};
const storeAllowFrom = await readTelegramAllowFromStore().catch(() => []);
const storeAllowFrom = await readChannelAllowFromStore("telegram").catch(() => []);
const baseCtx = first.ctx as { me?: unknown; getFile?: unknown } & Record<string, unknown>;
const getFile =
typeof baseCtx.getFile === "function" ? baseCtx.getFile.bind(baseCtx) : async () => ({});
@@ -248,7 +248,7 @@ export const registerTelegramHandlers = ({
messageThreadId,
});
const { groupConfig, topicConfig } = resolveTelegramGroupConfig(chatId, resolvedThreadId);
const storeAllowFrom = await readTelegramAllowFromStore().catch(() => []);
const storeAllowFrom = await readChannelAllowFromStore("telegram").catch(() => []);
const groupAllowOverride = firstDefined(topicConfig?.allowFrom, groupConfig?.allowFrom);
const effectiveGroupAllow = normalizeAllowFromWithStore({
allowFrom: groupAllowOverride ?? groupAllowFrom,
@@ -492,7 +492,7 @@ export const registerTelegramHandlers = ({
isForum,
messageThreadId,
});
const storeAllowFrom = await readTelegramAllowFromStore().catch(() => []);
const storeAllowFrom = await readChannelAllowFromStore("telegram").catch(() => []);
const { groupConfig, topicConfig } = resolveTelegramGroupConfig(chatId, resolvedThreadId);
const groupAllowOverride = firstDefined(topicConfig?.allowFrom, groupConfig?.allowFrom);
const effectiveGroupAllow = normalizeAllowFromWithStore({