@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
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Script for iPad WeChat Plugin - Real API Test
|
|
3
|
+
* Run: npx tsx test-ipad-real.ts
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { createIPadClient } from './src/client.js';
|
|
7
|
+
|
|
8
|
+
const CONFIG = {
|
|
9
|
+
appKey: 'app84l4hKvqmUphNX1H',
|
|
10
|
+
appSecret: 'CztidspJSiunhw7BVWnKiTgwVFV55nbaPVcBMRa34IT7hRvyxtJLsgMM0C3XMfbD',
|
|
11
|
+
guid: '0e7d1810-2b76-3c2b-8cab-74d94a951af9',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
async function test1_GetLoginAccountInfo() {
|
|
15
|
+
console.log('\n📋 Test 1: Get Login Account Info');
|
|
16
|
+
|
|
17
|
+
const client = createIPadClient(CONFIG);
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const info = await client.getLoginAccountInfo();
|
|
21
|
+
console.log('✅ Account Info:');
|
|
22
|
+
console.log(' WeChat ID:', (info as any).userName?.string);
|
|
23
|
+
console.log(' NickName:', (info as any).nickName?.string);
|
|
24
|
+
console.log(' Mobile:', (info as any).bindMobile?.string);
|
|
25
|
+
console.log(' Signature:', (info as any).signature?.string);
|
|
26
|
+
return info;
|
|
27
|
+
} catch (error: any) {
|
|
28
|
+
console.log('❌ Error:', error.message);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function test2_SyncContacts() {
|
|
34
|
+
console.log('\n📋 Test 2: Sync Contacts');
|
|
35
|
+
|
|
36
|
+
const client = createIPadClient(CONFIG);
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const contacts = await client.syncContacts();
|
|
40
|
+
console.log('✅ Contacts count:', contacts.length);
|
|
41
|
+
if (contacts.length > 0) {
|
|
42
|
+
console.log('Sample contact:', contacts[0]);
|
|
43
|
+
}
|
|
44
|
+
return contacts;
|
|
45
|
+
} catch (error: any) {
|
|
46
|
+
console.log('❌ Error:', error.message);
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function test3_GetRoomList() {
|
|
52
|
+
console.log('\n📋 Test 3: Get Room Info (sample room ID needed)');
|
|
53
|
+
console.log('⚠️ Skipping - requires a valid room ID');
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function test4_SendTextMessage() {
|
|
58
|
+
console.log('\n📋 Test 4: Send Text Message');
|
|
59
|
+
console.log('⚠️ Skipping - requires a valid friend wechat ID');
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function main() {
|
|
64
|
+
console.log('🚀 iPad WeChat Plugin - Real API Test');
|
|
65
|
+
console.log('=======================================');
|
|
66
|
+
console.log('Config:', { appKey: CONFIG.appKey, guid: CONFIG.guid });
|
|
67
|
+
|
|
68
|
+
await test1_GetLoginAccountInfo();
|
|
69
|
+
await test2_SyncContacts();
|
|
70
|
+
await test3_GetRoomList();
|
|
71
|
+
await test4_SendTextMessage();
|
|
72
|
+
|
|
73
|
+
console.log('\n=======================================');
|
|
74
|
+
console.log('✅ Tests completed!');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
main();
|
package/test-ipad.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Script for iPad WeChat Plugin
|
|
3
|
+
* Run: npx tsx test-ipad.ts
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as fs from 'fs/promises';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import {
|
|
9
|
+
createCacheManager,
|
|
10
|
+
CacheManager,
|
|
11
|
+
WeChatAccount,
|
|
12
|
+
WeChatMessage,
|
|
13
|
+
} from "@gloablehive/wechat-cache";
|
|
14
|
+
import { createIPadClient, type WebhookPayload } from './src/client.js';
|
|
15
|
+
|
|
16
|
+
const TEST_CACHE_PATH = '/tmp/wechat-cache-ipad-test';
|
|
17
|
+
|
|
18
|
+
async function cleanup() {
|
|
19
|
+
try {
|
|
20
|
+
await fs.rm(TEST_CACHE_PATH, { recursive: true, force: true });
|
|
21
|
+
} catch {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function test1_CacheSystem() {
|
|
25
|
+
console.log('\n📋 Test 1: iPad WeChat Cache System');
|
|
26
|
+
|
|
27
|
+
const accounts: WeChatAccount[] = [
|
|
28
|
+
{
|
|
29
|
+
accountId: 'ipad-account-001',
|
|
30
|
+
wechatAccountId: 'ipad-wechat-001',
|
|
31
|
+
wechatId: 'wxid_ipad001',
|
|
32
|
+
nickName: 'iPad客服',
|
|
33
|
+
enabled: true,
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
const manager = createCacheManager({
|
|
38
|
+
basePath: TEST_CACHE_PATH,
|
|
39
|
+
accounts,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
await manager.init();
|
|
43
|
+
console.log('✅ Cache manager initialized');
|
|
44
|
+
|
|
45
|
+
// Test message
|
|
46
|
+
const message: WeChatMessage = {
|
|
47
|
+
messageId: 'ipad-msg-001',
|
|
48
|
+
accountId: 'ipad-account-001',
|
|
49
|
+
conversationType: 'friend',
|
|
50
|
+
conversationId: 'wxid_friend001',
|
|
51
|
+
senderId: 'wxid_friend001',
|
|
52
|
+
content: '你好,这是iPad协议测试消息',
|
|
53
|
+
messageType: 1,
|
|
54
|
+
timestamp: Date.now(),
|
|
55
|
+
isSelf: false,
|
|
56
|
+
direction: 'inbound',
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
await manager.onMessage(message);
|
|
60
|
+
console.log('✅ Message cached');
|
|
61
|
+
|
|
62
|
+
// Verify file exists
|
|
63
|
+
const friendPath = path.join(TEST_CACHE_PATH, 'accounts', 'ipad-account-001', 'friends', 'wxid_friend001');
|
|
64
|
+
const files = await fs.readdir(friendPath);
|
|
65
|
+
console.log('✅ Cached files:', files);
|
|
66
|
+
|
|
67
|
+
return manager;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function test2_WebhookPayload() {
|
|
71
|
+
console.log('\n📋 Test 2: Webhook Payload Parsing');
|
|
72
|
+
|
|
73
|
+
// Simulate iPad webhook payload
|
|
74
|
+
const payload: WebhookPayload = {
|
|
75
|
+
event: 'message',
|
|
76
|
+
message: {
|
|
77
|
+
messageId: 'ipad-msg-002',
|
|
78
|
+
fromUser: 'wxid_testfriend',
|
|
79
|
+
toUser: 'wxid_ipad001',
|
|
80
|
+
content: '收到一条测试消息',
|
|
81
|
+
type: 1,
|
|
82
|
+
timestamp: Date.now(),
|
|
83
|
+
isSelf: false,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
console.log('✅ Payload:', JSON.stringify(payload, null, 2));
|
|
88
|
+
console.log('✅ Webhook payload structure valid');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function test3_ClientCreation() {
|
|
92
|
+
console.log('\n📋 Test 3: iPad Client Creation');
|
|
93
|
+
|
|
94
|
+
const client = createIPadClient({
|
|
95
|
+
baseUrl: 'https://api.example.com',
|
|
96
|
+
apiKey: 'test-api-key',
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
console.log('✅ Client created with methods:', Object.keys(client));
|
|
100
|
+
|
|
101
|
+
// Check all methods exist
|
|
102
|
+
const expectedMethods = [
|
|
103
|
+
'sendFriendMessage',
|
|
104
|
+
'sendRoomMessage',
|
|
105
|
+
'sendFriendMedia',
|
|
106
|
+
'sendRoomMedia',
|
|
107
|
+
'syncContacts',
|
|
108
|
+
'getContactDetail',
|
|
109
|
+
'updateFriendRemark',
|
|
110
|
+
'getRoomInfo',
|
|
111
|
+
'getRoomMembers',
|
|
112
|
+
'createRoom',
|
|
113
|
+
'addRoomMember',
|
|
114
|
+
'removeRoomMember',
|
|
115
|
+
'getLoginAccountInfo',
|
|
116
|
+
'getFriendMoments',
|
|
117
|
+
'publishMoment',
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
for (const method of expectedMethods) {
|
|
121
|
+
if (typeof (client as any)[method] === 'function') {
|
|
122
|
+
console.log(` ✅ ${method}`);
|
|
123
|
+
} else {
|
|
124
|
+
console.log(` ❌ ${method} - missing`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function main() {
|
|
130
|
+
console.log('🚀 iPad WeChat Plugin Tests');
|
|
131
|
+
console.log('============================');
|
|
132
|
+
|
|
133
|
+
await cleanup();
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
await test1_CacheSystem();
|
|
137
|
+
await test2_WebhookPayload();
|
|
138
|
+
await test3_ClientCreation();
|
|
139
|
+
|
|
140
|
+
console.log('\n============================');
|
|
141
|
+
console.log('✅ All tests passed!');
|
|
142
|
+
} catch (error) {
|
|
143
|
+
console.error('\n❌ Test failed:', error);
|
|
144
|
+
process.exit(1);
|
|
145
|
+
} finally {
|
|
146
|
+
await cleanup();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
main();
|
package/tsconfig.json
CHANGED
|
@@ -5,12 +5,18 @@
|
|
|
5
5
|
"moduleResolution": "bundler",
|
|
6
6
|
"lib": ["ES2022"],
|
|
7
7
|
"outDir": "./dist",
|
|
8
|
+
"rootDir": ".",
|
|
9
|
+
"declaration": false,
|
|
8
10
|
"strict": false,
|
|
9
11
|
"noImplicitAny": false,
|
|
10
12
|
"esModuleInterop": true,
|
|
11
13
|
"skipLibCheck": true,
|
|
12
|
-
"forceConsistentCasingInFileNames": true
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"allowSyntheticDefaultImports": true,
|
|
17
|
+
"noEmit": false,
|
|
18
|
+
"noEmitOnError": false
|
|
13
19
|
},
|
|
14
20
|
"include": ["*.ts", "src/**/*.ts"],
|
|
15
|
-
"exclude": ["node_modules", "dist"]
|
|
21
|
+
"exclude": ["node_modules", "dist", "test*.ts"]
|
|
16
22
|
}
|