fix: polish reply threading + tool dedupe (thanks @mneves75) (#326)
This commit is contained in:
36
src/auto-reply/reply/reply-threading.ts
Normal file
36
src/auto-reply/reply/reply-threading.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
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,
|
||||
): ReplyToMode {
|
||||
switch (channel) {
|
||||
case "telegram":
|
||||
return cfg.telegram?.replyToMode ?? "first";
|
||||
case "discord":
|
||||
return cfg.discord?.replyToMode ?? "off";
|
||||
case "slack":
|
||||
return cfg.slack?.replyToMode ?? "off";
|
||||
default:
|
||||
return "all";
|
||||
}
|
||||
}
|
||||
|
||||
export function createReplyToModeFilter(mode: ReplyToMode) {
|
||||
let hasThreaded = false;
|
||||
return (payload: ReplyPayload): ReplyPayload => {
|
||||
if (!payload.replyToId) return payload;
|
||||
if (mode === "off") {
|
||||
return { ...payload, replyToId: undefined };
|
||||
}
|
||||
if (mode === "all") return payload;
|
||||
if (hasThreaded) {
|
||||
return { ...payload, replyToId: undefined };
|
||||
}
|
||||
hasThreaded = true;
|
||||
return payload;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user