@openclaw-china/wecom-app 2026.3.2 → 2026.3.4-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -909,11 +909,31 @@ declare function sendWecom(account: ResolvedWecomAppAccount, target: string, opt
909
909
  /**
910
910
  * Moltbot 插件 API 接口
911
911
  */
912
+ type HttpRouteMatch = "exact" | "prefix";
913
+ type HttpRouteAuth = "gateway" | "plugin";
914
+ type HttpRouteParams = {
915
+ path: string;
916
+ auth: HttpRouteAuth;
917
+ match?: HttpRouteMatch;
918
+ handler: (req: IncomingMessage, res: ServerResponse) => Promise<boolean> | boolean;
919
+ };
920
+ type WecomAppRouteConfig = {
921
+ webhookPath?: string;
922
+ accounts?: Record<string, {
923
+ webhookPath?: string;
924
+ }>;
925
+ };
912
926
  interface MoltbotPluginApi {
913
927
  registerChannel: (opts: {
914
928
  plugin: unknown;
915
929
  }) => void;
916
930
  registerHttpHandler?: (handler: (req: IncomingMessage, res: ServerResponse) => Promise<boolean> | boolean) => void;
931
+ registerHttpRoute?: (params: HttpRouteParams) => void;
932
+ config?: {
933
+ channels?: {
934
+ "wecom-app"?: WecomAppRouteConfig;
935
+ };
936
+ };
917
937
  runtime?: unknown;
918
938
  [key: string]: unknown;
919
939
  }
package/dist/index.js CHANGED
@@ -8599,25 +8599,37 @@ var wecomAppPlugin = {
8599
8599
  * 主动发送文本消息
8600
8600
  */
8601
8601
  sendText: async (params) => {
8602
- const account = resolveWecomAppAccount({ cfg: params.cfg, accountId: params.accountId });
8603
- if (!account.canSendActive) {
8602
+ const parsed = parseDirectTarget(params.to);
8603
+ if (!parsed) {
8604
8604
  return {
8605
8605
  channel: "wecom-app",
8606
8606
  ok: false,
8607
8607
  messageId: "",
8608
- error: new Error("Account not configured for active sending (missing corpId, corpSecret, or agentId)")
8608
+ error: new Error(`Unsupported target for WeCom App: ${params.to}`)
8609
8609
  };
8610
8610
  }
8611
- const parsed = parseDirectTarget(params.to);
8612
- if (!parsed) {
8611
+ const accountId = parsed.accountId ?? params.accountId;
8612
+ const account = resolveWecomAppAccount({ cfg: params.cfg, accountId });
8613
+ if (parsed.accountId && accountId && !params.cfg.channels?.["wecom-app"]?.accounts?.[accountId]) {
8614
+ console.error(`[wecom-app] Account "${accountId}" not found in configuration`);
8613
8615
  return {
8614
8616
  channel: "wecom-app",
8615
8617
  ok: false,
8616
8618
  messageId: "",
8617
- error: new Error(`Unsupported target for WeCom App: ${params.to}`)
8619
+ error: new Error(`Account "${accountId}" not configured`)
8620
+ };
8621
+ }
8622
+ if (!account.canSendActive) {
8623
+ return {
8624
+ channel: "wecom-app",
8625
+ ok: false,
8626
+ messageId: "",
8627
+ error: new Error("Account not configured for active sending (missing corpId, corpSecret, or agentId)")
8618
8628
  };
8619
8629
  }
8620
8630
  const target = { userId: parsed.userId };
8631
+ console.log(`[wecom-app] Account resolved: canSendActive=${account.canSendActive}`);
8632
+ console.log("[wecom-app] Target parsed:", target);
8621
8633
  try {
8622
8634
  const result = await sendWecomAppMessage(account, target, params.text);
8623
8635
  return {
@@ -8640,29 +8652,38 @@ var wecomAppPlugin = {
8640
8652
  * OpenClaw outbound 适配器要求的接口
8641
8653
  */
8642
8654
  sendMedia: async (params) => {
8643
- console.log(`[wecom-app] sendMedia called: to=${params.to}, mediaUrl=${params.mediaUrl}`);
8655
+ const parsed = parseDirectTarget(params.to);
8656
+ if (!parsed) {
8657
+ return {
8658
+ channel: "wecom-app",
8659
+ ok: false,
8660
+ messageId: "",
8661
+ error: new Error(`Unsupported target for WeCom App: ${params.to}`)
8662
+ };
8663
+ }
8664
+ const accountId = parsed.accountId ?? params.accountId;
8644
8665
  const account = resolveWecomAppAccount({
8645
8666
  cfg: params.cfg,
8646
- accountId: params.accountId
8667
+ accountId
8647
8668
  });
8648
- console.log(`[wecom-app] Account resolved: canSendActive=${account.canSendActive}`);
8649
- if (!account.canSendActive) {
8650
- const error = new Error("Account not configured for active sending (missing corpId, corpSecret, or agentId)");
8651
- console.error(`[wecom-app] sendMedia error:`, error.message);
8669
+ if (parsed.accountId && accountId && !params.cfg.channels?.["wecom-app"]?.accounts?.[accountId]) {
8670
+ console.error(`[wecom-app] Account "${accountId}" not found in configuration`);
8652
8671
  return {
8653
8672
  channel: "wecom-app",
8654
8673
  ok: false,
8655
8674
  messageId: "",
8656
- error
8675
+ error: new Error(`Account "${accountId}" not configured`)
8657
8676
  };
8658
8677
  }
8659
- const parsed = parseDirectTarget(params.to);
8660
- if (!parsed) {
8678
+ console.log(`[wecom-app] Account resolved: canSendActive=${account.canSendActive}`);
8679
+ if (!account.canSendActive) {
8680
+ const error = new Error("Account not configured for active sending (missing corpId, corpSecret, or agentId)");
8681
+ console.error(`[wecom-app] sendMedia error:`, error.message);
8661
8682
  return {
8662
8683
  channel: "wecom-app",
8663
8684
  ok: false,
8664
8685
  messageId: "",
8665
- error: new Error(`Unsupported target for WeCom App: ${params.to}`)
8686
+ error
8666
8687
  };
8667
8688
  }
8668
8689
  const target = { userId: parsed.userId };
@@ -8912,6 +8933,20 @@ async function sendWecom(account, target, options) {
8912
8933
  }
8913
8934
 
8914
8935
  // index.ts
8936
+ function normalizeRoutePath(path, fallback) {
8937
+ const trimmed = path?.trim() ?? "";
8938
+ const candidate = trimmed || fallback;
8939
+ return candidate.startsWith("/") ? candidate : `/${candidate}`;
8940
+ }
8941
+ function collectWecomAppRoutePaths(config) {
8942
+ const routes = /* @__PURE__ */ new Set([normalizeRoutePath(config?.webhookPath, "/wecom-app")]);
8943
+ for (const accountConfig of Object.values(config?.accounts ?? {})) {
8944
+ const customPath = accountConfig?.webhookPath?.trim();
8945
+ if (!customPath) continue;
8946
+ routes.add(normalizeRoutePath(customPath, "/wecom-app"));
8947
+ }
8948
+ return [...routes];
8949
+ }
8915
8950
  var plugin = {
8916
8951
  id: "wecom-app",
8917
8952
  name: "WeCom App",
@@ -8928,7 +8963,16 @@ var plugin = {
8928
8963
  setWecomAppRuntime(api.runtime);
8929
8964
  }
8930
8965
  api.registerChannel({ plugin: wecomAppPlugin });
8931
- if (api.registerHttpHandler) {
8966
+ if (api.registerHttpRoute) {
8967
+ for (const path of collectWecomAppRoutePaths(api.config?.channels?.["wecom-app"])) {
8968
+ api.registerHttpRoute({
8969
+ path,
8970
+ auth: "plugin",
8971
+ match: "prefix",
8972
+ handler: handleWecomAppWebhookRequest
8973
+ });
8974
+ }
8975
+ } else if (api.registerHttpHandler) {
8932
8976
  api.registerHttpHandler(handleWecomAppWebhookRequest);
8933
8977
  }
8934
8978
  }