Skip to content

Commit 6b76a30

Browse files
fix(zalo): accept opaque string chat IDs (#101548)
Co-authored-by: Goutam Adwant <[email protected]>
1 parent 5a234d6 commit 6b76a30

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,21 @@ describe("zalo directory", () => {
5454
expect(zaloPlugin.pairing?.normalizeAllowEntry?.(" zalo:123 ")).toBe("123");
5555
expect(zaloPlugin.messaging?.normalizeTarget?.(" zl:234 ")).toBe("234");
5656
});
57+
58+
it("recognizes opaque Bot API chat ids as direct targets", () => {
59+
const looksLikeId = zaloPlugin.messaging?.targetResolver?.looksLikeId;
60+
if (!looksLikeId) {
61+
throw new Error("expected Zalo target resolver");
62+
}
63+
64+
expect(looksLikeId("123456", "123456")).toBe(true);
65+
expect(looksLikeId("3becaa50ae12474c1e03", "3becaa50ae12474c1e03")).toBe(true);
66+
expect(looksLikeId("abc.xyz", "abc.xyz")).toBe(true);
67+
expect(looksLikeId("zalo:49270a5f8f1c66423f0d", "49270a5f8f1c66423f0d")).toBe(true);
68+
expect(looksLikeId("zalo:abc.xyz", "abc.xyz")).toBe(true);
69+
expect(looksLikeId("zl:3becaa50ae12474c1e03", "3becaa50ae12474c1e03")).toBe(true);
70+
expect(looksLikeId("zl:abc.xyz", "abc.xyz")).toBe(true);
71+
expect(looksLikeId("support", "support")).toBe(true);
72+
expect(looksLikeId("zalo: ", "")).toBe(false);
73+
});
5774
});

extensions/zalo/src/channel.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ import { createStaticReplyToModeResolver } from "openclaw/plugin-sdk/conversatio
3030
import { createChannelDirectoryAdapter } from "openclaw/plugin-sdk/directory-runtime";
3131
import { listResolvedDirectoryUserEntriesFromAllowFrom } from "openclaw/plugin-sdk/directory-runtime";
3232
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
33-
import {
34-
isNumericTargetId,
35-
sendPayloadWithChunkedTextAndMedia,
36-
} from "openclaw/plugin-sdk/reply-payload";
33+
import { sendPayloadWithChunkedTextAndMedia } from "openclaw/plugin-sdk/reply-payload";
3734
import {
3835
createComputedAccountStatusAdapter,
3936
createDefaultChannelRuntimeState,
@@ -74,6 +71,11 @@ function normalizeZaloMessagingTarget(raw: string): string | undefined {
7471
return trimmed.replace(/^(zalo|zl):/i, "").trim();
7572
}
7673

74+
function looksLikeZaloChatId(raw: string, normalized?: string): boolean {
75+
const target = normalizeZaloMessagingTarget(normalized ?? raw);
76+
return Boolean(target);
77+
}
78+
7779
const loadZaloChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime.js"));
7880
const zaloSetupWizard = createZaloSetupWizardProxy(
7981
async () => (await import("./setup-surface.js")).zaloSetupWizard,
@@ -234,7 +236,7 @@ export const zaloPlugin: ChannelPlugin<ResolvedZaloAccount, ZaloProbeResult> =
234236
normalizeTarget: normalizeZaloMessagingTarget,
235237
resolveOutboundSessionRoute: (params) => resolveZaloOutboundSessionRoute(params),
236238
targetResolver: {
237-
looksLikeId: isNumericTargetId,
239+
looksLikeId: looksLikeZaloChatId,
238240
hint: "<chatId>",
239241
},
240242
},

0 commit comments

Comments
 (0)