mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:50:43 +00:00
fix(slack): normalize action thread targets (#73931)
This commit is contained in:
@@ -515,6 +515,24 @@ describe("handleSlackAction", () => {
|
||||
await sendSecondMessageAndExpectNoThread({ cfg, context });
|
||||
});
|
||||
|
||||
it("replyToMode=first normalizes channel target when accounting explicit threadTs", async () => {
|
||||
const { cfg, context, hasRepliedRef } = createReplyToFirstScenario();
|
||||
|
||||
await handleSlackAction(
|
||||
{
|
||||
action: "sendMessage",
|
||||
to: "#c123",
|
||||
content: "Explicit",
|
||||
threadTs: "9999999999.999999",
|
||||
},
|
||||
cfg,
|
||||
context,
|
||||
);
|
||||
|
||||
expect(hasRepliedRef.value).toBe(true);
|
||||
await sendSecondMessageAndExpectNoThread({ cfg, context });
|
||||
});
|
||||
|
||||
it("replyToMode=first marks hasRepliedRef even when threadTs is explicit", async () => {
|
||||
const { cfg, context, hasRepliedRef } = createReplyToFirstScenario();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
||||
import { isSingleUseReplyToMode } from "openclaw/plugin-sdk/reply-reference";
|
||||
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
|
||||
import { parseSlackBlocksInput } from "./blocks-input.js";
|
||||
import {
|
||||
createActionGate,
|
||||
@@ -26,6 +27,19 @@ const messagingActions = new Set([
|
||||
const reactionsActions = new Set(["react", "reactions"]);
|
||||
const pinActions = new Set(["pinMessage", "unpinMessage", "listPins"]);
|
||||
|
||||
function sameSlackChannelTarget(targetChannel: string, currentChannelId: string): boolean {
|
||||
const parsedTarget = parseSlackTarget(targetChannel, {
|
||||
defaultKind: "channel",
|
||||
});
|
||||
if (!parsedTarget || parsedTarget.kind !== "channel") {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
normalizeLowercaseStringOrEmpty(parsedTarget.id) ===
|
||||
normalizeLowercaseStringOrEmpty(currentChannelId)
|
||||
);
|
||||
}
|
||||
|
||||
type SlackActionsRuntimeModule = typeof import("./actions.runtime.js");
|
||||
type SlackAccountsRuntimeModule = typeof import("./accounts.runtime.js");
|
||||
|
||||
@@ -105,16 +119,8 @@ function resolveThreadTsFromContext(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const parsedTarget = parseSlackTarget(targetChannel, {
|
||||
defaultKind: "channel",
|
||||
});
|
||||
if (!parsedTarget || parsedTarget.kind !== "channel") {
|
||||
return undefined;
|
||||
}
|
||||
const normalizedTarget = parsedTarget.id;
|
||||
|
||||
// Different channel - don't inject
|
||||
if (normalizedTarget !== context.currentChannelId) {
|
||||
if (!sameSlackChannelTarget(targetChannel, context.currentChannelId)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -267,8 +273,7 @@ export async function handleSlackAction(
|
||||
// threadTs: once we send a message to the current channel, consider the
|
||||
// first reply "used" so later tool calls don't auto-thread again.
|
||||
if (context?.hasRepliedRef && context.currentChannelId) {
|
||||
const parsedTarget = parseSlackTarget(to, { defaultKind: "channel" });
|
||||
if (parsedTarget?.kind === "channel" && parsedTarget.id === context.currentChannelId) {
|
||||
if (sameSlackChannelTarget(to, context.currentChannelId)) {
|
||||
context.hasRepliedRef.value = true;
|
||||
}
|
||||
}
|
||||
@@ -310,8 +315,7 @@ export async function handleSlackAction(
|
||||
}
|
||||
|
||||
if (context?.hasRepliedRef && context.currentChannelId) {
|
||||
const parsedTarget = parseSlackTarget(to, { defaultKind: "channel" });
|
||||
if (parsedTarget?.kind === "channel" && parsedTarget.id === context.currentChannelId) {
|
||||
if (sameSlackChannelTarget(to, context.currentChannelId)) {
|
||||
context.hasRepliedRef.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,21 @@ describe("resolveSlackAutoThreadId", () => {
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("threads first matching prefixed channel target with bare current channel", () => {
|
||||
const hasRepliedRef = { value: false };
|
||||
|
||||
expect(
|
||||
resolveSlackAutoThreadId({
|
||||
to: "channel:C123",
|
||||
toolContext: createToolContext({
|
||||
replyToMode: "first",
|
||||
hasRepliedRef,
|
||||
}),
|
||||
}),
|
||||
).toBe("thread-1");
|
||||
expect(hasRepliedRef.value).toBe(false);
|
||||
});
|
||||
|
||||
it("skips auto-threading when reply mode or thread context blocks it", () => {
|
||||
expect(
|
||||
resolveSlackAutoThreadId({
|
||||
|
||||
Reference in New Issue
Block a user