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

推荐订阅源

I
InfoQ
S
SegmentFault 最新的问题
N
Netflix TechBlog - Medium
B
Blog
Jina AI
Jina AI
人人都是产品经理
人人都是产品经理
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 聂微东
Last Week in AI
Last Week in AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
V2EX
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
大猫的无限游戏
大猫的无限游戏
U
Unit 42
J
Java Code Geeks
IT之家
IT之家
aimingoo的专栏
aimingoo的专栏
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC

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): dedupe prompt media paths · openclaw/...
vincentkoc · 2026-06-18 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -1,6 +1,5 @@

11

// Telegram plugin module implements bot handlers behavior.

22

import { randomUUID } from "node:crypto";

3-

import path from "node:path";

43

import type { Message, ReactionTypeEmoji } from "grammy/types";

54

import { parseExecApprovalCommandText } from "openclaw/plugin-sdk/approval-reply-runtime";

65

import { resolveChannelConfigWrites } from "openclaw/plugin-sdk/channel-config-helpers";

@@ -165,41 +164,9 @@ import {

165164

isTelegramEditTargetMissingError,

166165

isTelegramMessageHasNoTextError,

167166

} from "./network-errors.js";

167+

import { resolveTelegramPromptMediaPath } from "./prompt-media-path.js";

168168

import { buildInlineKeyboard } from "./send.js";

169169
170-

function resolveTelegramPromptMediaPath(mediaPath: string): string | undefined {

171-

const toInboundMediaPath = (id: string): string | undefined => {

172-

if (

173-

!id ||

174-

id === "." ||

175-

id === ".." ||

176-

id.includes("/") ||

177-

id.includes("\\") ||

178-

id.includes("\0")

179-

) {

180-

return undefined;

181-

}

182-

return `media://inbound/${encodeURIComponent(id)}`;

183-

};

184-

const decodeInboundMediaId = (id: string): string | undefined => {

185-

try {

186-

return decodeURIComponent(id);

187-

} catch {

188-

return undefined;

189-

}

190-

};

191-

const canonicalMatch = /^media:\/\/inbound\/([^/\\]+)$/i.exec(mediaPath);

192-

if (canonicalMatch?.[1]) {

193-

const id = decodeInboundMediaId(canonicalMatch[1]);

194-

return id ? toInboundMediaPath(id) : undefined;

195-

}

196-

const normalized = mediaPath.replace(/\\/g, "/");

197-

if (!normalized.includes("/media/inbound/")) {

198-

return undefined;

199-

}

200-

return toInboundMediaPath(path.posix.basename(normalized));

201-

}

202-
203170

export const registerTelegramHandlers = ({

204171

cfg,

205172

accountId,

Original file line numberDiff line numberDiff line change

@@ -1,5 +1,4 @@

11

// Telegram plugin module implements bot message context.session behavior.

2-

import path from "node:path";

32

import {

43

type BuildChannelInboundEventContextParams,

54

type BuildChannelInboundEventContextAsyncParams,

@@ -34,6 +33,7 @@ import type {

3433

TelegramMessageContextSessionRuntimeOverrides,

3534

TelegramPromptContextEntry,

3635

} from "./bot-message-context.types.js";

36+

import { resolveTelegramPromptMediaPath } from "./prompt-media-path.js";

3737
3838

type TelegramMentionFacts = NonNullable<

3939

NonNullable<BuildChannelInboundEventContextParams["access"]>["mentions"]

@@ -145,39 +145,6 @@ function stripReplyChainForwarded(entry: TelegramReplyChainEntry): TelegramReply

145145

return withoutForwarded;

146146

}

147147
148-

function resolveTelegramPromptMediaPath(mediaPath: string): string | undefined {

149-

const toInboundMediaPath = (id: string): string | undefined => {

150-

if (

151-

!id ||

152-

id === "." ||

153-

id === ".." ||

154-

id.includes("/") ||

155-

id.includes("\\") ||

156-

id.includes("\0")

157-

) {

158-

return undefined;

159-

}

160-

return `media://inbound/${encodeURIComponent(id)}`;

161-

};

162-

const decodeInboundMediaId = (id: string): string | undefined => {

163-

try {

164-

return decodeURIComponent(id);

165-

} catch {

166-

return undefined;

167-

}

168-

};

169-

const canonicalMatch = /^media:\/\/inbound\/([^/\\]+)$/i.exec(mediaPath);

170-

if (canonicalMatch?.[1]) {

171-

const id = decodeInboundMediaId(canonicalMatch[1]);

172-

return id ? toInboundMediaPath(id) : undefined;

173-

}

174-

const normalized = mediaPath.replace(/\\/g, "/");

175-

if (!normalized.includes("/media/inbound/")) {

176-

return undefined;

177-

}

178-

return toInboundMediaPath(path.posix.basename(normalized));

179-

}

180-
181148

function formatReplyChainEntry(entry: TelegramReplyChainEntry, index: number): string {

182149

const forwardedAt = timestampMsToIsoString(entry.forwardedDate);

183150

const mediaPath = entry.mediaPath ? resolveTelegramPromptMediaPath(entry.mediaPath) : undefined;

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,36 @@

1+

import path from "node:path";

2+
3+

function toInboundMediaPath(id: string): string | undefined {

4+

if (

5+

!id ||

6+

id === "." ||

7+

id === ".." ||

8+

id.includes("/") ||

9+

id.includes("\\") ||

10+

id.includes("\0")

11+

) {

12+

return undefined;

13+

}

14+

return `media://inbound/${encodeURIComponent(id)}`;

15+

}

16+
17+

function decodeInboundMediaId(id: string): string | undefined {

18+

try {

19+

return decodeURIComponent(id);

20+

} catch {

21+

return undefined;

22+

}

23+

}

24+
25+

export function resolveTelegramPromptMediaPath(mediaPath: string): string | undefined {

26+

const canonicalMatch = /^media:\/\/inbound\/([^/\\]+)$/i.exec(mediaPath);

27+

if (canonicalMatch?.[1]) {

28+

const id = decodeInboundMediaId(canonicalMatch[1]);

29+

return id ? toInboundMediaPath(id) : undefined;

30+

}

31+

const normalized = mediaPath.replace(/\\/g, "/");

32+

if (!normalized.includes("/media/inbound/")) {

33+

return undefined;

34+

}

35+

return toInboundMediaPath(path.posix.basename(normalized));

36+

}