@gloablehive/ipad-wechat-plugin 1.0.5 → 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;
@@ -81,7 +88,7 @@ export const ipadWeChatPlugin = createChatChannelPlugin({
81
88
  // Config adapter - for runtime account management
82
89
  config: {
83
90
  listAccountIds: (cfg) => {
84
- const section = cfg.channels?.["ipad-wechat"];
91
+ const section = getConfigSection(cfg);
85
92
  if (section?.wechatAccountId) {
86
93
  return [section.wechatAccountId];
87
94
  }
@@ -91,11 +98,11 @@ export const ipadWeChatPlugin = createChatChannelPlugin({
91
98
  return resolveAccount(cfg, accountId);
92
99
  },
93
100
  defaultAccountId: (cfg) => {
94
- const section = cfg.channels?.["ipad-wechat"];
101
+ const section = getConfigSection(cfg);
95
102
  return section?.wechatAccountId || "default";
96
103
  },
97
104
  inspectAccount: (cfg, accountId) => {
98
- const section = cfg.channels?.["ipad-wechat"];
105
+ const section = getConfigSection(cfg);
99
106
  const hasCredentials = Boolean(section?.appKey && section?.appSecret && section?.guid);
100
107
  return {
101
108
  enabled: hasCredentials,
@@ -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.5",
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;
@@ -117,7 +126,7 @@ export const ipadWeChatPlugin = createChatChannelPlugin<IPadWeChatResolvedAccoun
117
126
  // Config adapter - for runtime account management
118
127
  config: {
119
128
  listAccountIds: (cfg: any) => {
120
- const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
129
+ const section = getConfigSection(cfg);
121
130
  if (section?.wechatAccountId) {
122
131
  return [section.wechatAccountId];
123
132
  }
@@ -127,11 +136,11 @@ export const ipadWeChatPlugin = createChatChannelPlugin<IPadWeChatResolvedAccoun
127
136
  return resolveAccount(cfg, accountId);
128
137
  },
129
138
  defaultAccountId: (cfg: any) => {
130
- const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
139
+ const section = getConfigSection(cfg);
131
140
  return section?.wechatAccountId || "default";
132
141
  },
133
142
  inspectAccount: (cfg: any, accountId?: string | null) => {
134
- const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
143
+ const section = getConfigSection(cfg);
135
144
  const hasCredentials = Boolean(section?.appKey && section?.appSecret && section?.guid);
136
145
  return {
137
146
  enabled: hasCredentials,
@@ -171,7 +180,7 @@ export const ipadWeChatPlugin = createChatChannelPlugin<IPadWeChatResolvedAccoun
171
180
  sendText: async (params: any) => {
172
181
  // Get config from params.cfg
173
182
  const cfg = params.cfg;
174
- const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
183
+ const section = getConfigSection(cfg);
175
184
 
176
185
  const client = createIPadClient({
177
186
  appKey: section?.appKey,
@@ -199,7 +208,7 @@ export const ipadWeChatPlugin = createChatChannelPlugin<IPadWeChatResolvedAccoun
199
208
 
200
209
  sendMedia: async (params: any) => {
201
210
  const cfg = params.cfg;
202
- const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
211
+ const section = getConfigSection(cfg);
203
212
 
204
213
  const client = createIPadClient({
205
214
  appKey: section?.appKey,
@@ -293,9 +302,10 @@ export async function handleInboundMessage(
293
302
  if (cfg) {
294
303
  try {
295
304
  const cache = getCacheManager(cfg);
305
+ const section = getConfigSection(cfg);
296
306
  const wechatMessage: WeChatMessage = {
297
307
  messageId: message.messageId,
298
- accountId: (cfg.channels as Record<string, any>)?.["ipad-wechat"]?.accountId || "default",
308
+ accountId: section?.wechatAccountId || "default",
299
309
  conversationType: isChatroom ? "chatroom" : "friend",
300
310
  conversationId,
301
311
  senderId: message.fromUser || "",