mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:40:44 +00:00
fix(whatsapp): prefer lid mention resolution
This commit is contained in:
@@ -51,6 +51,37 @@ describe("resolveWhatsAppOutboundMentions", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("prefers explicit LID metadata over a phone JID id", () => {
|
||||
expect(
|
||||
resolveWhatsAppOutboundMentions({
|
||||
chatJid: "120363000000000000@g.us",
|
||||
text: "ping @15551234567 and @277038292303944",
|
||||
participants: [
|
||||
{
|
||||
id: "15551234567@s.whatsapp.net",
|
||||
lid: "277038292303944@lid",
|
||||
},
|
||||
],
|
||||
}),
|
||||
).toEqual({
|
||||
text: "ping @277038292303944 and @277038292303944",
|
||||
mentionedJids: ["277038292303944@lid"],
|
||||
});
|
||||
});
|
||||
|
||||
it("uses bare digit tokens for LIDs before phone numbers when participant keys collide", () => {
|
||||
expect(
|
||||
resolveWhatsAppOutboundMentions({
|
||||
chatJid: "120363000000000000@g.us",
|
||||
text: "ping @277038292303944 and @+277038292303944",
|
||||
participants: [{ id: "277038292303944@s.whatsapp.net" }, { id: "277038292303944@lid" }],
|
||||
}),
|
||||
).toEqual({
|
||||
text: "ping @277038292303944 and @+277038292303944",
|
||||
mentionedJids: ["277038292303944@lid", "277038292303944@s.whatsapp.net"],
|
||||
});
|
||||
});
|
||||
|
||||
it("applies LID rewrites by match position while skipping code spans", () => {
|
||||
expect(
|
||||
resolveWhatsAppOutboundMentions({
|
||||
|
||||
@@ -128,9 +128,13 @@ function participantValues(participant: WhatsAppOutboundMentionParticipant): {
|
||||
|
||||
function chooseMentionJid(participant: WhatsAppOutboundMentionParticipant): string | null {
|
||||
const values = participantValues(participant);
|
||||
const idJid = normalizeKnownUserJid(values.id ?? "");
|
||||
const lidJid = normalizeKnownUserJid(values.lid ?? "");
|
||||
return (
|
||||
normalizeKnownUserJid(values.id ?? "") ??
|
||||
normalizeKnownUserJid(values.lid ?? "") ??
|
||||
(idJid && isLidJid(idJid) ? idJid : null) ??
|
||||
(lidJid && isLidJid(lidJid) ? lidJid : null) ??
|
||||
idJid ??
|
||||
lidJid ??
|
||||
normalizeKnownUserJid(values.phoneNumber ?? "") ??
|
||||
normalizeKnownUserJid(values.e164 ?? "")
|
||||
);
|
||||
@@ -210,7 +214,9 @@ export function resolveWhatsAppOutboundMentions(params: {
|
||||
}
|
||||
const token = match[0];
|
||||
const digits = match[1].replace(/\D/g, "");
|
||||
const target = byPhone.get(digits) ?? byLid.get(digits);
|
||||
const target = token.startsWith("@+")
|
||||
? (byPhone.get(digits) ?? byLid.get(digits))
|
||||
: (byLid.get(digits) ?? byPhone.get(digits));
|
||||
if (!target) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user