Files
openclaw/extensions/slack/src/threading.ts
scoootscooob 8746362f5e refactor(slack): move Slack channel code to extensions/slack/src/ (#45621)
Move all Slack channel implementation files from src/slack/ to
extensions/slack/src/ and replace originals with shim re-exports.
This follows the extension migration pattern for channel plugins.

- Copy all .ts files to extensions/slack/src/ (preserving directory
  structure: monitor/, http/, monitor/events/, monitor/message-handler/)
- Transform import paths: external src/ imports use relative paths
  back to src/, internal slack imports stay relative within extension
- Replace all src/slack/ files with shim re-exports pointing to
  the extension copies
- Update tsconfig.plugin-sdk.dts.json rootDir from "src" to "." so
  the DTS build can follow shim chains into extensions/
- Update write-plugin-sdk-entry-dts.ts re-export path accordingly
- Preserve extensions/slack/index.ts, package.json, openclaw.plugin.json,
  src/channel.ts, src/runtime.ts, src/channel.test.ts (untouched)
2026-03-14 02:47:04 -07:00

59 lines
2.0 KiB
TypeScript

import type { ReplyToMode } from "../../../src/config/types.js";
import type { SlackAppMentionEvent, SlackMessageEvent } from "./types.js";
export type SlackThreadContext = {
incomingThreadTs?: string;
messageTs?: string;
isThreadReply: boolean;
replyToId?: string;
messageThreadId?: string;
};
export function resolveSlackThreadContext(params: {
message: SlackMessageEvent | SlackAppMentionEvent;
replyToMode: ReplyToMode;
}): SlackThreadContext {
const incomingThreadTs = params.message.thread_ts;
const eventTs = params.message.event_ts;
const messageTs = params.message.ts ?? eventTs;
const hasThreadTs = typeof incomingThreadTs === "string" && incomingThreadTs.length > 0;
const isThreadReply =
hasThreadTs && (incomingThreadTs !== messageTs || Boolean(params.message.parent_user_id));
const replyToId = incomingThreadTs ?? messageTs;
const messageThreadId = isThreadReply
? incomingThreadTs
: params.replyToMode === "all"
? messageTs
: undefined;
return {
incomingThreadTs,
messageTs,
isThreadReply,
replyToId,
messageThreadId,
};
}
/**
* Resolves Slack thread targeting for replies and status indicators.
*
* @returns replyThreadTs - Thread timestamp for reply messages
* @returns statusThreadTs - Thread timestamp for status indicators (typing, etc.)
* @returns isThreadReply - true if this is a genuine user reply in a thread,
* false if thread_ts comes from a bot status message (e.g. typing indicator)
*/
export function resolveSlackThreadTargets(params: {
message: SlackMessageEvent | SlackAppMentionEvent;
replyToMode: ReplyToMode;
}) {
const ctx = resolveSlackThreadContext(params);
const { incomingThreadTs, messageTs, isThreadReply } = ctx;
const replyThreadTs = isThreadReply
? incomingThreadTs
: params.replyToMode === "all"
? messageTs
: undefined;
const statusThreadTs = replyThreadTs;
return { replyThreadTs, statusThreadTs, isThreadReply };
}