@gloablehive/ipad-wechat-plugin 1.0.5 → 1.0.7

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,
@@ -128,11 +135,19 @@ export const ipadWeChatPlugin = createChatChannelPlugin({
128
135
  },
129
136
  outbound: {
130
137
  channel: "ipad-wechat",
138
+ // Resolve target - for WeChat, just pass through the ID
139
+ resolveTarget: (params) => {
140
+ const target = params.to?.trim();
141
+ if (!target) {
142
+ return { ok: false, error: new Error("No target specified") };
143
+ }
144
+ return { ok: true, to: target };
145
+ },
131
146
  attachedResults: {
132
147
  sendText: async (params) => {
133
148
  // Get config from params.cfg
134
149
  const cfg = params.cfg;
135
- const section = cfg.channels?.["ipad-wechat"];
150
+ const section = getConfigSection(cfg);
136
151
  const client = createIPadClient({
137
152
  appKey: section?.appKey,
138
153
  appSecret: section?.appSecret,
@@ -157,7 +172,7 @@ export const ipadWeChatPlugin = createChatChannelPlugin({
157
172
  },
158
173
  sendMedia: async (params) => {
159
174
  const cfg = params.cfg;
160
- const section = cfg.channels?.["ipad-wechat"];
175
+ const section = getConfigSection(cfg);
161
176
  const client = createIPadClient({
162
177
  appKey: section?.appKey,
163
178
  appSecret: section?.appSecret,
@@ -241,9 +256,10 @@ export async function handleInboundMessage(api, payload, cfg) {
241
256
  if (cfg) {
242
257
  try {
243
258
  const cache = getCacheManager(cfg);
259
+ const section = getConfigSection(cfg);
244
260
  const wechatMessage = {
245
261
  messageId: message.messageId,
246
- accountId: cfg.channels?.["ipad-wechat"]?.accountId || "default",
262
+ accountId: section?.wechatAccountId || "default",
247
263
  conversationType: isChatroom ? "chatroom" : "friend",
248
264
  conversationId,
249
265
  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.7",
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,
@@ -167,11 +176,19 @@ export const ipadWeChatPlugin = createChatChannelPlugin<IPadWeChatResolvedAccoun
167
176
 
168
177
  outbound: {
169
178
  channel: "ipad-wechat",
179
+ // Resolve target - for WeChat, just pass through the ID
180
+ resolveTarget: (params: any) => {
181
+ const target = params.to?.trim();
182
+ if (!target) {
183
+ return { ok: false, error: new Error("No target specified") };
184
+ }
185
+ return { ok: true, to: target };
186
+ },
170
187
  attachedResults: {
171
188
  sendText: async (params: any) => {
172
189
  // Get config from params.cfg
173
190
  const cfg = params.cfg;
174
- const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
191
+ const section = getConfigSection(cfg);
175
192
 
176
193
  const client = createIPadClient({
177
194
  appKey: section?.appKey,
@@ -199,7 +216,7 @@ export const ipadWeChatPlugin = createChatChannelPlugin<IPadWeChatResolvedAccoun
199
216
 
200
217
  sendMedia: async (params: any) => {
201
218
  const cfg = params.cfg;
202
- const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
219
+ const section = getConfigSection(cfg);
203
220
 
204
221
  const client = createIPadClient({
205
222
  appKey: section?.appKey,
@@ -293,9 +310,10 @@ export async function handleInboundMessage(
293
310
  if (cfg) {
294
311
  try {
295
312
  const cache = getCacheManager(cfg);
313
+ const section = getConfigSection(cfg);
296
314
  const wechatMessage: WeChatMessage = {
297
315
  messageId: message.messageId,
298
- accountId: (cfg.channels as Record<string, any>)?.["ipad-wechat"]?.accountId || "default",
316
+ accountId: section?.wechatAccountId || "default",
299
317
  conversationType: isChatroom ? "chatroom" : "friend",
300
318
  conversationId,
301
319
  senderId: message.fromUser || "",