fix: normalize WhatsApp targets for groups and E.164 (#631) (thanks @imfing)
This commit is contained in:
@@ -48,7 +48,12 @@ import {
|
||||
import { registerAgentRunContext } from "../infra/agent-events.js";
|
||||
import { parseTelegramTarget } from "../telegram/targets.js";
|
||||
import { resolveTelegramToken } from "../telegram/token.js";
|
||||
import { normalizeE164, truncateUtf16Safe } from "../utils.js";
|
||||
import {
|
||||
isWhatsAppGroupJid,
|
||||
normalizeE164,
|
||||
normalizeWhatsAppTarget,
|
||||
truncateUtf16Safe,
|
||||
} from "../utils.js";
|
||||
import type { CronJob } from "./types.js";
|
||||
|
||||
export type RunCronAgentTurnResult = {
|
||||
@@ -203,14 +208,21 @@ function resolveDeliveryTarget(
|
||||
|
||||
const sanitizedWhatsappTo = (() => {
|
||||
if (provider !== "whatsapp") return rawTo;
|
||||
if (rawTo && isWhatsAppGroupJid(rawTo)) {
|
||||
return normalizeWhatsAppTarget(rawTo) || rawTo;
|
||||
}
|
||||
const rawAllow = cfg.whatsapp?.allowFrom ?? [];
|
||||
if (rawAllow.includes("*")) return rawTo;
|
||||
if (rawAllow.includes("*")) {
|
||||
return rawTo ? normalizeWhatsAppTarget(rawTo) : rawTo;
|
||||
}
|
||||
const allowFrom = rawAllow
|
||||
.map((val) => normalizeE164(val))
|
||||
.filter((val) => val.length > 1);
|
||||
if (allowFrom.length === 0) return rawTo;
|
||||
if (allowFrom.length === 0) {
|
||||
return rawTo ? normalizeWhatsAppTarget(rawTo) : rawTo;
|
||||
}
|
||||
if (!rawTo) return allowFrom[0];
|
||||
const normalized = normalizeE164(rawTo);
|
||||
const normalized = normalizeWhatsAppTarget(rawTo);
|
||||
if (allowFrom.includes(normalized)) return normalized;
|
||||
return allowFrom[0];
|
||||
})();
|
||||
@@ -543,7 +555,7 @@ export async function runCronIsolatedAgentTurn(params: {
|
||||
summary: "Delivery skipped (no WhatsApp recipient).",
|
||||
};
|
||||
}
|
||||
const to = normalizeE164(resolvedDelivery.to);
|
||||
const to = normalizeWhatsAppTarget(resolvedDelivery.to);
|
||||
try {
|
||||
await deliverPayloadsWithMedia({
|
||||
payloads,
|
||||
|
||||
Reference in New Issue
Block a user