mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 14:54:31 +00:00
fix(slack): thread channel ID through inbound context for reactions (#34831)
Slack reaction/thread context routing fixes via canonical synthesis of #34831. Co-authored-by: Tak <tak@users.noreply.github.com>
This commit is contained in:
@@ -58,6 +58,7 @@ export function buildThreadingToolContext(params: {
|
||||
ReplyToId: sessionCtx.ReplyToId,
|
||||
ThreadLabel: sessionCtx.ThreadLabel,
|
||||
MessageThreadId: sessionCtx.MessageThreadId,
|
||||
NativeChannelId: sessionCtx.NativeChannelId,
|
||||
},
|
||||
hasRepliedRef,
|
||||
}) ?? {};
|
||||
|
||||
@@ -142,6 +142,8 @@ export type MsgContext = {
|
||||
GatewayClientScopes?: string[];
|
||||
/** Thread identifier (Telegram topic id or Matrix thread event id). */
|
||||
MessageThreadId?: string | number;
|
||||
/** Platform-native channel/conversation id (e.g. Slack DM channel "D…" id). */
|
||||
NativeChannelId?: string;
|
||||
/** Telegram forum supergroup marker. */
|
||||
IsForum?: boolean;
|
||||
/** Warning: DM has topics enabled but this message is not in a topic. */
|
||||
|
||||
@@ -257,6 +257,8 @@ export type ChannelThreadingContext = {
|
||||
ReplyToIdFull?: string;
|
||||
ThreadLabel?: string;
|
||||
MessageThreadId?: string | number;
|
||||
/** Platform-native channel/conversation id (e.g. Slack DM channel "D…" id). */
|
||||
NativeChannelId?: string;
|
||||
};
|
||||
|
||||
export type ChannelThreadingToolContext = {
|
||||
|
||||
@@ -727,6 +727,7 @@ export async function prepareSlackMessage(params: {
|
||||
CommandAuthorized: commandAuthorized,
|
||||
OriginatingChannel: "slack" as const,
|
||||
OriginatingTo: slackTo,
|
||||
NativeChannelId: message.channel,
|
||||
}) satisfies FinalizedMsgContext;
|
||||
const pinnedMainDmOwner = isDirectMessage
|
||||
? resolvePinnedMainDmOwnerFromAllowlist({
|
||||
|
||||
@@ -144,4 +144,35 @@ describe("buildSlackThreadingToolContext", () => {
|
||||
});
|
||||
expect(result.replyToMode).toBe("off");
|
||||
});
|
||||
|
||||
it("extracts currentChannelId from channel: prefixed To", () => {
|
||||
const result = buildSlackThreadingToolContext({
|
||||
cfg: emptyCfg,
|
||||
accountId: null,
|
||||
context: { ChatType: "channel", To: "channel:C1234ABC" },
|
||||
});
|
||||
expect(result.currentChannelId).toBe("C1234ABC");
|
||||
});
|
||||
|
||||
it("uses NativeChannelId for DM when To is user-prefixed", () => {
|
||||
const result = buildSlackThreadingToolContext({
|
||||
cfg: emptyCfg,
|
||||
accountId: null,
|
||||
context: {
|
||||
ChatType: "direct",
|
||||
To: "user:U8SUVSVGS",
|
||||
NativeChannelId: "D8SRXRDNF",
|
||||
},
|
||||
});
|
||||
expect(result.currentChannelId).toBe("D8SRXRDNF");
|
||||
});
|
||||
|
||||
it("returns undefined currentChannelId when neither channel: To nor NativeChannelId is set", () => {
|
||||
const result = buildSlackThreadingToolContext({
|
||||
cfg: emptyCfg,
|
||||
accountId: null,
|
||||
context: { ChatType: "direct", To: "user:U8SUVSVGS" },
|
||||
});
|
||||
expect(result.currentChannelId).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,10 +19,14 @@ export function buildSlackThreadingToolContext(params: {
|
||||
const hasExplicitThreadTarget = params.context.MessageThreadId != null;
|
||||
const effectiveReplyToMode = hasExplicitThreadTarget ? "all" : configuredReplyToMode;
|
||||
const threadId = params.context.MessageThreadId ?? params.context.ReplyToId;
|
||||
// For channel messages, To is "channel:C…" — extract the bare ID.
|
||||
// For DMs, To is "user:U…" which can't be used for reactions; fall back
|
||||
// to NativeChannelId (the raw Slack channel id, e.g. "D…").
|
||||
const currentChannelId = params.context.To?.startsWith("channel:")
|
||||
? params.context.To.slice("channel:".length)
|
||||
: params.context.NativeChannelId?.trim() || undefined;
|
||||
return {
|
||||
currentChannelId: params.context.To?.startsWith("channel:")
|
||||
? params.context.To.slice("channel:".length)
|
||||
: undefined,
|
||||
currentChannelId,
|
||||
currentThreadTs: threadId != null ? String(threadId) : undefined,
|
||||
replyToMode: effectiveReplyToMode,
|
||||
hasRepliedRef: params.hasRepliedRef,
|
||||
|
||||
Reference in New Issue
Block a user