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

推荐订阅源

Martin Fowler
Martin Fowler
Y
Y Combinator Blog
M
MIT News - Artificial intelligence
The Cloudflare Blog
WordPress大学
WordPress大学
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 司徒正美
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
C
Check Point Blog
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
V
V2EX
F
Fortinet All Blogs
B
Blog
大猫的无限游戏
大猫的无限游戏
N
Netflix TechBlog - Medium
B
Blog RSS Feed
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

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): preserve api scope errors · openclaw/openclaw...
steipete · 2026-05-02 · via Recent Commits to openclaw:main

@@ -70,32 +70,96 @@ type SlackSendOpts = {

7070

blocks?: (Block | KnownBlock)[];

7171

};

727273+

type SlackWebApiErrorData = {

74+

error?: unknown;

75+

needed?: unknown;

76+

response_metadata?: {

77+

scopes?: unknown;

78+

acceptedScopes?: unknown;

79+

};

80+

};

81+82+

type SlackWebApiError = Error & {

83+

data?: SlackWebApiErrorData;

84+

};

85+7386

function hasCustomIdentity(identity?: SlackSendIdentity): boolean {

7487

return Boolean(identity?.username || identity?.iconUrl || identity?.iconEmoji);

7588

}

768977-

function isSlackCustomizeScopeError(err: unknown): boolean {

90+

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

91+

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

92+

}

93+94+

function normalizeSlackScopeList(value: unknown): string[] {

95+

if (!Array.isArray(value)) {

96+

return [];

97+

}

98+

return value.flatMap((scope) => {

99+

const normalized = normalizeSlackApiString(scope);

100+

return normalized ? [normalized] : [];

101+

});

102+

}

103+104+

function getSlackWebApiErrorData(err: unknown): SlackWebApiErrorData | undefined {

78105

if (!(err instanceof Error)) {

79-

return false;

106+

return undefined;

80107

}

81-

const maybeData = err as Error & {

82-

data?: {

83-

error?: string;

84-

needed?: string;

85-

response_metadata?: { scopes?: string[]; acceptedScopes?: string[] };

86-

};

87-

};

88-

const code = normalizeLowercaseStringOrEmpty(maybeData.data?.error);

108+

const data = (err as SlackWebApiError).data;

109+

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

110+

return undefined;

111+

}

112+

return data;

113+

}

114+115+

function formatSlackWebApiErrorMessage(err: unknown): string | undefined {

116+

if (!(err instanceof Error)) {

117+

return undefined;

118+

}

119+

const data = getSlackWebApiErrorData(err);

120+

const code = normalizeSlackApiString(data?.error);

121+

if (!code) {

122+

return undefined;

123+

}

124+

const details: string[] = [];

125+

const needed = normalizeSlackApiString(data?.needed);

126+

if (needed) {

127+

details.push(`needed: ${needed}`);

128+

}

129+

const scopes = normalizeSlackScopeList(data?.response_metadata?.scopes);

130+

if (scopes.length) {

131+

details.push(`granted: ${scopes.join(", ")}`);

132+

}

133+

const acceptedScopes = normalizeSlackScopeList(data?.response_metadata?.acceptedScopes);

134+

if (acceptedScopes.length) {

135+

details.push(`accepted: ${acceptedScopes.join(", ")}`);

136+

}

137+

return `${err.message || `An API error occurred: ${code}`}${

138+

details.length ? ` (${details.join("; ")})` : ""

139+

}`;

140+

}

141+142+

function enrichSlackWebApiError(err: unknown): unknown {

143+

const message = formatSlackWebApiErrorMessage(err);

144+

if (!message || !(err instanceof Error) || message === err.message) {

145+

return err;

146+

}

147+

return new Error(message);

148+

}

149+150+

function isSlackCustomizeScopeError(err: unknown): boolean {

151+

const data = getSlackWebApiErrorData(err);

152+

const code = normalizeLowercaseStringOrEmpty(normalizeSlackApiString(data?.error));

89153

if (code !== "missing_scope") {

90154

return false;

91155

}

92-

const needed = normalizeLowercaseStringOrEmpty(maybeData.data?.needed);

156+

const needed = normalizeLowercaseStringOrEmpty(normalizeSlackApiString(data?.needed));

93157

if (needed?.includes("chat:write.customize")) {

94158

return true;

95159

}

96160

const scopes = [

97-

...(maybeData.data?.response_metadata?.scopes ?? []),

98-

...(maybeData.data?.response_metadata?.acceptedScopes ?? []),

161+

...normalizeSlackScopeList(data?.response_metadata?.scopes),

162+

...normalizeSlackScopeList(data?.response_metadata?.acceptedScopes),

99163

].map((scope) => normalizeLowercaseStringOrEmpty(scope));

100164

return scopes.includes("chat:write.customize");

101165

}

@@ -401,6 +465,22 @@ async function sendMessageSlackQueued(params: {

401465

token: string;

402466

recipient: SlackRecipient;

403467

blocks?: (Block | KnownBlock)[];

468+

}): Promise<SlackSendResult> {

469+

try {

470+

return await sendMessageSlackQueuedInner(params);

471+

} catch (err) {

472+

throw enrichSlackWebApiError(err);

473+

}

474+

}

475+476+

async function sendMessageSlackQueuedInner(params: {

477+

trimmedMessage: string;

478+

opts: SlackSendOpts;

479+

cfg: OpenClawConfig;

480+

account: ReturnType<typeof resolveSlackAccount>;

481+

token: string;

482+

recipient: SlackRecipient;

483+

blocks?: (Block | KnownBlock)[];

404484

}): Promise<SlackSendResult> {

405485

const { opts, cfg, account, token, recipient, blocks, trimmedMessage } = params;

406486

const client = opts.client ?? getSlackWriteClient(token);