refactor: reuse ack reaction helper for whatsapp
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { loadConfig } from "../../../config/config.js";
|
||||
import { logVerbose } from "../../../globals.js";
|
||||
import { shouldAckReactionForWhatsApp } from "../../../channels/ack-reactions.js";
|
||||
import { sendReactionWhatsApp } from "../../outbound.js";
|
||||
import { formatError } from "../../session.js";
|
||||
import type { WebInboundMsg } from "../types.js";
|
||||
@@ -24,30 +25,25 @@ export function maybeSendAckReaction(params: {
|
||||
const groupMode = ackConfig?.group ?? "mentions";
|
||||
const conversationIdForCheck = params.msg.conversationId ?? params.msg.from;
|
||||
|
||||
const shouldSendReaction = () => {
|
||||
if (!emoji) return false;
|
||||
|
||||
if (params.msg.chatType === "direct") {
|
||||
return directEnabled;
|
||||
}
|
||||
|
||||
if (params.msg.chatType === "group") {
|
||||
if (groupMode === "never") return false;
|
||||
if (groupMode === "always") return true;
|
||||
if (groupMode === "mentions") {
|
||||
const activation = resolveGroupActivationFor({
|
||||
const activation =
|
||||
params.msg.chatType === "group"
|
||||
? resolveGroupActivationFor({
|
||||
cfg: params.cfg,
|
||||
agentId: params.agentId,
|
||||
sessionKey: params.sessionKey,
|
||||
conversationId: conversationIdForCheck,
|
||||
});
|
||||
if (activation === "always") return true;
|
||||
return params.msg.wasMentioned === true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
})
|
||||
: null;
|
||||
const shouldSendReaction = () =>
|
||||
shouldAckReactionForWhatsApp({
|
||||
emoji,
|
||||
isDirect: params.msg.chatType === "direct",
|
||||
isGroup: params.msg.chatType === "group",
|
||||
directEnabled,
|
||||
groupMode,
|
||||
wasMentioned: params.msg.wasMentioned === true,
|
||||
groupActivated: activation === "always",
|
||||
});
|
||||
|
||||
if (!shouldSendReaction()) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user