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

推荐订阅源

大猫的无限游戏
大猫的无限游戏
月光博客
月光博客
博客园 - Franky
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿
博客园 - 司徒正美
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
B
Blog RSS Feed
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
博客园_首页
S
SegmentFault 最新的问题
A
About on SuperTechFans
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
H
Help Net Security
MongoDB | Blog
MongoDB | Blog

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
refactor(telegram): unify outbound delivery adapter · ope...
obviyus · 2026-05-07 · via Recent Commits to openclaw:main

@@ -11,14 +11,8 @@ import {

1111

createChatChannelPlugin,

1212

} from "openclaw/plugin-sdk/channel-core";

1313

import { createAccountStatusSink } from "openclaw/plugin-sdk/channel-lifecycle";

14-

import {

15-

createMessageReceiptFromOutboundResults,

16-

defineChannelMessageAdapter,

17-

type ChannelMessageSendResult,

18-

type MessageReceiptPartKind,

19-

} from "openclaw/plugin-sdk/channel-message";

14+

import { createChannelMessageAdapterFromOutbound } from "openclaw/plugin-sdk/channel-message";

2015

import { createPairingPrefixStripper } from "openclaw/plugin-sdk/channel-pairing";

21-

import { attachChannelToResult } from "openclaw/plugin-sdk/channel-send-result";

2216

