mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-27 01:23:33 +00:00
fix(signal): canonicalize message targets in tool and inbound flows
This commit is contained in:
@@ -35,27 +35,36 @@ export function normalizeSignalMessagingTarget(raw: string): string | undefined
|
||||
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
const UUID_COMPACT_PATTERN = /^[0-9a-f]{32}$/i;
|
||||
|
||||
export function looksLikeSignalTargetId(raw: string): boolean {
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed) {
|
||||
return false;
|
||||
}
|
||||
if (/^(signal:)?(group:|username:|u:)/i.test(trimmed)) {
|
||||
return true;
|
||||
}
|
||||
if (/^(signal:)?uuid:/i.test(trimmed)) {
|
||||
const stripped = trimmed
|
||||
.replace(/^signal:/i, "")
|
||||
.replace(/^uuid:/i, "")
|
||||
.trim();
|
||||
if (!stripped) {
|
||||
return false;
|
||||
export function looksLikeSignalTargetId(raw: string, normalized?: string): boolean {
|
||||
const candidates = [raw, normalized ?? ""].map((value) => value.trim()).filter(Boolean);
|
||||
|
||||
for (const candidate of candidates) {
|
||||
if (/^(signal:)?(group:|username:|u:)/i.test(candidate)) {
|
||||
return true;
|
||||
}
|
||||
if (/^(signal:)?uuid:/i.test(candidate)) {
|
||||
const stripped = candidate
|
||||
.replace(/^signal:/i, "")
|
||||
.replace(/^uuid:/i, "")
|
||||
.trim();
|
||||
if (!stripped) {
|
||||
continue;
|
||||
}
|
||||
if (UUID_PATTERN.test(stripped) || UUID_COMPACT_PATTERN.test(stripped)) {
|
||||
return true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const withoutSignalPrefix = candidate.replace(/^signal:/i, "").trim();
|
||||
// Accept UUIDs (used by signal-cli for reactions)
|
||||
if (UUID_PATTERN.test(withoutSignalPrefix) || UUID_COMPACT_PATTERN.test(withoutSignalPrefix)) {
|
||||
return true;
|
||||
}
|
||||
if (/^\+?\d{3,}$/.test(withoutSignalPrefix)) {
|
||||
return true;
|
||||
}
|
||||
return UUID_PATTERN.test(stripped) || UUID_COMPACT_PATTERN.test(stripped);
|
||||
}
|
||||
// Accept UUIDs (used by signal-cli for reactions)
|
||||
if (UUID_PATTERN.test(trimmed) || UUID_COMPACT_PATTERN.test(trimmed)) {
|
||||
return true;
|
||||
}
|
||||
return /^\+?\d{3,}$/.test(trimmed);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,11 @@ describe("signal target normalization", () => {
|
||||
expect(looksLikeSignalTargetId("signal:uuid:123e4567-e89b-12d3-a456-426614174000")).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts signal-prefixed E.164 targets for detection", () => {
|
||||
expect(looksLikeSignalTargetId("signal:+15551234567")).toBe(true);
|
||||
expect(looksLikeSignalTargetId("signal:15551234567")).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts compact UUIDs for target detection", () => {
|
||||
expect(looksLikeSignalTargetId("123e4567e89b12d3a456426614174000")).toBe(true);
|
||||
expect(looksLikeSignalTargetId("uuid:123e4567e89b12d3a456426614174000")).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user