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

推荐订阅源

爱范儿
爱范儿
MyScale Blog
MyScale Blog
Recent Announcements
Recent Announcements
N
Netflix TechBlog - Medium
GbyAI
GbyAI
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
Martin Fowler
Martin Fowler
腾讯CDC
大猫的无限游戏
大猫的无限游戏
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
WordPress大学
WordPress大学
P
Proofpoint News Feed
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Y
Y Combinator 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
Mattermost: refresh slash callback command validation (#7...
eleqtrizit · 2026-05-01 · via Recent Commits to openclaw:main

@@ -17,6 +17,8 @@ import type { MattermostClient } from "./client.js";

17171818

// ─── Types ───────────────────────────────────────────────────────────────────

191920+

export const MATTERMOST_SLASH_POST_METHOD = "P";

21+2022

export type MattermostSlashCommandConfig = {

2123

/** Enable native slash commands. "auto" resolves to false for now (opt-in). */

2224

native: boolean | "auto";

@@ -45,6 +47,7 @@ export type MattermostRegisteredCommand = {

4547

trigger: string;

4648

teamId: string;

4749

token: string;

50+

url: string;

4851

/** True when this process created the command and should delete it on shutdown. */

4952

managed: boolean;

5053

};

@@ -84,7 +87,7 @@ export type MattermostSlashCommandResponse = {

8487

type MattermostCommandCreate = {

8588

team_id: string;

8689

trigger: string;

87-

method: "P" | "G";

90+

method: typeof MATTERMOST_SLASH_POST_METHOD | "G";

8891

url: string;

8992

description?: string;

9093

auto_complete: boolean;

@@ -98,15 +101,15 @@ type MattermostCommandUpdate = {

98101

id: string;

99102

team_id: string;

100103

trigger: string;

101-

method: "P" | "G";

104+

method: typeof MATTERMOST_SLASH_POST_METHOD | "G";

102105

url: string;

103106

description?: string;

104107

auto_complete: boolean;

105108

auto_complete_desc?: string;

106109

auto_complete_hint?: string;

107110

};

108111109-

type MattermostCommandResponse = {

112+

export type MattermostCommandResponse = {

110113

id: string;

111114

token: string;

112115

team_id: string;

@@ -192,9 +195,25 @@ export const DEFAULT_COMMAND_SPECS: MattermostCommandSpec[] = [

192195

export async function listMattermostCommands(

193196

client: MattermostClient,

194197

teamId: string,

198+

init?: Pick<RequestInit, "signal">,

195199

): Promise<MattermostCommandResponse[]> {

196200

return await client.request<MattermostCommandResponse[]>(

197201

`/commands?team_id=${encodeURIComponent(teamId)}&custom_only=true`,

202+

init,

203+

);

204+

}

205+206+

/**

207+

* Get a custom slash command by id.

208+

*/

209+

export async function getMattermostCommand(

210+

client: MattermostClient,

211+

commandId: string,

212+

init?: Pick<RequestInit, "signal">,

213+

): Promise<MattermostCommandResponse> {

214+

return await client.request<MattermostCommandResponse>(

215+

`/commands/${encodeURIComponent(commandId)}`,

216+

init,

198217

);

199218

}

200219

@@ -303,31 +322,36 @@ export async function registerSlashCommands(params: {

303322304323

const existingCmd = ownedCommands[0];

305324306-

// Already registered with the correct callback URL

307-

if (existingCmd && existingCmd.url === callbackUrl) {

325+

const existingNeedsUpdate = existingCmd

326+

? existingCmd.url !== callbackUrl || existingCmd.method !== MATTERMOST_SLASH_POST_METHOD

327+

: false;

328+329+

// Already registered with the correct callback URL and method.

330+

if (existingCmd && !existingNeedsUpdate) {

308331

log?.(`mattermost: command /${spec.trigger} already registered (id=${existingCmd.id})`);

309332

registered.push({

310333

id: existingCmd.id,

311334

trigger: spec.trigger,

312335

teamId,

313336

token: existingCmd.token,

337+

url: callbackUrl,

314338

managed: false,

315339

});

316340

continue;

317341

}

318342319-

// Exists but points to a different URL: attempt to reconcile by updating

320-

// (useful during callback URL migrations).

321-

if (existingCmd && existingCmd.url !== callbackUrl) {

343+

// Exists but has drifted critical callback fields: attempt to reconcile by

344+

// updating (useful during callback URL migrations or method drift).

345+

if (existingCmd && existingNeedsUpdate) {

322346

log?.(

323-

`mattermost: command /${spec.trigger} exists with different callback URL; updating (id=${existingCmd.id})`,

347+

`mattermost: command /${spec.trigger} exists with different callback settings; updating (id=${existingCmd.id})`,

324348

);

325349

try {

326350

const updated = await updateMattermostCommand(client, {

327351

id: existingCmd.id,

328352

team_id: teamId,

329353

trigger: spec.trigger,

330-

method: "P",

354+

method: MATTERMOST_SLASH_POST_METHOD,

331355

url: callbackUrl,

332356

description: spec.description,

333357

auto_complete: spec.autoComplete,

@@ -339,6 +363,7 @@ export async function registerSlashCommands(params: {

339363

trigger: spec.trigger,

340364

teamId,

341365

token: updated.token,

366+

url: callbackUrl,

342367

managed: false,

343368

});

344369

continue;

@@ -365,7 +390,7 @@ export async function registerSlashCommands(params: {

365390

const created = await createMattermostCommand(client, {

366391

team_id: teamId,

367392

trigger: spec.trigger,

368-

method: "P",

393+

method: MATTERMOST_SLASH_POST_METHOD,

369394

url: callbackUrl,

370395

description: spec.description,

371396

auto_complete: spec.autoComplete,

@@ -378,6 +403,7 @@ export async function registerSlashCommands(params: {

378403

trigger: spec.trigger,

379404

teamId,

380405

token: created.token,

406+

url: callbackUrl,

381407

managed: true,

382408

});

383409

} catch (err) {

@@ -499,6 +525,10 @@ export function resolveCommandText(

499525

return args ? `/${commandName} ${args}` : `/${commandName}`;

500526

}

501527528+

export function normalizeSlashCommandTrigger(command: string): string {

529+

return command.replace(/^\//, "").trim();

530+

}

531+502532

// ─── Config resolution ───────────────────────────────────────────────────────

503533504534

const DEFAULT_CALLBACK_PATH = "/api/channels/mattermost/command";