import {

2317

PAIRING_APPROVED_MESSAGE,

2418

buildTokenChannelStatusSummary,

@@ -62,9 +56,8 @@ import {

6256

import { resolveTelegramInlineButtonsScope } from "./inline-buttons.js";

6357

import * as monitorModule from "./monitor.js";

6458

import { looksLikeTelegramTargetId, normalizeTelegramMessagingTarget } from "./normalize.js";

65-

import { sendTelegramPayloadMessages } from "./outbound-adapter.js";

66-

import { telegramOutboundBaseAdapter } from "./outbound-base.js";

67-

import { parseTelegramReplyToMessageId, parseTelegramThreadId } from "./outbound-params.js";

59+

import { createTelegramOutboundAdapter } from "./outbound-adapter.js";

60+

import { parseTelegramThreadId } from "./outbound-params.js";

6861

import type { TelegramProbe } from "./probe.js";

6962

import * as probeModule from "./probe.js";

7063

import { resolveTelegramReactionLevel } from "./reaction-level.js";

@@ -108,8 +101,6 @@ async function loadTelegramUpdateOffsetRuntime() {

108101

return await telegramUpdateOffsetRuntimePromise;

109102

}

110103111-

type TelegramSendOptions = NonNullable<Parameters<TelegramSendFn>[2]>;

112-113104

function resolveTelegramProbe() {

114105

return (

115106

getOptionalTelegramRuntime()?.channel?.telegram?.probeTelegram ?? probeModule.probeTelegram

@@ -169,115 +160,39 @@ function resolveTelegramTokenHelper() {

169160

);

170161

}

171162172-

function buildTelegramSendOptions(params: {

173-

cfg: OpenClawConfig;

174-

mediaUrl?: string | null;

175-

mediaLocalRoots?: readonly string[] | null;

176-

mediaReadFile?: ((filePath: string) => Promise<Buffer>) | null;

177-

accountId?: string | null;

178-

replyToId?: string | null;

179-

threadId?: string | number | null;

180-

silent?: boolean | null;

181-

forceDocument?: boolean | null;

182-

gatewayClientScopes?: readonly string[] | null;

183-

}): TelegramSendOptions {

184-

return {

185-

verbose: false,

186-

cfg: params.cfg,

187-

...(params.mediaUrl ? { mediaUrl: params.mediaUrl } : {}),

188-

...(params.mediaLocalRoots?.length ? { mediaLocalRoots: params.mediaLocalRoots } : {}),

189-

...(params.mediaReadFile ? { mediaReadFile: params.mediaReadFile } : {}),

190-

messageThreadId: parseTelegramThreadId(params.threadId),

191-

replyToMessageId: parseTelegramReplyToMessageId(params.replyToId),

192-

accountId: params.accountId ?? undefined,

193-

silent: params.silent ?? undefined,

194-

forceDocument: params.forceDocument ?? undefined,

195-

...(Array.isArray(params.gatewayClientScopes)

196-

? { gatewayClientScopes: [...params.gatewayClientScopes] }

197-

: {}),

198-

};

199-

}

200-201-

async function sendTelegramOutbound(params: {

202-

cfg: OpenClawConfig;

203-

to: string;

204-

text: string;

205-

mediaUrl?: string | null;

206-

mediaLocalRoots?: readonly string[] | null;

207-

mediaReadFile?: ((filePath: string) => Promise<Buffer>) | null;

208-

accountId?: string | null;

209-

deps?: OutboundSendDeps;

210-

replyToId?: string | null;

211-

threadId?: string | number | null;

212-

silent?: boolean | null;

213-

forceDocument?: boolean | null;

214-

gatewayClientScopes?: readonly string[] | null;

215-

}) {

216-

const send = await resolveTelegramSend(params.deps);

217-

return await send(

218-

params.to,

219-

params.text,

220-

buildTelegramSendOptions({

221-

cfg: params.cfg,

222-

mediaUrl: params.mediaUrl,

223-

mediaLocalRoots: params.mediaLocalRoots,

224-

mediaReadFile: params.mediaReadFile,

225-

accountId: params.accountId,

226-

replyToId: params.replyToId,

227-

threadId: params.threadId,

228-

silent: params.silent,

229-

forceDocument: params.forceDocument,

230-

gatewayClientScopes: params.gatewayClientScopes,

163+

const telegramChannelOutbound = createTelegramOutboundAdapter({

164+

resolveSend: resolveTelegramSend,

165+

loadSendModule: loadTelegramSendModule,

166+

shouldSuppressLocalPayloadPrompt: ({ cfg, accountId, payload }) =>

167+

shouldSuppressLocalTelegramExecApprovalPrompt({

168+

cfg,

169+

accountId,

170+

payload,

231171

}),

232-

);

233-

}

234-235-

type TelegramMessageSendSourceResult = {

236-

messageId?: string;

237-

chatId?: string;

238-

receipt?: ChannelMessageSendResult["receipt"];

239-

};

240-241-

function toTelegramMessageSendResult(

242-

result: TelegramMessageSendSourceResult,

243-

kind: MessageReceiptPartKind,

244-

replyToId?: string | null,

245-

): ChannelMessageSendResult {

246-

const receipt =

247-

result.receipt ??

248-

createMessageReceiptFromOutboundResults({

249-

results: result.messageId

250-

? [

251-

{

252-

channel: "telegram",

253-

messageId: result.messageId,

254-

chatId: result.chatId,

255-

},

256-

]

257-

: [],

258-

kind,

259-

...(replyToId ? { replyToId } : {}),

260-

});

261-

return {

262-

messageId: result.messageId || receipt.primaryPlatformMessageId,

263-

receipt,

264-

};

265-

}

172+

beforeDeliverPayload: async ({ cfg, target, hint }) => {

173+

if (hint?.kind !== "approval-pending" || hint.approvalKind !== "exec") {

174+

return;

175+

}

176+

const threadId =

177+

typeof target.threadId === "number"

178+

? target.threadId

179+

: typeof target.threadId === "string"

180+

? Number.parseInt(target.threadId, 10)

181+

: undefined;

182+

const { sendTypingTelegram } = await loadTelegramSendModule();

183+

await sendTypingTelegram(target.to, {

184+

cfg,

185+

accountId: target.accountId ?? undefined,

186+

...(Number.isFinite(threadId) ? { messageThreadId: threadId } : {}),

187+

}).catch(() => {});

188+

},

189+

shouldTreatDeliveredTextAsVisible: shouldTreatTelegramDeliveredTextAsVisible,

190+

targetsMatchForReplySuppression: targetsMatchTelegramReplySuppression,

191+

preferFinalAssistantVisibleText: true,

192+

});

266193267-

const telegramMessageAdapter = defineChannelMessageAdapter({

194+

const telegramMessageAdapter = createChannelMessageAdapterFromOutbound<OpenClawConfig>({

268195

id: "telegram",

269-

durableFinal: {

270-

capabilities: {

271-

text: true,

272-

media: true,

273-

payload: true,

274-

silent: true,

275-

replyTo: true,

276-

thread: true,

277-

messageSendingHooks: true,

278-

batch: true,

279-

},

280-

},

281196

live: {

282197

capabilities: {

283198

draftPreview: true,

@@ -297,70 +212,7 @@ const telegramMessageAdapter = defineChannelMessageAdapter({

297212

defaultAckPolicy: "after_agent_dispatch",

298213

supportedAckPolicies: ["after_receive_record", "after_agent_dispatch"],

299214

},

300-

send: {

301-

text: async (ctx) =>

302-

toTelegramMessageSendResult(

303-

await sendTelegramOutbound({

304-

cfg: ctx.cfg,

305-

to: ctx.to,

306-

text: ctx.text,

307-

accountId: ctx.accountId,

308-

deps: ctx.deps,

309-

replyToId: ctx.replyToId,

310-

threadId: ctx.threadId,

311-

silent: ctx.silent,

312-

gatewayClientScopes: ctx.gatewayClientScopes,

313-

}),

314-

"text",

315-

ctx.replyToId,

316-

),

317-

media: async (ctx) =>

318-

toTelegramMessageSendResult(

319-

await sendTelegramOutbound({

320-

cfg: ctx.cfg,

321-

to: ctx.to,

322-

text: ctx.text,

323-

mediaUrl: ctx.mediaUrl,

324-

mediaLocalRoots: ctx.mediaLocalRoots,

325-

mediaReadFile: ctx.mediaReadFile,

326-

accountId: ctx.accountId,

327-

deps: ctx.deps,

328-

replyToId: ctx.replyToId,

329-

threadId: ctx.threadId,

330-

silent: ctx.silent,

331-

forceDocument: ctx.forceDocument,

332-

gatewayClientScopes: ctx.gatewayClientScopes,

333-

}),

334-

"media",

335-

ctx.replyToId,

336-

),

337-

payload: async (ctx) => {

338-

const send = await resolveTelegramSend(ctx.deps);

339-

const result = attachChannelToResult(

340-

"telegram",

341-

await sendTelegramPayloadMessages({

342-

send,

343-

to: ctx.to,

344-

payload: ctx.payload,

345-

baseOpts: {

346-

...buildTelegramSendOptions({

347-

cfg: ctx.cfg,

348-

mediaUrl: ctx.mediaUrl,

349-

mediaLocalRoots: ctx.mediaLocalRoots,

350-

accountId: ctx.accountId,

351-

replyToId: ctx.replyToId,

352-

threadId: ctx.threadId,

353-

silent: ctx.silent,

354-

forceDocument: ctx.forceDocument,

355-

gatewayClientScopes: ctx.gatewayClientScopes,

356-

}),

357-

...(ctx.mediaReadFile ? { mediaReadFile: ctx.mediaReadFile } : {}),

358-

},

359-

}),

360-

);

361-

return toTelegramMessageSendResult(result, "unknown", ctx.replyToId);

362-

},

363-

},

215+

outbound: telegramChannelOutbound,

364216

});

365217366218

const telegramMessageActions: ChannelMessageActionAdapter = {

@@ -1179,142 +1031,5 @@ export const telegramPlugin = createChatChannelPlugin({

11791031

return to.includes(":topic:") ? to : `${to}:topic:${threadId}`;

11801032

},

11811033

},

1182-

outbound: {

1183-

base: {

1184-

...telegramOutboundBaseAdapter,

1185-

shouldSuppressLocalPayloadPrompt: ({ cfg, accountId, payload }) =>

1186-

shouldSuppressLocalTelegramExecApprovalPrompt({

1187-

cfg,

1188-

accountId,

1189-

payload,

1190-

}),

1191-

beforeDeliverPayload: async ({ cfg, target, hint }) => {

1192-

if (hint?.kind !== "approval-pending" || hint.approvalKind !== "exec") {

1193-

return;

1194-

}

1195-

const threadId =

1196-

typeof target.threadId === "number"

1197-

? target.threadId

1198-

: typeof target.threadId === "string"

1199-

? Number.parseInt(target.threadId, 10)

1200-

: undefined;

1201-

const { sendTypingTelegram } = await loadTelegramSendModule();

1202-

await sendTypingTelegram(target.to, {

1203-

cfg,

1204-

accountId: target.accountId ?? undefined,

1205-

...(Number.isFinite(threadId) ? { messageThreadId: threadId } : {}),

1206-

}).catch(() => {});

1207-

},

1208-

shouldSkipPlainTextSanitization: ({ payload }) => Boolean(payload.channelData),

1209-

shouldTreatDeliveredTextAsVisible: shouldTreatTelegramDeliveredTextAsVisible,

1210-

preferFinalAssistantVisibleText: true,

1211-

targetsMatchForReplySuppression: targetsMatchTelegramReplySuppression,

1212-

resolveEffectiveTextChunkLimit: ({ fallbackLimit }) =>

1213-

typeof fallbackLimit === "number" ? Math.min(fallbackLimit, 4096) : 4096,

1214-

supportsPollDurationSeconds: true,

1215-

supportsAnonymousPolls: true,

1216-

sendPayload: async ({

1217-

cfg,

1218-

to,

1219-

payload,

1220-

mediaLocalRoots,

1221-

accountId,

1222-

deps,

1223-

replyToId,

1224-

threadId,

1225-

silent,

1226-

forceDocument,

1227-

gatewayClientScopes,

1228-

}) => {

1229-

const send = await resolveTelegramSend(deps);

1230-

const result = await sendTelegramPayloadMessages({

1231-

send,

1232-

to,

1233-

payload,

1234-

baseOpts: buildTelegramSendOptions({

1235-

cfg,

1236-

mediaLocalRoots,

1237-

accountId,

1238-

replyToId,

1239-

threadId,

1240-

silent,

1241-

forceDocument,

1242-

gatewayClientScopes,

1243-

}),

1244-

});

1245-

return attachChannelToResult("telegram", result);

1246-

},

1247-

},

1248-

attachedResults: {

1249-

channel: "telegram",

1250-

sendText: async ({

1251-

cfg,

1252-

to,

1253-

text,

1254-

accountId,

1255-

deps,

1256-

replyToId,

1257-

threadId,

1258-

silent,

1259-

gatewayClientScopes,

1260-

}) =>

1261-

await sendTelegramOutbound({

1262-

cfg,

1263-

to,

1264-

text,

1265-

accountId,

1266-

deps,

1267-

replyToId,

1268-

threadId,

1269-

silent,

1270-

gatewayClientScopes,

1271-

}),

1272-

sendMedia: async ({

1273-

cfg,

1274-

to,

1275-

text,

1276-

mediaUrl,

1277-

mediaLocalRoots,

1278-

accountId,

1279-

deps,

1280-

replyToId,

1281-

threadId,

1282-

silent,

1283-

gatewayClientScopes,

1284-

}) =>

1285-

await sendTelegramOutbound({

1286-

cfg,

1287-

to,

1288-

text,

1289-

mediaUrl,

1290-

mediaLocalRoots,

1291-

accountId,

1292-

deps,

1293-

replyToId,

1294-

threadId,

1295-

silent,

1296-

gatewayClientScopes,

1297-

}),

1298-

sendPoll: async ({

1299-

cfg,

1300-

to,

1301-

poll,

1302-

accountId,

1303-

threadId,

1304-

silent,

1305-

isAnonymous,

1306-

gatewayClientScopes,

1307-

}) => {

1308-

const { sendPollTelegram } = await loadTelegramSendModule();

1309-

return await sendPollTelegram(to, poll, {

1310-

cfg,

1311-

accountId: accountId ?? undefined,

1312-

messageThreadId: parseTelegramThreadId(threadId),

1313-

silent: silent ?? undefined,

1314-

isAnonymous: isAnonymous ?? undefined,

1315-

gatewayClientScopes,

1316-

});

1317-

},

1318-

},

1319-

},

1034+

outbound: telegramChannelOutbound,

13201035

});