@badzz88/baileys 8.2.0 → 8.4.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/README.md +27 -27
- package/WAProto/fix-import.js +29 -0
- package/engine-requirements.js +2 -2
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Signal/p +1 -0
- package/lib/Socket/chats.js +21 -4
- package/lib/Socket/communities.d.ts +180 -0
- package/lib/Socket/communities.js +421 -0
- package/lib/Socket/luxu.d.ts +266 -0
- package/lib/Socket/luxu.js +541 -0
- package/lib/Socket/messages-send.d.ts +34 -0
- package/lib/Socket/messages-send.js +312 -137
- package/lib/Socket/newsletter.js +3 -4
- package/lib/Socket/socket.d.ts +1 -0
- package/lib/Socket/socket.js +71 -0
- package/lib/Utils/messages.js +15 -4
- package/lib/index.js +25 -21
- package/package.json +6 -5
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
const WAProto_1 = require('../../WAProto');
|
|
2
|
+
const Types_1 = require('../Types');
|
|
3
|
+
const Utils_1 = require('../Utils');
|
|
4
|
+
const WABinary_1 = require('../WABinary');
|
|
5
|
+
const newsletter_1 = require('./newsletter');
|
|
6
|
+
|
|
7
|
+
const makeCommunitiesSocket = (config) => {
|
|
8
|
+
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
|
9
|
+
const { authState, ev, query, upsertMessage } = sock;
|
|
10
|
+
|
|
11
|
+
const communityQuery = async (jid, type, content) => query({
|
|
12
|
+
tag: 'iq',
|
|
13
|
+
attrs: {
|
|
14
|
+
type,
|
|
15
|
+
xmlns: 'w:g2',
|
|
16
|
+
to: jid
|
|
17
|
+
},
|
|
18
|
+
content
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const communityMetadata = async (jid) => {
|
|
22
|
+
const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
|
|
23
|
+
return extractCommunityMetadata(result);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const communityFetchAllParticipating = async () => {
|
|
27
|
+
const result = await query({
|
|
28
|
+
tag: 'iq',
|
|
29
|
+
attrs: {
|
|
30
|
+
to: '@g.us',
|
|
31
|
+
xmlns: 'w:g2',
|
|
32
|
+
type: 'get'
|
|
33
|
+
},
|
|
34
|
+
content: [
|
|
35
|
+
{
|
|
36
|
+
tag: 'participating',
|
|
37
|
+
attrs: {},
|
|
38
|
+
content: [
|
|
39
|
+
{ tag: 'participants', attrs: {} },
|
|
40
|
+
{ tag: 'description', attrs: {} }
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
});
|
|
45
|
+
const data = {};
|
|
46
|
+
const communitiesChild = WABinary_1.getBinaryNodeChild(result, 'communities');
|
|
47
|
+
if (communitiesChild) {
|
|
48
|
+
const communities = WABinary_1.getBinaryNodeChildren(communitiesChild, 'community');
|
|
49
|
+
for (const communityNode of communities) {
|
|
50
|
+
const meta = extractCommunityMetadata({
|
|
51
|
+
tag: 'result',
|
|
52
|
+
attrs: {},
|
|
53
|
+
content: [communityNode]
|
|
54
|
+
});
|
|
55
|
+
data[meta.id] = meta;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
sock.ev.emit('groups.update', Object.values(data));
|
|
59
|
+
return data;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
async function parseGroupResult(node) {
|
|
63
|
+
Utils_1.logger.info({ node }, 'parseGroupResult');
|
|
64
|
+
const groupNode = WABinary_1.getBinaryNodeChild(node, 'group');
|
|
65
|
+
if (groupNode) {
|
|
66
|
+
try {
|
|
67
|
+
Utils_1.logger.info({ groupNode }, 'groupNode');
|
|
68
|
+
const metadata = await sock.groupMetadata(`${groupNode.attrs.id}@g.us`);
|
|
69
|
+
return metadata? metadata : Optional.empty();
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.error('Error parsing group metadata:', error);
|
|
73
|
+
return Optional.empty();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return Optional.empty();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const Optional = {
|
|
80
|
+
empty: () => null,
|
|
81
|
+
of: (value) => (value!== null? { value } : null)
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
sock.ws.on('CB:ib,,dirty', async (node) => {
|
|
85
|
+
const { attrs } = WABinary_1.getBinaryNodeChild(node, 'dirty');
|
|
86
|
+
if (attrs.type!== 'communities') {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
await communityFetchAllParticipating();
|
|
90
|
+
await sock.cleanDirtyBits('groups');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
...sock,
|
|
95
|
+
communityMetadata,
|
|
96
|
+
communityCreate: async (subject, body) => {
|
|
97
|
+
const descriptionId = Utils_1.generateMessageID().substring(0, 12);
|
|
98
|
+
const result = await communityQuery('@g.us', 'set', [
|
|
99
|
+
{
|
|
100
|
+
tag: 'create',
|
|
101
|
+
attrs: { subject },
|
|
102
|
+
content: [
|
|
103
|
+
{
|
|
104
|
+
tag: 'description',
|
|
105
|
+
attrs: { id: descriptionId },
|
|
106
|
+
content: [
|
|
107
|
+
{
|
|
108
|
+
tag: 'body',
|
|
109
|
+
attrs: {},
|
|
110
|
+
content: Buffer.from(body || '', 'utf-8')
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
tag: 'parent',
|
|
116
|
+
attrs: { default_membership_approval_mode: 'request_required' }
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
tag: 'allow_non_admin_sub_group_creation',
|
|
120
|
+
attrs: {}
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
tag: 'create_general_chat',
|
|
124
|
+
attrs: {}
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
]);
|
|
129
|
+
return await parseGroupResult(result);
|
|
130
|
+
},
|
|
131
|
+
communityCreateGroup: async (subject, participants, parentCommunityJid) => {
|
|
132
|
+
const key = Utils_1.generateMessageIDV2();
|
|
133
|
+
const result = await communityQuery('@g.us', 'set', [
|
|
134
|
+
{
|
|
135
|
+
tag: 'create',
|
|
136
|
+
attrs: {
|
|
137
|
+
subject,
|
|
138
|
+
key
|
|
139
|
+
},
|
|
140
|
+
content: [
|
|
141
|
+
...participants.map(jid => ({
|
|
142
|
+
tag: 'participant',
|
|
143
|
+
attrs: { jid }
|
|
144
|
+
})),
|
|
145
|
+
{ tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
]);
|
|
149
|
+
return await parseGroupResult(result);
|
|
150
|
+
},
|
|
151
|
+
communityLeave: async (id) => {
|
|
152
|
+
await communityQuery('@g.us', 'set', [
|
|
153
|
+
{
|
|
154
|
+
tag: 'leave',
|
|
155
|
+
attrs: {},
|
|
156
|
+
content: [{ tag: 'community', attrs: { id } }]
|
|
157
|
+
}
|
|
158
|
+
]);
|
|
159
|
+
},
|
|
160
|
+
communityUpdateSubject: async (jid, subject) => {
|
|
161
|
+
await communityQuery(jid, 'set', [
|
|
162
|
+
{
|
|
163
|
+
tag: 'subject',
|
|
164
|
+
attrs: {},
|
|
165
|
+
content: Buffer.from(subject, 'utf-8')
|
|
166
|
+
}
|
|
167
|
+
]);
|
|
168
|
+
},
|
|
169
|
+
communityLinkGroup: async (groupJid, parentCommunityJid) => {
|
|
170
|
+
await communityQuery(parentCommunityJid, 'set', [
|
|
171
|
+
{
|
|
172
|
+
tag: 'links',
|
|
173
|
+
attrs: {},
|
|
174
|
+
content: [
|
|
175
|
+
{
|
|
176
|
+
tag: 'link',
|
|
177
|
+
attrs: { link_type: 'sub_group' },
|
|
178
|
+
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
}
|
|
182
|
+
]);
|
|
183
|
+
},
|
|
184
|
+
communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
|
|
185
|
+
await communityQuery(parentCommunityJid, 'set', [
|
|
186
|
+
{
|
|
187
|
+
tag: 'unlink',
|
|
188
|
+
attrs: { unlink_type: 'sub_group' },
|
|
189
|
+
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
190
|
+
}
|
|
191
|
+
]);
|
|
192
|
+
},
|
|
193
|
+
communityFetchLinkedGroups: async (jid) => {
|
|
194
|
+
let communityJid = jid;
|
|
195
|
+
let isCommunity = false;
|
|
196
|
+
const metadata = await sock.groupMetadata(jid);
|
|
197
|
+
if (metadata.linkedParent) {
|
|
198
|
+
communityJid = metadata.linkedParent;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
isCommunity = true;
|
|
202
|
+
}
|
|
203
|
+
const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }]);
|
|
204
|
+
const linkedGroupsData = [];
|
|
205
|
+
const subGroupsNode = WABinary_1.getBinaryNodeChild(result, 'sub_groups');
|
|
206
|
+
if (subGroupsNode) {
|
|
207
|
+
const groupNodes = WABinary_1.getBinaryNodeChildren(subGroupsNode, 'group');
|
|
208
|
+
for (const groupNode of groupNodes) {
|
|
209
|
+
linkedGroupsData.push({
|
|
210
|
+
id: groupNode.attrs.id? WABinary_1.jidEncode(groupNode.attrs.id, 'g.us') : undefined,
|
|
211
|
+
subject: groupNode.attrs.subject || '',
|
|
212
|
+
creation: groupNode.attrs.creation? Number(groupNode.attrs.creation) : undefined,
|
|
213
|
+
owner: groupNode.attrs.creator? WABinary_1.jidNormalizedUser(groupNode.attrs.creator) : undefined,
|
|
214
|
+
size: groupNode.attrs.size? Number(groupNode.attrs.size) : undefined
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
communityJid,
|
|
220
|
+
isCommunity,
|
|
221
|
+
linkedGroups: linkedGroupsData
|
|
222
|
+
};
|
|
223
|
+
},
|
|
224
|
+
communityRequestParticipantsList: async (jid) => {
|
|
225
|
+
const result = await communityQuery(jid, 'get', [
|
|
226
|
+
{
|
|
227
|
+
tag: 'membership_approval_requests',
|
|
228
|
+
attrs: {}
|
|
229
|
+
}
|
|
230
|
+
]);
|
|
231
|
+
const node = WABinary_1.getBinaryNodeChild(result, 'membership_approval_requests');
|
|
232
|
+
const participants = WABinary_1.getBinaryNodeChildren(node, 'membership_approval_request');
|
|
233
|
+
return participants.map(v => v.attrs);
|
|
234
|
+
},
|
|
235
|
+
communityRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
236
|
+
const result = await communityQuery(jid, 'set', [
|
|
237
|
+
{
|
|
238
|
+
tag: 'membership_requests_action',
|
|
239
|
+
attrs: {},
|
|
240
|
+
content: [
|
|
241
|
+
{
|
|
242
|
+
tag: action,
|
|
243
|
+
attrs: {},
|
|
244
|
+
content: participants.map(jid => ({
|
|
245
|
+
tag: 'participant',
|
|
246
|
+
attrs: { jid }
|
|
247
|
+
}))
|
|
248
|
+
}
|
|
249
|
+
]
|
|
250
|
+
}
|
|
251
|
+
]);
|
|
252
|
+
const node = WABinary_1.getBinaryNodeChild(result, 'membership_requests_action');
|
|
253
|
+
const nodeAction = WABinary_1.getBinaryNodeChild(node, action);
|
|
254
|
+
const participantsAffected = WABinary_1.getBinaryNodeChildren(nodeAction, 'participant');
|
|
255
|
+
return participantsAffected.map(p => {
|
|
256
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid };
|
|
257
|
+
});
|
|
258
|
+
},
|
|
259
|
+
communityParticipantsUpdate: async (jid, participants, action) => {
|
|
260
|
+
const result = await communityQuery(jid, 'set', [
|
|
261
|
+
{
|
|
262
|
+
tag: action,
|
|
263
|
+
attrs: action === 'remove'? { linked_groups: 'true' } : {},
|
|
264
|
+
content: participants.map(jid => ({
|
|
265
|
+
tag: 'participant',
|
|
266
|
+
attrs: { jid }
|
|
267
|
+
}))
|
|
268
|
+
}
|
|
269
|
+
]);
|
|
270
|
+
const node = WABinary_1.getBinaryNodeChild(result, action);
|
|
271
|
+
const participantsAffected = WABinary_1.getBinaryNodeChildren(node, 'participant');
|
|
272
|
+
return participantsAffected.map(p => {
|
|
273
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
communityUpdateDescription: async (jid, description) => {
|
|
277
|
+
const metadata = await communityMetadata(jid);
|
|
278
|
+
const prev = metadata.descId?? null;
|
|
279
|
+
await communityQuery(jid, 'set', [
|
|
280
|
+
{
|
|
281
|
+
tag: 'description',
|
|
282
|
+
attrs: {
|
|
283
|
+
...(description? { id: Utils_1.generateMessageID() } : { delete: 'true' }),
|
|
284
|
+
...(prev? { prev } : {})
|
|
285
|
+
},
|
|
286
|
+
content: description? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
|
|
287
|
+
}
|
|
288
|
+
]);
|
|
289
|
+
},
|
|
290
|
+
communityInviteCode: async (jid) => {
|
|
291
|
+
const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
|
|
292
|
+
const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite');
|
|
293
|
+
return inviteNode?.attrs.code;
|
|
294
|
+
},
|
|
295
|
+
communityRevokeInvite: async (jid) => {
|
|
296
|
+
const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
|
|
297
|
+
const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite');
|
|
298
|
+
return inviteNode?.attrs.code;
|
|
299
|
+
},
|
|
300
|
+
communityAcceptInvite: async (code) => {
|
|
301
|
+
const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
|
|
302
|
+
const result = WABinary_1.getBinaryNodeChild(results, 'community');
|
|
303
|
+
return result?.attrs.jid;
|
|
304
|
+
},
|
|
305
|
+
communityRevokeInviteV4: async (communityJid, invitedJid) => {
|
|
306
|
+
const result = await communityQuery(communityJid, 'set', [
|
|
307
|
+
{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
|
|
308
|
+
]);
|
|
309
|
+
return!!result;
|
|
310
|
+
},
|
|
311
|
+
communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
312
|
+
key = typeof key === 'string'? { remoteJid: key } : key;
|
|
313
|
+
const results = await communityQuery(inviteMessage.groupJid, 'set', [
|
|
314
|
+
{
|
|
315
|
+
tag: 'accept',
|
|
316
|
+
attrs: {
|
|
317
|
+
code: inviteMessage.inviteCode,
|
|
318
|
+
expiration: inviteMessage.inviteExpiration.toString(),
|
|
319
|
+
admin: key.remoteJid
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
]);
|
|
323
|
+
if (key.id) {
|
|
324
|
+
inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
325
|
+
inviteMessage.inviteExpiration = 0;
|
|
326
|
+
inviteMessage.inviteCode = '';
|
|
327
|
+
ev.emit('messages.update', [
|
|
328
|
+
{
|
|
329
|
+
key,
|
|
330
|
+
update: {
|
|
331
|
+
message: {
|
|
332
|
+
groupInviteMessage: inviteMessage
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
]);
|
|
337
|
+
}
|
|
338
|
+
await upsertMessage({
|
|
339
|
+
key: {
|
|
340
|
+
remoteJid: inviteMessage.groupJid,
|
|
341
|
+
id: Utils_1.generateMessageIDV2(sock.user?.id),
|
|
342
|
+
fromMe: false,
|
|
343
|
+
participant: key.remoteJid
|
|
344
|
+
},
|
|
345
|
+
messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
346
|
+
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
347
|
+
participant: key.remoteJid,
|
|
348
|
+
messageTimestamp: Utils_1.unixTimestampSeconds()
|
|
349
|
+
}, 'notify');
|
|
350
|
+
return results.attrs.from;
|
|
351
|
+
}),
|
|
352
|
+
communityGetInviteInfo: async (code) => {
|
|
353
|
+
const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
|
|
354
|
+
return extractCommunityMetadata(results);
|
|
355
|
+
},
|
|
356
|
+
communityToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
357
|
+
const content = ephemeralExpiration
|
|
358
|
+
? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
359
|
+
: { tag: 'not_ephemeral', attrs: {} };
|
|
360
|
+
await communityQuery(jid, 'set', [content]);
|
|
361
|
+
},
|
|
362
|
+
communitySettingUpdate: async (jid, setting) => {
|
|
363
|
+
await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
|
|
364
|
+
},
|
|
365
|
+
communityMemberAddMode: async (jid, mode) => {
|
|
366
|
+
await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
|
|
367
|
+
},
|
|
368
|
+
communityJoinApprovalMode: async (jid, mode) => {
|
|
369
|
+
await communityQuery(jid, 'set', [
|
|
370
|
+
{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
|
|
371
|
+
]);
|
|
372
|
+
},
|
|
373
|
+
communityFetchAllParticipating
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
const extractCommunityMetadata = (result) => {
|
|
378
|
+
const community = WABinary_1.getBinaryNodeChild(result, 'community');
|
|
379
|
+
const descChild = WABinary_1.getBinaryNodeChild(community, 'description');
|
|
380
|
+
let desc;
|
|
381
|
+
let descId;
|
|
382
|
+
if (descChild) {
|
|
383
|
+
desc = WABinary_1.getBinaryNodeChildString(descChild, 'body');
|
|
384
|
+
descId = descChild.attrs.id;
|
|
385
|
+
}
|
|
386
|
+
const communityId = community.attrs.id?.includes('@')
|
|
387
|
+
? community.attrs.id
|
|
388
|
+
: WABinary_1.jidEncode(community.attrs.id || '', 'g.us');
|
|
389
|
+
const eph = WABinary_1.getBinaryNodeChild(community, 'ephemeral')?.attrs.expiration;
|
|
390
|
+
const memberAddMode = WABinary_1.getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add';
|
|
391
|
+
const metadata = {
|
|
392
|
+
id: communityId,
|
|
393
|
+
subject: community.attrs.subject || '',
|
|
394
|
+
subjectOwner: community.attrs.s_o,
|
|
395
|
+
subjectTime: Number(community.attrs.s_t || 0),
|
|
396
|
+
size: WABinary_1.getBinaryNodeChildren(community, 'participant').length,
|
|
397
|
+
creation: Number(community.attrs.creation || 0),
|
|
398
|
+
owner: community.attrs.creator? WABinary_1.jidNormalizedUser(community.attrs.creator) : undefined,
|
|
399
|
+
desc,
|
|
400
|
+
descId,
|
|
401
|
+
linkedParent: WABinary_1.getBinaryNodeChild(community, 'linked_parent')?.attrs.jid || undefined,
|
|
402
|
+
restrict:!!WABinary_1.getBinaryNodeChild(community, 'locked'),
|
|
403
|
+
announce:!!WABinary_1.getBinaryNodeChild(community, 'announcement'),
|
|
404
|
+
isCommunity:!!WABinary_1.getBinaryNodeChild(community, 'parent'),
|
|
405
|
+
isCommunityAnnounce:!!WABinary_1.getBinaryNodeChild(community, 'default_sub_community'),
|
|
406
|
+
joinApprovalMode:!!WABinary_1.getBinaryNodeChild(community, 'membership_approval_mode'),
|
|
407
|
+
memberAddMode,
|
|
408
|
+
participants: WABinary_1.getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
|
|
409
|
+
return {
|
|
410
|
+
id: attrs.jid,
|
|
411
|
+
admin: (attrs.type || null)
|
|
412
|
+
};
|
|
413
|
+
}),
|
|
414
|
+
ephemeralDuration: eph? +eph : undefined,
|
|
415
|
+
addressingMode: WABinary_1.getBinaryNodeChildString(community, 'addressing_mode')
|
|
416
|
+
};
|
|
417
|
+
return metadata;
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
exports.makeCommunitiesSocket = makeCommunitiesSocket;
|
|
421
|
+
exports.extractCommunityMetadata = extractCommunityMetadata;
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { proto } from '../../WAProto';
|
|
2
|
+
|
|
3
|
+
declare namespace imup {
|
|
4
|
+
interface MediaUploadOptions {
|
|
5
|
+
fileEncSha256?: Buffer;
|
|
6
|
+
mediaType?: string;
|
|
7
|
+
newsletter?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type WAMediaUploadFunction = (
|
|
11
|
+
stream: Buffer | NodeJS.ReadableStream,
|
|
12
|
+
options?: MediaUploadOptions
|
|
13
|
+
) => Promise<{ url: string; directPath: string }>;
|
|
14
|
+
|
|
15
|
+
interface WAMessageContentGenerationOptions {
|
|
16
|
+
upload?: WAMediaUploadFunction;
|
|
17
|
+
mediaCache?: any;
|
|
18
|
+
options?: any;
|
|
19
|
+
logger?: any;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface StickerMessage {
|
|
23
|
+
url: string;
|
|
24
|
+
fileSha256: Buffer | string;
|
|
25
|
+
fileEncSha256: Buffer | string;
|
|
26
|
+
mediaKey: Buffer | string;
|
|
27
|
+
mimetype: string;
|
|
28
|
+
directPath: string;
|
|
29
|
+
fileLength: number | string;
|
|
30
|
+
mediaKeyTimestamp: number | string;
|
|
31
|
+
isAnimated?: boolean;
|
|
32
|
+
stickerSentTs?: number | string;
|
|
33
|
+
isAvatar?: boolean;
|
|
34
|
+
isAiSticker?: boolean;
|
|
35
|
+
isLottie?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface PaymentMessage {
|
|
39
|
+
amount: number;
|
|
40
|
+
currency?: string;
|
|
41
|
+
from?: string;
|
|
42
|
+
expiry?: number;
|
|
43
|
+
sticker?: { stickerMessage: StickerMessage };
|
|
44
|
+
note?: string;
|
|
45
|
+
background?: {
|
|
46
|
+
id?: string;
|
|
47
|
+
fileLength?: string;
|
|
48
|
+
width?: number;
|
|
49
|
+
height?: number;
|
|
50
|
+
mimetype?: string;
|
|
51
|
+
placeholderArgb?: number;
|
|
52
|
+
textArgb?: number;
|
|
53
|
+
subtextArgb?: number;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface ProductMessage {
|
|
58
|
+
title: string;
|
|
59
|
+
description: string;
|
|
60
|
+
thumbnail: Buffer | { url: string };
|
|
61
|
+
productId: string;
|
|
62
|
+
retailerId: string;
|
|
63
|
+
url: string;
|
|
64
|
+
body?: string;
|
|
65
|
+
footer?: string;
|
|
66
|
+
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
67
|
+
priceAmount1000?: number | null;
|
|
68
|
+
currencyCode?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface InteractiveMessage {
|
|
72
|
+
title: string;
|
|
73
|
+
footer?: string;
|
|
74
|
+
thumbnail?: string;
|
|
75
|
+
image?: string | Buffer | { url: string };
|
|
76
|
+
video?: string | Buffer | { url: string };
|
|
77
|
+
document?: Buffer;
|
|
78
|
+
mimetype?: string;
|
|
79
|
+
fileName?: string;
|
|
80
|
+
jpegThumbnail?: Buffer;
|
|
81
|
+
contextInfo?: {
|
|
82
|
+
mentionedJid?: string[];
|
|
83
|
+
forwardingScore?: number;
|
|
84
|
+
isForwarded?: boolean;
|
|
85
|
+
forwardedNewsletterMessageInfo?: proto.Message.ContextInfo.ForwardedNewsletterMessageInfo;
|
|
86
|
+
externalAdReply?: {
|
|
87
|
+
title?: string;
|
|
88
|
+
body?: string;
|
|
89
|
+
mediaType?: number;
|
|
90
|
+
thumbnailUrl?: string;
|
|
91
|
+
mediaUrl?: string;
|
|
92
|
+
sourceUrl?: string;
|
|
93
|
+
showAdAttribution?: boolean;
|
|
94
|
+
renderLargerThumbnail?: boolean;
|
|
95
|
+
[key: string]: any;
|
|
96
|
+
};
|
|
97
|
+
[key: string]: any;
|
|
98
|
+
};
|
|
99
|
+
externalAdReply?: {
|
|
100
|
+
title?: string;
|
|
101
|
+
body?: string;
|
|
102
|
+
mediaType?: number;
|
|
103
|
+
thumbnailUrl?: string;
|
|
104
|
+
mediaUrl?: string;
|
|
105
|
+
sourceUrl?: string;
|
|
106
|
+
showAdAttribution?: boolean;
|
|
107
|
+
renderLargerThumbnail?: boolean;
|
|
108
|
+
[key: string]: any;
|
|
109
|
+
};
|
|
110
|
+
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
111
|
+
nativeFlowMessage?: {
|
|
112
|
+
messageParamsJson?: string;
|
|
113
|
+
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
114
|
+
[key: string]: any;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface AlbumItem {
|
|
119
|
+
image?: { url: string; caption?: string };
|
|
120
|
+
video?: { url: string; caption?: string };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
interface EventMessageLocation {
|
|
124
|
+
degreesLatitude: number;
|
|
125
|
+
degreesLongitude: number;
|
|
126
|
+
name: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface EventMessage {
|
|
130
|
+
isCanceled?: boolean;
|
|
131
|
+
name: string;
|
|
132
|
+
description: string;
|
|
133
|
+
location?: EventMessageLocation;
|
|
134
|
+
joinLink?: string;
|
|
135
|
+
startTime?: string | number;
|
|
136
|
+
endTime?: string | number;
|
|
137
|
+
extraGuestsAllowed?: boolean;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
interface PollVote {
|
|
141
|
+
optionName: string;
|
|
142
|
+
optionVoteCount: string | number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
interface PollResultMessage {
|
|
146
|
+
name: string;
|
|
147
|
+
pollVotes: PollVote[];
|
|
148
|
+
newsletter?: {
|
|
149
|
+
newsletterName: string;
|
|
150
|
+
newsletterJid: string;
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
interface OrderMessage {
|
|
155
|
+
thumbnail?: Buffer | string,
|
|
156
|
+
itemCount?: string | number,
|
|
157
|
+
message: string,
|
|
158
|
+
orderTitle: string,
|
|
159
|
+
totalAmount1000?: string | number,
|
|
160
|
+
totalCurrencyCode?: string
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
interface GroupStatus {
|
|
164
|
+
message?: any;
|
|
165
|
+
image?: string | Buffer | { url: string };
|
|
166
|
+
video?: string | Buffer | { url: string };
|
|
167
|
+
text?: string;
|
|
168
|
+
caption?: string;
|
|
169
|
+
document?: string | Buffer | { url: string };
|
|
170
|
+
[key: string]: any;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
interface GroupLabel {
|
|
174
|
+
labelText: string;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
interface MessageContent {
|
|
178
|
+
requestPaymentMessage?: PaymentMessage;
|
|
179
|
+
productMessage?: ProductMessage;
|
|
180
|
+
interactiveMessage?: InteractiveMessage;
|
|
181
|
+
albumMessage?: AlbumItem[];
|
|
182
|
+
eventMessage?: EventMessage;
|
|
183
|
+
pollResultMessage?: PollResultMessage;
|
|
184
|
+
groupStatus?: GroupStatus;
|
|
185
|
+
orderMessage?: OrderMessage;
|
|
186
|
+
groupLabel?: GroupLabel;
|
|
187
|
+
sender?: string;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
interface MessageOptions {
|
|
191
|
+
quoted?: proto.IWebMessageInfo;
|
|
192
|
+
filter?: boolean;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
interface Utils {
|
|
196
|
+
prepareWAMessageMedia: (media: any, options: WAMessageContentGenerationOptions) => Promise<any>;
|
|
197
|
+
generateWAMessageContent: (content: any, options: WAMessageContentGenerationOptions) => Promise<any>;
|
|
198
|
+
generateWAMessageFromContent: (jid: string, content: any, options?: any) => Promise<any>;
|
|
199
|
+
generateWAMessage: (jid: string, content: any, options?: any) => Promise<any>;
|
|
200
|
+
generateMessageID: () => string;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
declare class imup {
|
|
205
|
+
constructor(
|
|
206
|
+
utils: imup.Utils,
|
|
207
|
+
waUploadToServer: imup.WAMediaUploadFunction,
|
|
208
|
+
relayMessageFn?: (jid: string, content: any, options?: any) => Promise<any>
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
detectType(content: imup.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | 'GROUP_STATUS' | 'ORDER' | 'GROUP_LABEL' |null;
|
|
212
|
+
|
|
213
|
+
handlePayment(
|
|
214
|
+
content: { requestPaymentMessage: imup.PaymentMessage },
|
|
215
|
+
quoted?: proto.IWebMessageInfo
|
|
216
|
+
): Promise<{ requestPaymentMessage: proto.Message.RequestPaymentMessage }>;
|
|
217
|
+
|
|
218
|
+
handleProduct(
|
|
219
|
+
content: { productMessage: imup.ProductMessage },
|
|
220
|
+
jid: string,
|
|
221
|
+
quoted?: proto.IWebMessageInfo
|
|
222
|
+
): Promise<{ viewOnceMessage: proto.Message.ViewOnceMessage }>;
|
|
223
|
+
|
|
224
|
+
handleInteractive(
|
|
225
|
+
content: { interactiveMessage: imup.InteractiveMessage },
|
|
226
|
+
jid: string,
|
|
227
|
+
quoted?: proto.IWebMessageInfo
|
|
228
|
+
): Promise<{ interactiveMessage: proto.Message.InteractiveMessage }>;
|
|
229
|
+
|
|
230
|
+
handleAlbum(
|
|
231
|
+
content: { albumMessage: imup.AlbumItem[] },
|
|
232
|
+
jid: string,
|
|
233
|
+
quoted?: proto.IWebMessageInfo
|
|
234
|
+
): Promise<any>;
|
|
235
|
+
|
|
236
|
+
handleEvent(
|
|
237
|
+
content: { eventMessage: imup.EventMessage },
|
|
238
|
+
jid: string,
|
|
239
|
+
quoted?: proto.IWebMessageInfo
|
|
240
|
+
): Promise<any>;
|
|
241
|
+
|
|
242
|
+
handlePollResult(
|
|
243
|
+
content: { pollResultMessage: imup.PollResultMessage },
|
|
244
|
+
jid: string,
|
|
245
|
+
quoted?: proto.IWebMessageInfo
|
|
246
|
+
): Promise<any>;
|
|
247
|
+
|
|
248
|
+
handleOrderMessage(
|
|
249
|
+
content: { orderMessage: imup.OrderMessage },
|
|
250
|
+
jid: string,
|
|
251
|
+
quoted?: proto.IWebMessageInfo
|
|
252
|
+
): Promise<any>;
|
|
253
|
+
|
|
254
|
+
handleGroupStory(
|
|
255
|
+
content: { groupStatus: imup.GroupStatus },
|
|
256
|
+
jid: string,
|
|
257
|
+
quoted?: proto.IWebMessageInfo
|
|
258
|
+
): Promise<any>;
|
|
259
|
+
|
|
260
|
+
handleGbLabel(
|
|
261
|
+
content: { groupLabel: imup.GroupLabel },
|
|
262
|
+
jid: string,
|
|
263
|
+
): Promise<any>;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export = imup;
|