mirror of https://github.com/openclaw/openclaw.git
perf: split whatsapp targets facade
This commit is contained in:
parent
4528f8779e
commit
6d6060d3ec
|
|
@ -0,0 +1,5 @@
|
|||
export {
|
||||
isWhatsAppGroupJid,
|
||||
isWhatsAppUserTarget,
|
||||
normalizeWhatsAppTarget,
|
||||
} from "./src/normalize-target.js";
|
||||
|
|
@ -876,6 +876,36 @@ export const GENERATED_PLUGIN_SDK_FACADES = [
|
|||
"ZAI_GLOBAL_BASE_URL",
|
||||
],
|
||||
},
|
||||
{
|
||||
subpath: "whatsapp-targets",
|
||||
source: pluginSource("whatsapp", "targets.js"),
|
||||
exports: ["isWhatsAppGroupJid", "isWhatsAppUserTarget", "normalizeWhatsAppTarget"],
|
||||
},
|
||||
{
|
||||
subpath: "whatsapp-surface",
|
||||
source: pluginSource("whatsapp", "api.js"),
|
||||
exportSources: {
|
||||
DEFAULT_WEB_MEDIA_BYTES: pluginSource("whatsapp", "constants.js"),
|
||||
},
|
||||
exports: [
|
||||
"DEFAULT_WEB_MEDIA_BYTES",
|
||||
"hasAnyWhatsAppAuth",
|
||||
"listEnabledWhatsAppAccounts",
|
||||
"listWhatsAppDirectoryGroupsFromConfig",
|
||||
"listWhatsAppDirectoryPeersFromConfig",
|
||||
"resolveWhatsAppAccount",
|
||||
"resolveWhatsAppGroupRequireMention",
|
||||
"resolveWhatsAppGroupToolPolicy",
|
||||
"resolveWhatsAppOutboundTarget",
|
||||
"whatsappAccessControlTesting",
|
||||
],
|
||||
typeExports: [
|
||||
"WebChannelStatus",
|
||||
"WebInboundMessage",
|
||||
"WebListenerCloseReason",
|
||||
"WebMonitorTuning",
|
||||
],
|
||||
},
|
||||
{
|
||||
subpath: "zalo-setup",
|
||||
source: pluginSource("zalo", "api.js"),
|
||||
|
|
|
|||
|
|
@ -557,6 +557,32 @@ export interface PluginSdkFacadeTypeMap {
|
|||
};
|
||||
types: {};
|
||||
};
|
||||
"whatsapp-targets": {
|
||||
module: typeof import("@openclaw/whatsapp/targets.js");
|
||||
sourceModules: {
|
||||
source1: {
|
||||
module: typeof import("@openclaw/whatsapp/targets.js");
|
||||
};
|
||||
};
|
||||
types: {};
|
||||
};
|
||||
"whatsapp-surface": {
|
||||
module: typeof import("@openclaw/whatsapp/api.js");
|
||||
sourceModules: {
|
||||
source1: {
|
||||
module: typeof import("@openclaw/whatsapp/api.js");
|
||||
};
|
||||
source2: {
|
||||
module: typeof import("@openclaw/whatsapp/constants.js");
|
||||
};
|
||||
};
|
||||
types: {
|
||||
WebChannelStatus: import("@openclaw/whatsapp/api.js").WebChannelStatus;
|
||||
WebInboundMessage: import("@openclaw/whatsapp/api.js").WebInboundMessage;
|
||||
WebListenerCloseReason: import("@openclaw/whatsapp/api.js").WebListenerCloseReason;
|
||||
WebMonitorTuning: import("@openclaw/whatsapp/api.js").WebMonitorTuning;
|
||||
};
|
||||
};
|
||||
"zalo-setup": {
|
||||
module: typeof import("@openclaw/zalo/api.js");
|
||||
sourceModules: {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
isWhatsAppGroupJid,
|
||||
isWhatsAppUserTarget,
|
||||
normalizeWhatsAppTarget,
|
||||
} from "./whatsapp-targets.js";
|
||||
|
||||
describe("plugin-sdk whatsapp-targets", () => {
|
||||
it("normalizes user targets through the public facade", () => {
|
||||
expect(normalizeWhatsAppTarget("1555123@s.whatsapp.net")).toBe("+1555123");
|
||||
expect(normalizeWhatsAppTarget("whatsapp:+1555123")).toBe("+1555123");
|
||||
});
|
||||
|
||||
it("preserves valid group JIDs through the public facade", () => {
|
||||
expect(isWhatsAppGroupJid("120363401234567890@g.us")).toBe(true);
|
||||
expect(normalizeWhatsAppTarget("120363401234567890@g.us")).toBe("120363401234567890@g.us");
|
||||
});
|
||||
|
||||
it("detects WhatsApp user JIDs through the public facade", () => {
|
||||
expect(isWhatsAppUserTarget("41796666864:0@s.whatsapp.net")).toBe(true);
|
||||
expect(isWhatsAppUserTarget("123456789@lid")).toBe(true);
|
||||
expect(isWhatsAppUserTarget("123456789-987654321@g.us")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
// Generated by scripts/generate-plugin-sdk-facades.mjs. Do not edit manually.
|
||||
import type { PluginSdkFacadeTypeMap } from "../generated/plugin-sdk-facade-type-map.generated.js";
|
||||
type FacadeEntry = PluginSdkFacadeTypeMap["whatsapp-targets"];
|
||||
type FacadeModule = FacadeEntry["module"];
|
||||
import { loadBundledPluginPublicSurfaceModuleSync } from "./facade-runtime.js";
|
||||
|
||||
function loadFacadeModule(): FacadeModule {
|
||||
return loadBundledPluginPublicSurfaceModuleSync<FacadeModule>({
|
||||
dirName: "whatsapp",
|
||||
artifactBasename: "targets.js",
|
||||
});
|
||||
}
|
||||
export const isWhatsAppGroupJid: FacadeModule["isWhatsAppGroupJid"] = ((...args) =>
|
||||
loadFacadeModule()["isWhatsAppGroupJid"](...args)) as FacadeModule["isWhatsAppGroupJid"];
|
||||
export const isWhatsAppUserTarget: FacadeModule["isWhatsAppUserTarget"] = ((...args) =>
|
||||
loadFacadeModule()["isWhatsAppUserTarget"](...args)) as FacadeModule["isWhatsAppUserTarget"];
|
||||
export const normalizeWhatsAppTarget: FacadeModule["normalizeWhatsAppTarget"] = ((...args) =>
|
||||
loadFacadeModule()["normalizeWhatsAppTarget"](
|
||||
...args,
|
||||
)) as FacadeModule["normalizeWhatsAppTarget"];
|
||||
Loading…
Reference in New Issue