Skip to content

Commit e90bdb9

Browse files
fix(zalo): treat chat ids as opaque strings
1 parent af9c536 commit e90bdb9

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

extensions/zalo/src/channel.directory.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,20 @@ describe("zalo directory", () => {
5555
expect(zaloPlugin.messaging?.normalizeTarget?.(" zl:234 ")).toBe("234");
5656
});
5757

58-
it("recognizes numeric and hex-like Bot API chat ids as direct targets", () => {
58+
it("recognizes opaque Bot API chat ids as direct targets", () => {
5959
const looksLikeId = zaloPlugin.messaging?.targetResolver?.looksLikeId;
6060
if (!looksLikeId) {
6161
throw new Error("expected Zalo target resolver");
6262
}
6363

6464
expect(looksLikeId("123456", "123456")).toBe(true);
6565
expect(looksLikeId("3becaa50ae12474c1e03", "3becaa50ae12474c1e03")).toBe(true);
66+
expect(looksLikeId("abc.xyz", "abc.xyz")).toBe(true);
6667
expect(looksLikeId("zalo:49270a5f8f1c66423f0d", "49270a5f8f1c66423f0d")).toBe(true);
68+
expect(looksLikeId("zalo:abc.xyz", "abc.xyz")).toBe(true);
6769
expect(looksLikeId("zl:3becaa50ae12474c1e03", "3becaa50ae12474c1e03")).toBe(true);
68-
expect(looksLikeId("support", "support")).toBe(false);
70+
expect(looksLikeId("zl:abc.xyz", "abc.xyz")).toBe(true);
71+
expect(looksLikeId("support", "support")).toBe(true);
72+
expect(looksLikeId("zalo: ", "")).toBe(false);
6973
});
7074
});

extensions/zalo/src/channel.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ function normalizeZaloMessagingTarget(raw: string): string | undefined {
7171
return trimmed.replace(/^(zalo|zl):/i, "").trim();
7272
}
7373

74-
const zaloChatIdPattern = /^(?:\d{3,}|(?=[a-f0-9]{12,}$)(?=.*[a-f])[a-f0-9]+)$/i;
75-
7674
function looksLikeZaloChatId(raw: string, normalized?: string): boolean {
7775
const target = normalizeZaloMessagingTarget(normalized ?? raw);
78-
return target ? zaloChatIdPattern.test(target) : false;
76+
return Boolean(target);
7977
}
8078

8179
const loadZaloChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime.js"));

0 commit comments

Comments
 (0)