mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-29 19:01:44 +00:00
refactor(telegram): tighten api result typings
This commit is contained in:
@@ -11,6 +11,7 @@ import { makeProxyFetch } from "./proxy.js";
|
||||
type TelegramApiOk<T> = { ok: true; result: T };
|
||||
type TelegramApiErr = { ok: false; description?: string };
|
||||
type TelegramGroupMembershipAuditData = Omit<TelegramGroupMembershipAudit, "elapsedMs">;
|
||||
type TelegramChatMemberResult = { status?: string };
|
||||
|
||||
export async function auditTelegramGroupMembershipImpl(
|
||||
params: AuditTelegramGroupMembershipParams,
|
||||
@@ -27,7 +28,7 @@ export async function auditTelegramGroupMembershipImpl(
|
||||
try {
|
||||
const url = `${base}/getChatMember?chat_id=${encodeURIComponent(chatId)}&user_id=${encodeURIComponent(String(params.botId))}`;
|
||||
const res = await fetchWithTimeout(url, {}, params.timeoutMs, fetcher);
|
||||
const json = (await res.json()) as TelegramApiOk<{ status?: string }> | TelegramApiErr;
|
||||
const json = (await res.json()) as TelegramApiOk<TelegramChatMemberResult> | TelegramApiErr;
|
||||
if (!res.ok || !isRecord(json) || !json.ok) {
|
||||
const desc =
|
||||
isRecord(json) && !json.ok && typeof json.description === "string"
|
||||
@@ -43,9 +44,8 @@ export async function auditTelegramGroupMembershipImpl(
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const status = isRecord((json as TelegramApiOk<unknown>).result)
|
||||
? ((json as TelegramApiOk<{ status?: string }>).result.status ?? null)
|
||||
: null;
|
||||
const status =
|
||||
isRecord(json.result) && typeof json.result.status === "string" ? json.result.status : null;
|
||||
const ok = status === "creator" || status === "administrator" || status === "member";
|
||||
groups.push({
|
||||
chatId,
|
||||
|
||||
@@ -21,6 +21,8 @@ type TelegramSendMessageDraft = (
|
||||
},
|
||||
) => Promise<unknown>;
|
||||
|
||||
type TelegramSendMessageParams = Parameters<Bot["api"]["sendMessage"]>[2];
|
||||
|
||||
/**
|
||||
* Keep draft-id allocation shared across bundled chunks so concurrent preview
|
||||
* lanes do not accidentally reuse draft ids when code-split entries coexist.
|
||||
@@ -179,7 +181,7 @@ export function createTelegramDraftStream(params: {
|
||||
: replyParams;
|
||||
const usedThreadParams =
|
||||
"message_thread_id" in (sendParams ?? {}) &&
|
||||
typeof (sendParams as { message_thread_id?: unknown }).message_thread_id === "number";
|
||||
typeof sendParams?.message_thread_id === "number";
|
||||
try {
|
||||
return {
|
||||
sent: await params.api.sendMessage(chatId, sendArgs.renderedText, sendParams),
|
||||
@@ -189,9 +191,7 @@ export function createTelegramDraftStream(params: {
|
||||
if (!usedThreadParams || !THREAD_NOT_FOUND_RE.test(String(err))) {
|
||||
throw err;
|
||||
}
|
||||
const threadlessParams = {
|
||||
...(sendParams as Record<string, unknown>),
|
||||
};
|
||||
const threadlessParams: TelegramSendMessageParams = { ...(sendParams ?? {}) };
|
||||
delete threadlessParams.message_thread_id;
|
||||
params.warn?.(sendArgs.fallbackWarnMessage);
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user