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

推荐订阅源

The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
宝玉的分享
宝玉的分享
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
量子位
Blog — PlanetScale
Blog — PlanetScale
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
D
Docker
罗磊的独立博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
IT之家
IT之家
MyScale Blog
MyScale Blog
Microsoft Azure Blog
Microsoft Azure 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
fix(slack): recover long dm text from blocks · openclaw/o...
steipete · 2026-05-02 · via Recent Commits to openclaw:main

@@ -14,6 +14,31 @@ type SlackResolvedMessageContent = {

1414

const SLACK_MENTION_RESOLUTION_CONCURRENCY = 4;

1515

const SLACK_MENTION_RESOLUTION_MAX_LOOKUPS_PER_MESSAGE = 20;

161617+

type SlackTextObject = {

18+

text?: unknown;

19+

};

20+21+

type SlackRichTextElement = {

22+

type?: unknown;

23+

text?: unknown;

24+

url?: unknown;

25+

user_id?: unknown;

26+

channel_id?: unknown;

27+

usergroup_id?: unknown;

28+

name?: unknown;

29+

range?: unknown;

30+

elements?: unknown;

31+

};

32+33+

type SlackBlockLike = {

34+

type?: unknown;

35+

text?: unknown;

36+

elements?: unknown;

37+

fields?: unknown;

38+

alt_text?: unknown;

39+

title?: unknown;

40+

};

41+1742

type SlackMediaModule = typeof import("../media.js");

1843

let slackMediaModulePromise: Promise<SlackMediaModule> | undefined;

1944

@@ -54,6 +79,152 @@ function renderSlackUserMentions(

5479

});

5580

}

568182+

function readString(value: unknown): string | undefined {

83+

return typeof value === "string" ? value : undefined;

84+

}

85+86+

function readTextObject(value: unknown): string | undefined {

87+

if (!value || typeof value !== "object") {

88+

return undefined;

89+

}

90+

return normalizeOptionalString(readString((value as SlackTextObject).text));

91+

}

92+93+

function renderSlackRichTextLeaf(element: SlackRichTextElement): string {

94+

switch (element.type) {

95+

case "text":

96+

return readString(element.text) ?? "";

97+

case "link":

98+

return readString(element.text) ?? readString(element.url) ?? "";

99+

case "user": {

100+

const userId = readString(element.user_id);

101+

return userId ? `<@${userId}>` : "";

102+

}

103+

case "channel": {

104+

const channelId = readString(element.channel_id);

105+

return channelId ? `<#${channelId}>` : "";

106+

}

107+

case "usergroup": {

108+

const usergroupId = readString(element.usergroup_id);

109+

return usergroupId ? `<!subteam^${usergroupId}>` : "";

110+

}

111+

case "broadcast": {

112+

const range = readString(element.range);

113+

return range ? `<!${range}>` : "";

114+

}

115+

case "emoji": {

116+

const name = readString(element.name);

117+

return name ? `:${name}:` : "";

118+

}

119+

default:

120+

return "";

121+

}

122+

}

123+124+

function renderSlackRichTextElements(elements: unknown): string {

125+

if (!Array.isArray(elements)) {

126+

return "";

127+

}

128+

const parts: string[] = [];

129+

for (const rawElement of elements) {

130+

if (!rawElement || typeof rawElement !== "object") {

131+

continue;

132+

}

133+

const element = rawElement as SlackRichTextElement;

134+

switch (element.type) {

135+

case "rich_text_section":

136+

case "rich_text_preformatted":

137+

case "rich_text_quote": {

138+

parts.push(renderSlackRichTextElements(element.elements));

139+

break;

140+

}

141+

case "rich_text_list": {

142+

const listText = Array.isArray(element.elements)

143+

? element.elements

144+

.map((child) =>

145+

child && typeof child === "object"

146+

? renderSlackRichTextElements((child as SlackRichTextElement).elements)

147+

: "",

148+

)

149+

.filter(Boolean)

150+

.join("\n")

151+

: "";

152+

parts.push(listText);

153+

break;

154+

}

155+

default:

156+

parts.push(renderSlackRichTextLeaf(element));

157+

break;

158+

}

159+

}

160+

return parts.join("");

161+

}

162+163+

function readSlackBlockText(block: unknown): string | undefined {

164+

if (!block || typeof block !== "object") {

165+

return undefined;

166+

}

167+

const blockLike = block as SlackBlockLike;

168+

switch (blockLike.type) {

169+

case "rich_text":

170+

return normalizeOptionalString(renderSlackRichTextElements(blockLike.elements));

171+

case "section": {

172+

const text = readTextObject(blockLike.text);

173+

if (text) {

174+

return text;

175+

}

176+

if (Array.isArray(blockLike.fields)) {

177+

const fields = blockLike.fields.map(readTextObject).filter(Boolean);

178+

return fields.length > 0 ? fields.join("\n") : undefined;

179+

}

180+

return undefined;

181+

}

182+

case "header":

183+

return readTextObject(blockLike.text);

184+

case "context": {

185+

if (!Array.isArray(blockLike.elements)) {

186+

return undefined;

187+

}

188+

const parts = blockLike.elements.map(readTextObject).filter(Boolean);

189+

return parts.length > 0 ? parts.join(" ") : undefined;

190+

}

191+

case "image":

192+

return (

193+

normalizeOptionalString(readString(blockLike.alt_text)) ?? readTextObject(blockLike.title)

194+

);

195+

case "video":

196+

return (

197+

readTextObject(blockLike.title) ?? normalizeOptionalString(readString(blockLike.alt_text))

198+

);

199+

default:

200+

return undefined;

201+

}

202+

}

203+204+

function resolveSlackBlocksText(blocks: unknown[] | undefined): string | undefined {

205+

if (!blocks?.length) {

206+

return undefined;

207+

}

208+

const parts = blocks.map(readSlackBlockText).filter(Boolean);

209+

return parts.length > 0 ? parts.join("\n") : undefined;

210+

}

211+212+

function chooseSlackPrimaryText(params: {

213+

messageText: string | undefined;

214+

blocksText: string | undefined;

215+

}): string | undefined {

216+

const { messageText, blocksText } = params;

217+

if (!blocksText) {

218+

return messageText;

219+

}

220+

if (!messageText) {

221+

return blocksText;

222+

}

223+

return blocksText.length > messageText.length && blocksText.startsWith(messageText)

224+

? blocksText

225+

: messageText;

226+

}

227+57228

function filterInheritedParentFiles(params: {

58229

files: SlackFile[] | undefined;

59230

isThreadReply: boolean;

@@ -143,11 +314,12 @@ export async function resolveSlackMessageContent(params: {

143314

.join("\n")

144315

: undefined;

145316146-

const textParts = [

147-

normalizeOptionalString(params.message.text),

148-

attachmentContent?.text,

149-

botAttachmentText,

150-

];

317+

const blocksText = resolveSlackBlocksText(params.message.blocks);

318+

const primaryText = chooseSlackPrimaryText({

319+

messageText: normalizeOptionalString(params.message.text),

320+

blocksText,

321+

});

322+

const textParts = [primaryText, attachmentContent?.text, botAttachmentText];

151323

const renderedMentions = new Map<string, string | null>();

152324

const resolveUserName = params.resolveUserName;

153325

if (resolveUserName) {