惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
GbyAI
GbyAI
爱范儿
爱范儿
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Check Point Blog
M
MIT News - Artificial intelligence
量子位
宝玉的分享
宝玉的分享
MongoDB | Blog
MongoDB | Blog
V
Visual Studio Blog
罗磊的独立博客
F
Fortinet All Blogs
美团技术团队
博客园_首页
博客园 - 【当耐特】
L
LangChain Blog
月光博客
月光博客
腾讯CDC
The Cloudflare Blog
D
Docker
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(e2e): bound Telegram proof Bot API calls · openclaw/o...
vincentkoc · 2026-05-27 · via Recent Commits to openclaw:main

@@ -0,0 +1,70 @@

1+

type JsonObject = Record<string, unknown>;

2+3+

type TelegramBotApiOptions = {

4+

baseUrl?: string;

5+

fetchImpl?: (url: string, init: RequestInit) => Promise<Response>;

6+

timeoutMs?: number;

7+

};

8+9+

const DEFAULT_BASE_URL =

10+

process.env.OPENCLAW_TELEGRAM_USER_BOT_API_BASE_URL ?? "https://api.telegram.org";

11+

const DEFAULT_TIMEOUT_MS = readPositiveInt(

12+

process.env.OPENCLAW_TELEGRAM_USER_BOT_API_TIMEOUT_MS,

13+

30000,

14+

);

15+16+

function readPositiveInt(raw: string | undefined, fallback: number) {

17+

const parsed = Number.parseInt(raw ?? "", 10);

18+

return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;

19+

}

20+21+

function optionalString(source: JsonObject, key: string) {

22+

const value = source[key];

23+

return typeof value === "string" && value.trim() ? value.trim() : undefined;

24+

}

25+26+

export async function telegramBotApi(

27+

token: string,

28+

method: string,

29+

body: JsonObject = {},

30+

options: TelegramBotApiOptions = {},

31+

) {

32+

const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;

33+

const timeoutMs = Math.max(1, options.timeoutMs ?? DEFAULT_TIMEOUT_MS);

34+

const timeoutError = Object.assign(

35+

new Error(`Telegram Bot API ${method} timed out after ${timeoutMs}ms`),

36+

{ code: "ETIMEDOUT" },

37+

);

38+

const controller = new AbortController();

39+

let timeout: NodeJS.Timeout | undefined;

40+

const timeoutPromise = new Promise<never>((_, reject) => {

41+

timeout = setTimeout(() => {

42+

controller.abort(timeoutError);

43+

reject(timeoutError);

44+

}, timeoutMs);

45+

timeout.unref?.();

46+

});

47+48+

try {

49+

const response = await Promise.race([

50+

(options.fetchImpl ?? fetch)(`${baseUrl}/bot${token}/${method}`, {

51+

method: "POST",

52+

headers: { "content-type": "application/json" },

53+

body: JSON.stringify(body),

54+

signal: controller.signal,

55+

}),

56+

timeoutPromise,

57+

]);

58+

const payload = (await Promise.race([response.json(), timeoutPromise])) as JsonObject;

59+

if (!response.ok || payload.ok !== true) {

60+

throw new Error(

61+

optionalString(payload, "description") ?? `${method} failed with HTTP ${response.status}`,

62+

);

63+

}

64+

return payload.result;

65+

} finally {

66+

if (timeout) {

67+

clearTimeout(timeout);

68+

}

69+

}

70+

}