@gloablehive/ipad-wechat-plugin 1.0.4 → 1.0.6

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.
@@ -19,13 +19,20 @@ import { createIPadClient } from "./client.js";
19
19
  import { createCacheManager, } from "@gloablehive/wechat-cache";
20
20
  // Cache manager instance (lazy initialized)
21
21
  let cacheManager = null;
22
+ /**
23
+ * Get config section from either channels or plugins.entries
24
+ */
25
+ function getConfigSection(cfg) {
26
+ return cfg?.channels?.["ipad-wechat"]
27
+ || cfg?.plugins?.entries?.["ipad-wechat"]?.config;
28
+ }
22
29
  /**
23
30
  * Get or create cache manager
24
31
  */
25
32
  function getCacheManager(cfg) {
26
33
  if (cacheManager)
27
34
  return cacheManager;
28
- const section = cfg.channels?.["ipad-wechat"];
35
+ const section = getConfigSection(cfg);
29
36
  const accounts = (section?.accounts || []);
30
37
  // If no accounts configured, create default from main config
31
38
  if (accounts.length === 0 && section?.wechatAccountId) {
@@ -45,7 +52,7 @@ function getCacheManager(cfg) {
45
52
  return cacheManager;
46
53
  }
47
54
  function resolveAccount(cfg, accountId) {
48
- const section = cfg.channels?.["ipad-wechat"];
55
+ const section = getConfigSection(cfg);
49
56
  const appKey = section?.appKey;
50
57
  const appSecret = section?.appSecret;
51
58
  const guid = section?.guid;
@@ -78,6 +85,32 @@ export const ipadWeChatPlugin = createChatChannelPlugin({
78
85
  supportsEditing: false,
79
86
  supportsDeleting: false,
80
87
  },
88
+ // Config adapter - for runtime account management
89
+ config: {
90
+ listAccountIds: (cfg) => {
91
+ const section = getConfigSection(cfg);
92
+ if (section?.wechatAccountId) {
93
+ return [section.wechatAccountId];
94
+ }
95
+ return ["default"];
96
+ },
97
+ resolveAccount: (cfg, accountId) => {
98
+ return resolveAccount(cfg, accountId);
99
+ },
100
+ defaultAccountId: (cfg) => {
101
+ const section = getConfigSection(cfg);
102
+ return section?.wechatAccountId || "default";
103
+ },
104
+ inspectAccount: (cfg, accountId) => {
105
+ const section = getConfigSection(cfg);
106
+ const hasCredentials = Boolean(section?.appKey && section?.appSecret && section?.guid);
107
+ return {
108
+ enabled: hasCredentials,
109
+ configured: hasCredentials,
110
+ tokenStatus: hasCredentials ? "available" : "missing",
111
+ };
112
+ },
113
+ },
81
114
  // Setup adapter - for initial configuration
82
115
  setup: {
83
116
  resolveAccountId: (params) => {
@@ -89,32 +122,6 @@ export const ipadWeChatPlugin = createChatChannelPlugin({
89
122
  },
90
123
  },
91
124
  }),
92
- // Config adapter - for runtime account management
93
- config: {
94
- listAccountIds: (cfg) => {
95
- const section = cfg.channels?.["ipad-wechat"];
96
- if (section?.wechatAccountId) {
97
- return [section.wechatAccountId];
98
- }
99
- return ["default"];
100
- },
101
- resolveAccount: (cfg, accountId) => {
102
- return resolveAccount(cfg, accountId);
103
- },
104
- defaultAccountId: (cfg) => {
105
- const section = cfg.channels?.["ipad-wechat"];
106
- return section?.wechatAccountId || "default";
107
- },
108
- inspectAccount: (cfg, accountId) => {
109
- const section = cfg.channels?.["ipad-wechat"];
110
- const hasCredentials = Boolean(section?.appKey && section?.appSecret && section?.guid);
111
- return {
112
- enabled: hasCredentials,
113
- configured: hasCredentials,
114
- tokenStatus: hasCredentials ? "available" : "missing",
115
- };
116
- },
117
- },
118
125
  security: {
119
126
  dm: {
120
127
  channelKey: "ipad-wechat",
@@ -132,7 +139,7 @@ export const ipadWeChatPlugin = createChatChannelPlugin({
132
139
  sendText: async (params) => {
133
140
  // Get config from params.cfg
134
141
  const cfg = params.cfg;
135
- const section = cfg.channels?.["ipad-wechat"];
142
+ const section = getConfigSection(cfg);
136
143
  const client = createIPadClient({
137
144
  appKey: section?.appKey,
138
145
  appSecret: section?.appSecret,
@@ -157,7 +164,7 @@ export const ipadWeChatPlugin = createChatChannelPlugin({
157
164
  },
158
165
  sendMedia: async (params) => {
159
166
  const cfg = params.cfg;
160
- const section = cfg.channels?.["ipad-wechat"];
167
+ const section = getConfigSection(cfg);
161
168
  const client = createIPadClient({
162
169
  appKey: section?.appKey,
163
170
  appSecret: section?.appSecret,
@@ -241,9 +248,10 @@ export async function handleInboundMessage(api, payload, cfg) {
241
248
  if (cfg) {
242
249
  try {
243
250
  const cache = getCacheManager(cfg);
251
+ const section = getConfigSection(cfg);
244
252
  const wechatMessage = {
245
253
  messageId: message.messageId,
246
- accountId: cfg.channels?.["ipad-wechat"]?.accountId || "default",
254
+ accountId: section?.wechatAccountId || "default",
247
255
  conversationType: isChatroom ? "chatroom" : "friend",
248
256
  conversationId,
249
257
  senderId: message.fromUser || "",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gloablehive/ipad-wechat-plugin",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "description": "OpenClaw channel plugin for iPad WeChat protocol - enables sending/receiving WeChat messages through iPad protocol",
6
6
  "main": "index.ts",
package/src/channel.ts CHANGED
@@ -32,13 +32,21 @@ import {
32
32
  // Cache manager instance (lazy initialized)
33
33
  let cacheManager: CacheManager | null = null;
34
34
 
35
+ /**
36
+ * Get config section from either channels or plugins.entries
37
+ */
38
+ function getConfigSection(cfg: any): any {
39
+ return cfg?.channels?.["ipad-wechat"]
40
+ || cfg?.plugins?.entries?.["ipad-wechat"]?.config;
41
+ }
42
+
35
43
  /**
36
44
  * Get or create cache manager
37
45
  */
38
46
  function getCacheManager(cfg: OpenClawConfig): CacheManager {
39
47
  if (cacheManager) return cacheManager;
40
48
 
41
- const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
49
+ const section = getConfigSection(cfg);
42
50
  const accounts = (section?.accounts || []) as WeChatAccount[];
43
51
 
44
52
  // If no accounts configured, create default from main config
@@ -78,7 +86,8 @@ function resolveAccount(
78
86
  cfg: OpenClawConfig,
79
87
  accountId?: string | null
80
88
  ): IPadWeChatResolvedAccount {
81
- const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
89
+ const section = getConfigSection(cfg);
90
+
82
91
  const appKey = section?.appKey;
83
92
  const appSecret = section?.appSecret;
84
93
  const guid = section?.guid;
@@ -114,6 +123,32 @@ export const ipadWeChatPlugin = createChatChannelPlugin<IPadWeChatResolvedAccoun
114
123
  supportsEditing: false,
115
124
  supportsDeleting: false,
116
125
  } as any,
126
+ // Config adapter - for runtime account management
127
+ config: {
128
+ listAccountIds: (cfg: any) => {
129
+ const section = getConfigSection(cfg);
130
+ if (section?.wechatAccountId) {
131
+ return [section.wechatAccountId];
132
+ }
133
+ return ["default"];
134
+ },
135
+ resolveAccount: (cfg: any, accountId?: string | null) => {
136
+ return resolveAccount(cfg, accountId);
137
+ },
138
+ defaultAccountId: (cfg: any) => {
139
+ const section = getConfigSection(cfg);
140
+ return section?.wechatAccountId || "default";
141
+ },
142
+ inspectAccount: (cfg: any, accountId?: string | null) => {
143
+ const section = getConfigSection(cfg);
144
+ const hasCredentials = Boolean(section?.appKey && section?.appSecret && section?.guid);
145
+ return {
146
+ enabled: hasCredentials,
147
+ configured: hasCredentials,
148
+ tokenStatus: hasCredentials ? "available" : "missing",
149
+ };
150
+ },
151
+ } as any,
117
152
  // Setup adapter - for initial configuration
118
153
  setup: {
119
154
  resolveAccountId: (params: any) => {
@@ -126,33 +161,6 @@ export const ipadWeChatPlugin = createChatChannelPlugin<IPadWeChatResolvedAccoun
126
161
  },
127
162
  }) as any,
128
163
 
129
- // Config adapter - for runtime account management
130
- config: {
131
- listAccountIds: (cfg: any) => {
132
- const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
133
- if (section?.wechatAccountId) {
134
- return [section.wechatAccountId];
135
- }
136
- return ["default"];
137
- },
138
- resolveAccount: (cfg: any, accountId?: string | null) => {
139
- return resolveAccount(cfg, accountId);
140
- },
141
- defaultAccountId: (cfg: any) => {
142
- const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
143
- return section?.wechatAccountId || "default";
144
- },
145
- inspectAccount: (cfg: any, accountId?: string | null) => {
146
- const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
147
- const hasCredentials = Boolean(section?.appKey && section?.appSecret && section?.guid);
148
- return {
149
- enabled: hasCredentials,
150
- configured: hasCredentials,
151
- tokenStatus: hasCredentials ? "available" : "missing",
152
- };
153
- },
154
- } as any,
155
-
156
164
  security: {
157
165
  dm: {
158
166
  channelKey: "ipad-wechat",
@@ -172,7 +180,7 @@ export const ipadWeChatPlugin = createChatChannelPlugin<IPadWeChatResolvedAccoun
172
180
  sendText: async (params: any) => {
173
181
  // Get config from params.cfg
174
182
  const cfg = params.cfg;
175
- const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
183
+ const section = getConfigSection(cfg);
176
184
 
177
185
  const client = createIPadClient({
178
186
  appKey: section?.appKey,
@@ -200,7 +208,7 @@ export const ipadWeChatPlugin = createChatChannelPlugin<IPadWeChatResolvedAccoun
200
208
 
201
209
  sendMedia: async (params: any) => {
202
210
  const cfg = params.cfg;
203
- const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
211
+ const section = getConfigSection(cfg);
204
212
 
205
213
  const client = createIPadClient({
206
214
  appKey: section?.appKey,
@@ -294,9 +302,10 @@ export async function handleInboundMessage(
294
302
  if (cfg) {
295
303
  try {
296
304
  const cache = getCacheManager(cfg);
305
+ const section = getConfigSection(cfg);
297
306
  const wechatMessage: WeChatMessage = {
298
307
  messageId: message.messageId,
299
- accountId: (cfg.channels as Record<string, any>)?.["ipad-wechat"]?.accountId || "default",
308
+ accountId: section?.wechatAccountId || "default",
300
309
  conversationType: isChatroom ? "chatroom" : "friend",
301
310
  conversationId,
302
311
  senderId: message.fromUser || "",