@open-wa/schema 5.0.0 → 5.1.0
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/generated/index.cjs +8 -2
- package/dist/generated/index.cjs.map +1 -1
- package/dist/generated/index.d.cts +715 -1
- package/dist/generated/index.d.cts.map +1 -1
- package/dist/generated/index.d.mts +715 -1
- package/dist/generated/index.d.mts.map +1 -1
- package/dist/generated/index.mjs +8 -2
- package/dist/generated/index.mjs.map +1 -1
- package/dist/{index-ChYFQM1K.d.cts → index-DTztyYhw.d.cts} +893 -3
- package/dist/index-DTztyYhw.d.cts.map +1 -0
- package/dist/{index-BHcd0h7x.d.mts → index-nVKR0RmZ.d.mts} +893 -3
- package/dist/index-nVKR0RmZ.d.mts.map +1 -0
- package/dist/index.cjs +51 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +24 -2
- package/dist/index.mjs.map +1 -1
- package/dist/methods/index.cjs +5 -1
- package/dist/methods/index.d.cts +2 -2
- package/dist/methods/index.d.mts +2 -2
- package/dist/methods/index.mjs +2 -2
- package/dist/{methods-CZqeUhKy.mjs → methods-BSv5O3bS.mjs} +317 -2
- package/dist/methods-BSv5O3bS.mjs.map +1 -0
- package/dist/{methods-Dizm7Fn9.cjs → methods-DO0JONvB.cjs} +472 -1
- package/dist/methods-DO0JONvB.cjs.map +1 -0
- package/package.json +4 -3
- package/src/__tests__/generators.contract.test.ts +181 -0
- package/src/__tests__/registry.contract.test.ts +81 -0
- package/src/client-config.ts +30 -0
- package/src/codecs.test.ts +41 -0
- package/src/codecs.ts +191 -0
- package/src/common-types.ts +280 -0
- package/src/config.ts +47 -0
- package/src/enums.ts +63 -0
- package/src/events/groups.ts +33 -0
- package/src/events/index.ts +4 -0
- package/src/events/messaging.ts +86 -0
- package/src/events/registry.ts +124 -0
- package/src/events/state.ts +59 -0
- package/src/generated/AliasMap.ts +216 -0
- package/src/generated/BaseClient.ts +878 -0
- package/src/generated/BaseNamespacedClient.ts +214 -0
- package/src/generated/index.ts +5 -0
- package/src/generated/openapi.json +8949 -0
- package/src/generated/types.ts +383 -0
- package/src/http-manifest.ts +97 -0
- package/src/implementor.test.ts +88 -0
- package/src/implementor.ts +75 -0
- package/src/index.ts +44 -0
- package/src/interactive.ts +151 -0
- package/src/methods/business.ts +51 -0
- package/src/methods/chats.ts +263 -0
- package/src/methods/communities.ts +119 -0
- package/src/methods/contacts.ts +158 -0
- package/src/methods/groups.ts +376 -0
- package/src/methods/index.ts +34 -0
- package/src/methods/interactive.ts +21 -0
- package/src/methods/labels.ts +86 -0
- package/src/methods/media.ts +36 -0
- package/src/methods/messaging.ts +828 -0
- package/src/methods/session.ts +261 -0
- package/src/methods/status.ts +120 -0
- package/src/parameters.ts +237 -0
- package/src/registry.test.ts +30 -0
- package/src/registry.ts +601 -0
- package/dist/index-BHcd0h7x.d.mts.map +0 -1
- package/dist/index-ChYFQM1K.d.cts.map +0 -1
- package/dist/methods-CZqeUhKy.mjs.map +0 -1
- package/dist/methods-Dizm7Fn9.cjs.map +0 -1
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defineMethodV2 } from '../registry';
|
|
3
|
+
import { chatIdParam, imageDataParam, nameParam, statusTextParam, userAgentParam } from '../parameters';
|
|
4
|
+
|
|
5
|
+
export const getMe = defineMethodV2('getMe', {
|
|
6
|
+
meta: {
|
|
7
|
+
description: 'Get host account info',
|
|
8
|
+
action: 'read',
|
|
9
|
+
namespace: 'session',
|
|
10
|
+
license: 'none',
|
|
11
|
+
functionality: 'both',
|
|
12
|
+
httpMethod: 'GET',
|
|
13
|
+
},
|
|
14
|
+
input: z.object({}),
|
|
15
|
+
parameterOrder: [],
|
|
16
|
+
output: z.any(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const getHostNumber = defineMethodV2('getHostNumber', {
|
|
20
|
+
meta: {
|
|
21
|
+
description: 'Get host phone number',
|
|
22
|
+
action: 'read',
|
|
23
|
+
namespace: 'session',
|
|
24
|
+
license: 'none',
|
|
25
|
+
functionality: 'both',
|
|
26
|
+
httpMethod: 'GET',
|
|
27
|
+
},
|
|
28
|
+
input: z.object({}),
|
|
29
|
+
parameterOrder: [],
|
|
30
|
+
output: z.string(),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const getConnectionState = defineMethodV2('getConnectionState', {
|
|
34
|
+
meta: {
|
|
35
|
+
description: 'Get connection state',
|
|
36
|
+
action: 'read',
|
|
37
|
+
namespace: 'session',
|
|
38
|
+
license: 'none',
|
|
39
|
+
functionality: 'both',
|
|
40
|
+
httpMethod: 'GET',
|
|
41
|
+
},
|
|
42
|
+
input: z.object({}),
|
|
43
|
+
parameterOrder: [],
|
|
44
|
+
output: z.any(),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const getWAVersion = defineMethodV2('getWAVersion', {
|
|
48
|
+
meta: {
|
|
49
|
+
description: 'Get WhatsApp Web version',
|
|
50
|
+
action: 'read',
|
|
51
|
+
namespace: 'session',
|
|
52
|
+
license: 'none',
|
|
53
|
+
functionality: 'both',
|
|
54
|
+
httpMethod: 'GET',
|
|
55
|
+
aliases: {
|
|
56
|
+
explicit: ['getWhatsAppVersion'],
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
input: z.object({}),
|
|
60
|
+
parameterOrder: [],
|
|
61
|
+
output: z.string(),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export const getBatteryLevel = defineMethodV2('getBatteryLevel', {
|
|
65
|
+
meta: {
|
|
66
|
+
description: 'Get phone battery level',
|
|
67
|
+
action: 'read',
|
|
68
|
+
namespace: 'session',
|
|
69
|
+
license: 'none',
|
|
70
|
+
functionality: 'both',
|
|
71
|
+
httpMethod: 'GET',
|
|
72
|
+
},
|
|
73
|
+
input: z.object({}),
|
|
74
|
+
parameterOrder: [],
|
|
75
|
+
output: z.number(),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export const isPlugged = defineMethodV2('isPlugged', {
|
|
79
|
+
meta: {
|
|
80
|
+
description: 'Check if phone is charging',
|
|
81
|
+
action: 'read',
|
|
82
|
+
namespace: 'session',
|
|
83
|
+
license: 'none',
|
|
84
|
+
functionality: 'both',
|
|
85
|
+
httpMethod: 'GET',
|
|
86
|
+
aliases: {
|
|
87
|
+
deprecated: ['getIsPlugged'],
|
|
88
|
+
},
|
|
89
|
+
wapiOverride: 'getIsPlugged',
|
|
90
|
+
},
|
|
91
|
+
input: z.object({}),
|
|
92
|
+
parameterOrder: [],
|
|
93
|
+
output: z.boolean(),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
export const getFeatures = defineMethodV2('getFeatures', {
|
|
97
|
+
meta: {
|
|
98
|
+
description: 'Get enabled features',
|
|
99
|
+
action: 'read',
|
|
100
|
+
namespace: 'session',
|
|
101
|
+
license: 'none',
|
|
102
|
+
functionality: 'both',
|
|
103
|
+
httpMethod: 'GET',
|
|
104
|
+
},
|
|
105
|
+
input: z.object({}),
|
|
106
|
+
parameterOrder: [],
|
|
107
|
+
output: z.any(),
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
export const getLicenseType = defineMethodV2('getLicenseType', {
|
|
111
|
+
meta: {
|
|
112
|
+
description: 'Get license type',
|
|
113
|
+
action: 'read',
|
|
114
|
+
namespace: 'session',
|
|
115
|
+
license: 'none',
|
|
116
|
+
functionality: 'both',
|
|
117
|
+
httpMethod: 'GET',
|
|
118
|
+
},
|
|
119
|
+
input: z.object({}),
|
|
120
|
+
parameterOrder: [],
|
|
121
|
+
output: z.union([z.any(), z.boolean()]),
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
export const getUserAgent = defineMethodV2('getUserAgent', {
|
|
125
|
+
meta: {
|
|
126
|
+
description: 'Get user agent',
|
|
127
|
+
action: 'read',
|
|
128
|
+
namespace: 'session',
|
|
129
|
+
license: 'none',
|
|
130
|
+
functionality: 'both',
|
|
131
|
+
httpMethod: 'GET',
|
|
132
|
+
aliases: {
|
|
133
|
+
deprecated: ['getGeneratedUserAgent'],
|
|
134
|
+
},
|
|
135
|
+
wapiOverride: 'getGeneratedUserAgent',
|
|
136
|
+
},
|
|
137
|
+
input: z.object({ userAgent: userAgentParam }),
|
|
138
|
+
parameterOrder: ['userAgent'],
|
|
139
|
+
output: z.string(),
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
export const getProcessStats = defineMethodV2('getProcessStats', {
|
|
143
|
+
meta: {
|
|
144
|
+
description: 'Get process statistics',
|
|
145
|
+
action: 'read',
|
|
146
|
+
namespace: 'session',
|
|
147
|
+
license: 'none',
|
|
148
|
+
functionality: 'both',
|
|
149
|
+
httpMethod: 'GET',
|
|
150
|
+
},
|
|
151
|
+
input: z.object({}),
|
|
152
|
+
parameterOrder: [],
|
|
153
|
+
output: z.any(),
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
export const getLoadedMessageCount = defineMethodV2('getLoadedMessageCount', {
|
|
157
|
+
meta: {
|
|
158
|
+
description: 'Get loaded message count',
|
|
159
|
+
action: 'read',
|
|
160
|
+
namespace: 'session',
|
|
161
|
+
license: 'none',
|
|
162
|
+
functionality: 'both',
|
|
163
|
+
httpMethod: 'GET',
|
|
164
|
+
aliases: {
|
|
165
|
+
deprecated: ['getAmountOfLoadedMessages'],
|
|
166
|
+
},
|
|
167
|
+
wapiOverride: 'getAmountOfLoadedMessages',
|
|
168
|
+
},
|
|
169
|
+
input: z.object({}),
|
|
170
|
+
parameterOrder: [],
|
|
171
|
+
output: z.number(),
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
export const getSnapshot = defineMethodV2('getSnapshot', {
|
|
175
|
+
meta: {
|
|
176
|
+
description: 'Take screenshot',
|
|
177
|
+
action: 'read',
|
|
178
|
+
namespace: 'session',
|
|
179
|
+
license: 'none',
|
|
180
|
+
functionality: 'both',
|
|
181
|
+
httpMethod: 'GET',
|
|
182
|
+
aliases: {
|
|
183
|
+
explicit: ['takeScreenshot'],
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
input: z.object({
|
|
187
|
+
chatId: chatIdParam.optional(),
|
|
188
|
+
width: z.number().optional(),
|
|
189
|
+
height: z.number().optional(),
|
|
190
|
+
}),
|
|
191
|
+
parameterOrder: ['chatId', 'width', 'height'],
|
|
192
|
+
output: z.string(),
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
export const healthCheck = defineMethodV2('healthCheck', {
|
|
196
|
+
meta: {
|
|
197
|
+
description: 'Health check',
|
|
198
|
+
action: 'read',
|
|
199
|
+
namespace: 'session',
|
|
200
|
+
license: 'none',
|
|
201
|
+
functionality: 'both',
|
|
202
|
+
httpMethod: 'GET',
|
|
203
|
+
},
|
|
204
|
+
input: z.object({}),
|
|
205
|
+
parameterOrder: [],
|
|
206
|
+
output: z.any(),
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
export const setMyName = defineMethodV2('setMyName', {
|
|
210
|
+
meta: {
|
|
211
|
+
description: 'Set host name',
|
|
212
|
+
action: 'update',
|
|
213
|
+
namespace: 'session',
|
|
214
|
+
license: 'none',
|
|
215
|
+
functionality: 'personal-only',
|
|
216
|
+
httpMethod: 'PUT',
|
|
217
|
+
aliases: {
|
|
218
|
+
explicit: ['setDisplayName'],
|
|
219
|
+
namespacedName: 'setName',
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
input: z.object({ name: nameParam }),
|
|
223
|
+
parameterOrder: ['name'],
|
|
224
|
+
output: z.boolean(),
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
export const setMyStatus = defineMethodV2('setMyStatus', {
|
|
228
|
+
meta: {
|
|
229
|
+
description: 'Set host status',
|
|
230
|
+
action: 'update',
|
|
231
|
+
namespace: 'session',
|
|
232
|
+
license: 'none',
|
|
233
|
+
functionality: 'both',
|
|
234
|
+
httpMethod: 'PUT',
|
|
235
|
+
aliases: {
|
|
236
|
+
explicit: ['setStatusText'],
|
|
237
|
+
namespacedName: 'setStatus',
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
input: z.object({ statusText: statusTextParam }),
|
|
241
|
+
parameterOrder: ['statusText'],
|
|
242
|
+
output: z.boolean(),
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
export const setProfilePicture = defineMethodV2('setProfilePicture', {
|
|
246
|
+
meta: {
|
|
247
|
+
description: 'Set profile picture',
|
|
248
|
+
action: 'update',
|
|
249
|
+
namespace: 'session',
|
|
250
|
+
license: 'insiders',
|
|
251
|
+
functionality: 'both',
|
|
252
|
+
httpMethod: 'PUT',
|
|
253
|
+
aliases: {
|
|
254
|
+
deprecated: ['setProfilePic'],
|
|
255
|
+
},
|
|
256
|
+
wapiOverride: 'setProfilePic',
|
|
257
|
+
},
|
|
258
|
+
input: z.object({ image: imageDataParam }),
|
|
259
|
+
parameterOrder: ['image'],
|
|
260
|
+
output: z.boolean(),
|
|
261
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defineMethodV2 } from '../registry';
|
|
3
|
+
import { contactIdParam } from '../parameters';
|
|
4
|
+
|
|
5
|
+
export const postTextStatus = defineMethodV2('postTextStatus', {
|
|
6
|
+
meta: {
|
|
7
|
+
description: 'Post text status',
|
|
8
|
+
action: 'send',
|
|
9
|
+
namespace: 'status',
|
|
10
|
+
license: 'insiders',
|
|
11
|
+
functionality: 'both',
|
|
12
|
+
httpMethod: 'POST',
|
|
13
|
+
},
|
|
14
|
+
input: z.object({
|
|
15
|
+
text: z.string().describe('Status text'),
|
|
16
|
+
backgroundColor: z.string().optional().describe('Background color'),
|
|
17
|
+
font: z.number().optional().describe('Font style'),
|
|
18
|
+
}),
|
|
19
|
+
parameterOrder: ['text', 'backgroundColor', 'font'],
|
|
20
|
+
output: z.any(),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const postImageStatus = defineMethodV2('postImageStatus', {
|
|
24
|
+
meta: {
|
|
25
|
+
description: 'Post image status',
|
|
26
|
+
action: 'send',
|
|
27
|
+
namespace: 'status',
|
|
28
|
+
license: 'insiders',
|
|
29
|
+
functionality: 'both',
|
|
30
|
+
httpMethod: 'POST',
|
|
31
|
+
},
|
|
32
|
+
input: z.object({
|
|
33
|
+
image: z.string().describe('Image data URL'),
|
|
34
|
+
caption: z.string().optional().describe('Status caption'),
|
|
35
|
+
}),
|
|
36
|
+
parameterOrder: ['image', 'caption'],
|
|
37
|
+
output: z.any(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const postVideoStatus = defineMethodV2('postVideoStatus', {
|
|
41
|
+
meta: {
|
|
42
|
+
description: 'Post video status',
|
|
43
|
+
action: 'send',
|
|
44
|
+
namespace: 'status',
|
|
45
|
+
license: 'insiders',
|
|
46
|
+
functionality: 'both',
|
|
47
|
+
httpMethod: 'POST',
|
|
48
|
+
},
|
|
49
|
+
input: z.object({
|
|
50
|
+
video: z.string().describe('Video data URL'),
|
|
51
|
+
caption: z.string().optional().describe('Status caption'),
|
|
52
|
+
}),
|
|
53
|
+
parameterOrder: ['video', 'caption'],
|
|
54
|
+
output: z.any(),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export const getStories = defineMethodV2('getStories', {
|
|
58
|
+
meta: {
|
|
59
|
+
description: 'Get all stories',
|
|
60
|
+
action: 'read',
|
|
61
|
+
namespace: 'status',
|
|
62
|
+
license: 'insiders',
|
|
63
|
+
functionality: 'both',
|
|
64
|
+
httpMethod: 'GET',
|
|
65
|
+
aliases: {
|
|
66
|
+
explicit: ['getStatuses'],
|
|
67
|
+
namespacedName: 'getAll',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
input: z.object({}),
|
|
71
|
+
parameterOrder: [],
|
|
72
|
+
output: z.array(z.any()),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export const getStatus = defineMethodV2('getStatus', {
|
|
76
|
+
meta: {
|
|
77
|
+
description: 'Get specific status',
|
|
78
|
+
action: 'read',
|
|
79
|
+
namespace: 'mystatus',
|
|
80
|
+
license: 'insiders',
|
|
81
|
+
functionality: 'both',
|
|
82
|
+
httpMethod: 'GET',
|
|
83
|
+
},
|
|
84
|
+
input: z.object({ contactId: contactIdParam }),
|
|
85
|
+
parameterOrder: ['contactId'],
|
|
86
|
+
output: z.any(),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export const deleteStatus = defineMethodV2('deleteStatus', {
|
|
90
|
+
meta: {
|
|
91
|
+
description: 'Delete status',
|
|
92
|
+
action: 'delete',
|
|
93
|
+
namespace: 'status',
|
|
94
|
+
license: 'insiders',
|
|
95
|
+
functionality: 'both',
|
|
96
|
+
httpMethod: 'DELETE',
|
|
97
|
+
},
|
|
98
|
+
input: z.object({
|
|
99
|
+
statusesToDelete: z.union([z.string(), z.array(z.string())]).describe('Status ID(s)'),
|
|
100
|
+
}),
|
|
101
|
+
parameterOrder: ['statusesToDelete'],
|
|
102
|
+
output: z.any(),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
export const deleteAllStatus = defineMethodV2('deleteAllStatus', {
|
|
106
|
+
meta: {
|
|
107
|
+
description: 'Delete all statuses',
|
|
108
|
+
action: 'delete',
|
|
109
|
+
namespace: 'status',
|
|
110
|
+
license: 'insiders',
|
|
111
|
+
functionality: 'both',
|
|
112
|
+
httpMethod: 'DELETE',
|
|
113
|
+
aliases: {
|
|
114
|
+
explicit: ['deleteAllStatuses'],
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
input: z.object({}),
|
|
118
|
+
parameterOrder: [],
|
|
119
|
+
output: z.any(),
|
|
120
|
+
});
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { parameterRegistry } from './registry';
|
|
3
|
+
import {
|
|
4
|
+
ChatIdSchema,
|
|
5
|
+
ContactIdSchema,
|
|
6
|
+
GroupIdSchema,
|
|
7
|
+
MessageIdSchema,
|
|
8
|
+
FileToDataUrlSchema,
|
|
9
|
+
} from './codecs';
|
|
10
|
+
|
|
11
|
+
export const chatIdParam = ChatIdSchema.describe('Chat ID (phone number or formatted ID)').register(
|
|
12
|
+
parameterRegistry,
|
|
13
|
+
{
|
|
14
|
+
example: '447123456789@c.us',
|
|
15
|
+
brandedType: 'ChatId',
|
|
16
|
+
formatDescription: 'A contact ID, group ID, or LID JID',
|
|
17
|
+
pattern: '^\\d+(-\\d+)?@(c|g)\\.us$|^\\d+@lid$',
|
|
18
|
+
keyAliases: ['id', 'contactId'],
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export const contactIdParam = ContactIdSchema.describe('Contact ID').register(parameterRegistry, {
|
|
23
|
+
example: '447123456789@c.us',
|
|
24
|
+
brandedType: 'ContactId',
|
|
25
|
+
formatDescription: 'A WhatsApp contact JID',
|
|
26
|
+
pattern: '^\\d+@c\\.us$',
|
|
27
|
+
keyAliases: ['id'],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const groupIdParam = GroupIdSchema.describe('Group chat ID').register(parameterRegistry, {
|
|
31
|
+
example: '447123456789-1445627445@g.us',
|
|
32
|
+
brandedType: 'GroupChatId',
|
|
33
|
+
formatDescription: 'A WhatsApp group JID',
|
|
34
|
+
pattern: '^\\d+(-\\d+)?@g\\.us$',
|
|
35
|
+
keyAliases: ['chatId', 'groupChatId'],
|
|
36
|
+
deprecatedKeyAliases: ['groupChatId'],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const communityIdParam = GroupIdSchema.describe('Community ID').register(parameterRegistry, {
|
|
40
|
+
example: '447123456789-1445627445@g.us',
|
|
41
|
+
brandedType: 'GroupChatId',
|
|
42
|
+
formatDescription: 'A WhatsApp community JID',
|
|
43
|
+
pattern: '^\\d+(-\\d+)?@g\\.us$',
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const messageIdParam = MessageIdSchema.describe('Message ID').register(parameterRegistry, {
|
|
47
|
+
example: 'false_447123456789@c.us_9C4D0965EA5C09D591334AB6BDB07FEB',
|
|
48
|
+
brandedType: 'MessageId',
|
|
49
|
+
formatDescription: 'A WhatsApp message identifier',
|
|
50
|
+
pattern: '^(true|false)_.+_.+$',
|
|
51
|
+
keyAliases: ['id', 'msgId'],
|
|
52
|
+
deprecatedKeyAliases: ['msgId'],
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const toParam = ChatIdSchema.describe('Recipient chat ID').register(parameterRegistry, {
|
|
56
|
+
example: '447123456789@c.us',
|
|
57
|
+
brandedType: 'ChatId',
|
|
58
|
+
formatDescription: 'The target chat for a send operation',
|
|
59
|
+
pattern: '^\\d+(-\\d+)?@(c|g)\\.us$|^\\d+@lid$',
|
|
60
|
+
keyAliases: ['chatId'],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export const contentParam = z.string().min(1).brand('Content').describe('Message content').register(
|
|
64
|
+
parameterRegistry,
|
|
65
|
+
{
|
|
66
|
+
example: 'Hello, world!',
|
|
67
|
+
brandedType: 'Content',
|
|
68
|
+
keyAliases: ['text', 'body', 'message'],
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
export const captionParam = z.string().optional().describe('Media caption').register(parameterRegistry, {
|
|
73
|
+
example: 'Check out this image!',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export const filenameParam = z.string().optional().describe('Filename with extension').register(
|
|
77
|
+
parameterRegistry,
|
|
78
|
+
{
|
|
79
|
+
example: 'document.pdf',
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
export const userAgentParam = z.string().optional().describe('User agent string').register(
|
|
84
|
+
parameterRegistry,
|
|
85
|
+
{
|
|
86
|
+
example: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)',
|
|
87
|
+
keyAliases: ['userA'],
|
|
88
|
+
deprecatedKeyAliases: ['userA'],
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
export const nameParam = z.string().describe('Display name').register(parameterRegistry, {
|
|
93
|
+
example: 'OpenWA Bot',
|
|
94
|
+
keyAliases: ['newName'],
|
|
95
|
+
deprecatedKeyAliases: ['newName'],
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export const statusTextParam = z.string().describe('Status text').register(parameterRegistry, {
|
|
99
|
+
example: 'Available',
|
|
100
|
+
keyAliases: ['newStatus'],
|
|
101
|
+
deprecatedKeyAliases: ['newStatus'],
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export const imageDataParam = FileToDataUrlSchema.describe(
|
|
105
|
+
'Image file (path, URL, DataURL, or Base64)'
|
|
106
|
+
).register(parameterRegistry, {
|
|
107
|
+
example: 'data:image/png;base64,iVBORw0KGgo...',
|
|
108
|
+
brandedType: 'DataURL',
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
export const fileDataParam = FileToDataUrlSchema.describe(
|
|
112
|
+
'File (path, URL, DataURL, Base64, or Buffer)'
|
|
113
|
+
).register(parameterRegistry, {
|
|
114
|
+
example: 'data:application/pdf;base64,JVBERi0xLjQK...',
|
|
115
|
+
brandedType: 'DataURL',
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
export const audioDataParam = FileToDataUrlSchema.describe(
|
|
119
|
+
'Audio file (path, URL, DataURL, or Base64)'
|
|
120
|
+
).register(parameterRegistry, {
|
|
121
|
+
example: 'data:audio/mpeg;base64,SUQzBAAAAAAAI1RTU0UAAAA...',
|
|
122
|
+
brandedType: 'DataURL',
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
export const videoDataParam = FileToDataUrlSchema.describe(
|
|
126
|
+
'Video file (path, URL, DataURL, or Base64)'
|
|
127
|
+
).register(parameterRegistry, {
|
|
128
|
+
example: 'data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21...',
|
|
129
|
+
brandedType: 'DataURL',
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
export const documentDataParam = FileToDataUrlSchema.describe(
|
|
133
|
+
'Document file (path, URL, DataURL, or Base64)'
|
|
134
|
+
).register(parameterRegistry, {
|
|
135
|
+
example: 'data:application/pdf;base64,JVBERi0xLjQK...',
|
|
136
|
+
brandedType: 'DataURL',
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
export const stickerDataParam = FileToDataUrlSchema.describe(
|
|
140
|
+
'Sticker file (path, URL, DataURL, or Base64)'
|
|
141
|
+
).register(parameterRegistry, {
|
|
142
|
+
example: 'data:image/webp;base64,UklGRiQAAABXRUJQVlA4IBgAAAAw...',
|
|
143
|
+
brandedType: 'DataURL',
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
export const latitudeParam = z.union([z.number(), z.string()]).describe('Latitude coordinate').register(
|
|
147
|
+
parameterRegistry,
|
|
148
|
+
{
|
|
149
|
+
example: 51.5074,
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
export const longitudeParam = z.union([z.number(), z.string()]).describe('Longitude coordinate').register(
|
|
154
|
+
parameterRegistry,
|
|
155
|
+
{
|
|
156
|
+
example: -0.1278,
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
export const locationNameParam = z.string().optional().describe('Location name or description').register(
|
|
161
|
+
parameterRegistry,
|
|
162
|
+
{
|
|
163
|
+
example: 'London, UK',
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
export const waitForIdParam = z.boolean().optional().default(false).describe('Wait for message ID').register(
|
|
168
|
+
parameterRegistry,
|
|
169
|
+
{
|
|
170
|
+
example: true,
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
export const includeMeParam = z.boolean().optional().default(true).describe('Include own messages').register(
|
|
175
|
+
parameterRegistry,
|
|
176
|
+
{
|
|
177
|
+
example: true,
|
|
178
|
+
}
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
export const includeNotificationsParam = z
|
|
182
|
+
.boolean()
|
|
183
|
+
.optional()
|
|
184
|
+
.default(false)
|
|
185
|
+
.describe('Include notification messages')
|
|
186
|
+
.register(parameterRegistry, {
|
|
187
|
+
example: false,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
export const onlyLocalParam = z.boolean().optional().default(false).describe('Delete only locally').register(
|
|
191
|
+
parameterRegistry,
|
|
192
|
+
{
|
|
193
|
+
example: false,
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
export const skipMyMessagesParam = z
|
|
198
|
+
.boolean()
|
|
199
|
+
.optional()
|
|
200
|
+
.default(false)
|
|
201
|
+
.describe('Skip own messages')
|
|
202
|
+
.register(parameterRegistry, {
|
|
203
|
+
example: false,
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
export const withNewMessagesOnlyParam = z
|
|
207
|
+
.boolean()
|
|
208
|
+
.optional()
|
|
209
|
+
.default(false)
|
|
210
|
+
.describe('Only chats with unread messages')
|
|
211
|
+
.register(parameterRegistry, {
|
|
212
|
+
example: false,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
export const messageIdsParam = z
|
|
216
|
+
.union([z.array(messageIdParam), messageIdParam])
|
|
217
|
+
.describe('Message ID(s) to process')
|
|
218
|
+
.register(parameterRegistry, {
|
|
219
|
+
example: ['false_447123456789@c.us_ABC123', 'false_447123456789@c.us_DEF456'],
|
|
220
|
+
brandedType: 'MessageId[]',
|
|
221
|
+
keyAliases: ['messages'],
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
export const mentionedJidListParam = z
|
|
225
|
+
.array(contactIdParam)
|
|
226
|
+
.optional()
|
|
227
|
+
.describe('List of mentioned contact IDs')
|
|
228
|
+
.register(parameterRegistry, {
|
|
229
|
+
example: ['447123456789@c.us', '441234567890@c.us'],
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
export const messageOptionsParam = z.any().optional().describe('Additional message options').register(
|
|
233
|
+
parameterRegistry,
|
|
234
|
+
{
|
|
235
|
+
example: { quotedMsg: 'messageId', mentionedJidList: ['447123456789@c.us'] },
|
|
236
|
+
}
|
|
237
|
+
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineMethod, Registry, z } from './registry';
|
|
2
|
+
|
|
3
|
+
describe('Schema Registry', () => {
|
|
4
|
+
it('should register and retrieve a method', () => {
|
|
5
|
+
defineMethod('testMethod', {
|
|
6
|
+
meta: { description: 'A test method' },
|
|
7
|
+
input: z.object({ foo: z.string() }),
|
|
8
|
+
output: z.object({ bar: z.number() }),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const retrieved = Registry.getMethod('testMethod');
|
|
12
|
+
expect(retrieved).toBeDefined();
|
|
13
|
+
expect(retrieved?.name).toBe('testMethod');
|
|
14
|
+
expect(retrieved?.metadata.description).toBe('A test method');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should validate input using registered schema', () => {
|
|
18
|
+
const TestMethod = defineMethod('validationTest', {
|
|
19
|
+
meta: { description: 'Validation test' },
|
|
20
|
+
input: z.object({ email: z.string().email() }),
|
|
21
|
+
output: z.void(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const valid = TestMethod.inputSchema.safeParse({ email: 'test@example.com' });
|
|
25
|
+
expect(valid.success).toBe(true);
|
|
26
|
+
|
|
27
|
+
const invalid = TestMethod.inputSchema.safeParse({ email: 'not-an-email' });
|
|
28
|
+
expect(invalid.success).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
});
|