@gloablehive/ipad-wechat-plugin 1.0.0 → 1.0.2
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.js +40 -0
- package/dist/openclaw.plugin.json +98 -0
- package/dist/src/channel.js +243 -0
- package/dist/src/client.js +610 -0
- package/index.ts +7 -2
- package/openclaw.plugin.json +11 -7
- package/package.json +3 -2
- package/src/channel.ts +73 -27
- package/src/client.ts +660 -155
- package/test-ipad-real.ts +77 -0
- package/test-ipad.ts +150 -0
- package/tsconfig.json +8 -2
package/src/channel.ts
CHANGED
|
@@ -64,8 +64,9 @@ function getCacheManager(cfg: OpenClawConfig): CacheManager {
|
|
|
64
64
|
|
|
65
65
|
export interface IPadWeChatResolvedAccount {
|
|
66
66
|
accountId: string | null;
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
appKey: string;
|
|
68
|
+
appSecret: string;
|
|
69
|
+
guid: string;
|
|
69
70
|
wechatAccountId: string;
|
|
70
71
|
wechatId: string;
|
|
71
72
|
nickName: string;
|
|
@@ -78,17 +79,19 @@ function resolveAccount(
|
|
|
78
79
|
accountId?: string | null
|
|
79
80
|
): IPadWeChatResolvedAccount {
|
|
80
81
|
const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
|
|
81
|
-
const
|
|
82
|
-
const
|
|
82
|
+
const appKey = section?.appKey;
|
|
83
|
+
const appSecret = section?.appSecret;
|
|
84
|
+
const guid = section?.guid;
|
|
83
85
|
|
|
84
|
-
if (!
|
|
85
|
-
throw new Error("ipad-wechat:
|
|
86
|
+
if (!appKey || !appSecret || !guid) {
|
|
87
|
+
throw new Error("ipad-wechat: appKey, appSecret, and guid are required");
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
return {
|
|
89
91
|
accountId: accountId ?? null,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
appKey,
|
|
93
|
+
appSecret,
|
|
94
|
+
guid,
|
|
92
95
|
wechatAccountId: section?.wechatAccountId || "",
|
|
93
96
|
wechatId: section?.wechatId || "",
|
|
94
97
|
nickName: section?.nickName || "WeChat User",
|
|
@@ -100,25 +103,38 @@ function resolveAccount(
|
|
|
100
103
|
export const ipadWeChatPlugin = createChatChannelPlugin<IPadWeChatResolvedAccount>({
|
|
101
104
|
base: createChannelPluginBase({
|
|
102
105
|
id: "ipad-wechat",
|
|
106
|
+
capabilities: {
|
|
107
|
+
supportedMessageTypes: ["text", "image", "video", "file", "link", "location", "contact"],
|
|
108
|
+
maxAttachmentSize: 25 * 1024 * 1024,
|
|
109
|
+
supportsMarkdown: false,
|
|
110
|
+
supportsHtml: false,
|
|
111
|
+
supportsEmoji: true,
|
|
112
|
+
supportsReactions: false,
|
|
113
|
+
supportsThreads: true,
|
|
114
|
+
supportsEditing: false,
|
|
115
|
+
supportsDeleting: false,
|
|
116
|
+
} as any,
|
|
103
117
|
setup: {
|
|
104
|
-
|
|
105
|
-
|
|
118
|
+
resolveAccountId: (params: any) => {
|
|
119
|
+
return resolveAccount(params.cfg, params.accountId)?.accountId || "";
|
|
120
|
+
},
|
|
121
|
+
inspectAccount(cfg: any, accountId: any) {
|
|
106
122
|
const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
|
|
107
|
-
const
|
|
123
|
+
const hasCredentials = Boolean(section?.appKey && section?.appSecret && section?.guid);
|
|
108
124
|
return {
|
|
109
|
-
enabled:
|
|
110
|
-
configured:
|
|
111
|
-
tokenStatus:
|
|
125
|
+
enabled: hasCredentials,
|
|
126
|
+
configured: hasCredentials,
|
|
127
|
+
tokenStatus: hasCredentials ? "available" : "missing",
|
|
112
128
|
};
|
|
113
129
|
},
|
|
114
|
-
},
|
|
115
|
-
}),
|
|
130
|
+
} as any,
|
|
131
|
+
}) as any,
|
|
116
132
|
|
|
117
133
|
security: {
|
|
118
134
|
dm: {
|
|
119
135
|
channelKey: "ipad-wechat",
|
|
120
|
-
resolvePolicy: (account) => account.dmPolicy,
|
|
121
|
-
resolveAllowFrom: (account) => account.allowFrom,
|
|
136
|
+
resolvePolicy: (account: any) => account.dmPolicy,
|
|
137
|
+
resolveAllowFrom: (account: any) => account.allowFrom,
|
|
122
138
|
defaultPolicy: "allowlist",
|
|
123
139
|
},
|
|
124
140
|
},
|
|
@@ -128,11 +144,17 @@ export const ipadWeChatPlugin = createChatChannelPlugin<IPadWeChatResolvedAccoun
|
|
|
128
144
|
},
|
|
129
145
|
|
|
130
146
|
outbound: {
|
|
147
|
+
channel: "ipad-wechat",
|
|
131
148
|
attachedResults: {
|
|
132
|
-
sendText: async (params) => {
|
|
149
|
+
sendText: async (params: any) => {
|
|
150
|
+
// Get config from params.cfg
|
|
151
|
+
const cfg = params.cfg;
|
|
152
|
+
const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
|
|
153
|
+
|
|
133
154
|
const client = createIPadClient({
|
|
134
|
-
|
|
135
|
-
|
|
155
|
+
appKey: section?.appKey,
|
|
156
|
+
appSecret: section?.appSecret,
|
|
157
|
+
guid: section?.guid,
|
|
136
158
|
});
|
|
137
159
|
|
|
138
160
|
// Check if DM or group
|
|
@@ -153,24 +175,48 @@ export const ipadWeChatPlugin = createChatChannelPlugin<IPadWeChatResolvedAccoun
|
|
|
153
175
|
}
|
|
154
176
|
},
|
|
155
177
|
|
|
156
|
-
sendMedia: async (params) => {
|
|
178
|
+
sendMedia: async (params: any) => {
|
|
179
|
+
const cfg = params.cfg;
|
|
180
|
+
const section = (cfg.channels as Record<string, any>)?.["ipad-wechat"];
|
|
181
|
+
|
|
157
182
|
const client = createIPadClient({
|
|
158
|
-
|
|
159
|
-
|
|
183
|
+
appKey: section?.appKey,
|
|
184
|
+
appSecret: section?.appSecret,
|
|
185
|
+
guid: section?.guid,
|
|
160
186
|
});
|
|
161
187
|
|
|
162
188
|
const isChatroom = params.to?.includes("@chatroom");
|
|
163
189
|
|
|
190
|
+
// Get file path from mediaUrl or mediaReadFile
|
|
191
|
+
let filePath = "";
|
|
192
|
+
if (params.mediaUrl) {
|
|
193
|
+
filePath = params.mediaUrl;
|
|
194
|
+
} else if (params.mediaReadFile) {
|
|
195
|
+
// Read file from local roots
|
|
196
|
+
const roots = params.mediaLocalRoots || ["./"];
|
|
197
|
+
for (const root of roots) {
|
|
198
|
+
try {
|
|
199
|
+
const fullPath = `${root}/${filePath}`;
|
|
200
|
+
const buffer = await params.mediaReadFile(fullPath);
|
|
201
|
+
// In a real implementation, we'd upload the file first
|
|
202
|
+
filePath = fullPath;
|
|
203
|
+
break;
|
|
204
|
+
} catch {
|
|
205
|
+
// Try next root
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
164
210
|
if (isChatroom) {
|
|
165
211
|
const result = await client.sendRoomMedia({
|
|
166
212
|
roomId: params.to,
|
|
167
|
-
filePath:
|
|
213
|
+
filePath: filePath,
|
|
168
214
|
});
|
|
169
215
|
return { messageId: result.messageId };
|
|
170
216
|
} else {
|
|
171
217
|
const result = await client.sendFriendMedia({
|
|
172
218
|
friendWechatId: params.to,
|
|
173
|
-
filePath:
|
|
219
|
+
filePath: filePath,
|
|
174
220
|
});
|
|
175
221
|
return { messageId: result.messageId };
|
|
176
222
|
}
|
|
@@ -189,7 +235,7 @@ export const ipadWeChatPlugin = createChatChannelPlugin<IPadWeChatResolvedAccoun
|
|
|
189
235
|
supportsEditing: false,
|
|
190
236
|
supportsDeleting: false,
|
|
191
237
|
},
|
|
192
|
-
});
|
|
238
|
+
} as any);
|
|
193
239
|
|
|
194
240
|
export async function handleInboundMessage(
|
|
195
241
|
api: any,
|