refactor(telegram): unify username lookup plumbing
This commit is contained in:
parent
24473b7dd0
commit
7914ac01ab
@ -11,6 +11,26 @@ export function resolveTelegramChatLookupFetch(params?: {
|
||||
return resolveTelegramFetch(proxyFetch, { network: params?.network });
|
||||
}
|
||||
|
||||
export async function lookupTelegramChatId(params: {
|
||||
token: string;
|
||||
chatId: string;
|
||||
signal?: AbortSignal;
|
||||
apiRoot?: string;
|
||||
proxyUrl?: string;
|
||||
network?: TelegramNetworkConfig;
|
||||
}): Promise<string | null> {
|
||||
return fetchTelegramChatId({
|
||||
token: params.token,
|
||||
chatId: params.chatId,
|
||||
signal: params.signal,
|
||||
apiRoot: params.apiRoot,
|
||||
fetchImpl: resolveTelegramChatLookupFetch({
|
||||
proxyUrl: params.proxyUrl,
|
||||
network: params.network,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export async function fetchTelegramChatId(params: {
|
||||
token: string;
|
||||
chatId: string;
|
||||
|
||||
@ -11,7 +11,7 @@ import type { ChannelSetupAdapter, ChannelSetupDmPolicy } from "openclaw/plugin-
|
||||
import { formatCliCommand, formatDocsLink } from "openclaw/plugin-sdk/setup-tools";
|
||||
import type { TelegramNetworkConfig } from "../runtime-api.js";
|
||||
import { resolveDefaultTelegramAccountId, resolveTelegramAccount } from "./accounts.js";
|
||||
import { fetchTelegramChatId, resolveTelegramChatLookupFetch } from "./api-fetch.js";
|
||||
import { lookupTelegramChatId } from "./api-fetch.js";
|
||||
|
||||
const channel = "telegram" as const;
|
||||
|
||||
@ -51,10 +51,6 @@ export async function resolveTelegramAllowFromEntries(params: {
|
||||
proxyUrl?: string;
|
||||
network?: TelegramNetworkConfig;
|
||||
}) {
|
||||
const fetchImpl = resolveTelegramChatLookupFetch({
|
||||
proxyUrl: params.proxyUrl,
|
||||
network: params.network,
|
||||
});
|
||||
return await Promise.all(
|
||||
params.entries.map(async (entry) => {
|
||||
const numericId = parseTelegramAllowFromId(entry);
|
||||
@ -66,11 +62,12 @@ export async function resolveTelegramAllowFromEntries(params: {
|
||||
return { input: entry, resolved: false, id: null };
|
||||
}
|
||||
const username = stripped.startsWith("@") ? stripped : `@${stripped}`;
|
||||
const id = await fetchTelegramChatId({
|
||||
const id = await lookupTelegramChatId({
|
||||
token: params.credentialValue,
|
||||
chatId: username,
|
||||
apiRoot: params.apiRoot,
|
||||
fetchImpl,
|
||||
proxyUrl: params.proxyUrl,
|
||||
network: params.network,
|
||||
});
|
||||
return { input: entry, resolved: Boolean(id), id };
|
||||
}),
|
||||
|
||||
@ -4,8 +4,8 @@ import {
|
||||
listTelegramAccountIds,
|
||||
lookupTelegramChatId,
|
||||
normalizeTelegramAllowFromEntry,
|
||||
} from "../../extensions/telegram/api.js";
|
||||
import type { TelegramNetworkConfig } from "../config/types.telegram.js";
|
||||
} from "openclaw/plugin-sdk/telegram";
|
||||
import type { TelegramNetworkConfig } from "openclaw/plugin-sdk/telegram";
|
||||
import { normalizeChatChannelId } from "../channels/registry.js";
|
||||
import { formatCliCommand } from "../cli/command-format.js";
|
||||
import { resolveCommandSecretRefsViaGateway } from "../cli/command-secret-gateway.js";
|
||||
|
||||
@ -82,7 +82,7 @@ export {
|
||||
isNumericTelegramUserId,
|
||||
normalizeTelegramAllowFromEntry,
|
||||
} from "../../../extensions/telegram/api.js";
|
||||
export { fetchTelegramChatId } from "../../../extensions/telegram/api.js";
|
||||
export { fetchTelegramChatId, lookupTelegramChatId } from "../../../extensions/telegram/api.js";
|
||||
export {
|
||||
resolveTelegramInlineButtonsScope,
|
||||
resolveTelegramTargetChatType,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user