Adds support for separate replyToMode settings for DMs vs channels:
- Add channels.slack.dm.replyToMode for DM-specific threading
- Keep channels.slack.replyToMode as default for channels
- Add resolveSlackReplyToMode helper to centralize logic
- Pass chatType through threading resolution chain
Usage:
```json5
{
channels: {
slack: {
replyToMode: "off", // channels
dm: {
replyToMode: "all" // DMs always thread
}
}
}
}
```
When dm.replyToMode is set, DMs use that mode; channels use the
top-level replyToMode. Backward compatible when not configured.
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import { getChannelDock } from "../../channels/dock.js";
|
|
import { normalizeChannelId } from "../../channels/plugins/index.js";
|
|
import type { ClawdbotConfig } from "../../config/config.js";
|
|
import type { ReplyToMode } from "../../config/types.js";
|
|
import type { OriginatingChannelType } from "../templating.js";
|
|
import type { ReplyPayload } from "../types.js";
|
|
|
|
export function resolveReplyToMode(
|
|
cfg: ClawdbotConfig,
|
|
channel?: OriginatingChannelType,
|
|
accountId?: string | null,
|
|
chatType?: string | null,
|
|
): ReplyToMode {
|
|
const provider = normalizeChannelId(channel);
|
|
if (!provider) return "all";
|
|
const resolved = getChannelDock(provider)?.threading?.resolveReplyToMode?.({
|
|
cfg,
|
|
accountId,
|
|
chatType,
|
|
});
|
|
return resolved ?? "all";
|
|
}
|
|
|
|
export function createReplyToModeFilter(
|
|
mode: ReplyToMode,
|
|
opts: { allowTagsWhenOff?: boolean } = {},
|
|
) {
|
|
let hasThreaded = false;
|
|
return (payload: ReplyPayload): ReplyPayload => {
|
|
if (!payload.replyToId) return payload;
|
|
if (mode === "off") {
|
|
if (opts.allowTagsWhenOff && payload.replyToTag) return payload;
|
|
return { ...payload, replyToId: undefined };
|
|
}
|
|
if (mode === "all") return payload;
|
|
if (hasThreaded) {
|
|
return { ...payload, replyToId: undefined };
|
|
}
|
|
hasThreaded = true;
|
|
return payload;
|
|
};
|
|
}
|
|
|
|
export function createReplyToModeFilterForChannel(
|
|
mode: ReplyToMode,
|
|
channel?: OriginatingChannelType,
|
|
) {
|
|
const provider = normalizeChannelId(channel);
|
|
const allowTagsWhenOff = provider
|
|
? Boolean(getChannelDock(provider)?.threading?.allowTagsWhenOff)
|
|
: false;
|
|
return createReplyToModeFilter(mode, {
|
|
allowTagsWhenOff,
|
|
});
|
|
}
|