@queenanya/baileys 7.1.9 → 7.2.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/lib/Defaults/index.js +3 -1
- package/lib/Socket/business.d.ts +13 -5
- package/lib/Socket/chats.d.ts +2 -2
- package/lib/Socket/chats.js +9 -0
- package/lib/Socket/groups.d.ts +1 -1
- package/lib/Socket/index.d.ts +13 -5
- package/lib/Socket/messages-recv.d.ts +12 -5
- package/lib/Socket/messages-recv.js +94 -12
- package/lib/Socket/messages-send.d.ts +9 -4
- package/lib/Socket/messages-send.js +90 -31
- package/lib/Socket/newsletter.d.ts +1 -1
- package/lib/Socket/registration.d.ts +13 -5
- package/lib/Store/make-in-memory-store.js +5 -1
- package/lib/Types/Chat.d.ts +1 -0
- package/lib/Types/Events.d.ts +5 -1
- package/lib/Types/Message.d.ts +15 -25
- package/lib/Types/Socket.d.ts +5 -0
- package/lib/Utils/decode-wa-message.d.ts +1 -0
- package/lib/Utils/decode-wa-message.js +5 -5
- package/lib/Utils/history.d.ts +4 -0
- package/lib/Utils/history.js +3 -0
- package/lib/Utils/messages.js +17 -58
- package/lib/Utils/process-message.d.ts +3 -2
- package/lib/Utils/process-message.js +39 -25
- package/lib/WABinary/jid-utils.d.ts +2 -2
- package/lib/WABinary/jid-utils.js +4 -4
- package/package.json +1 -1
package/lib/Utils/messages.js
CHANGED
|
@@ -30,7 +30,6 @@ const MessageTypeProto = {
|
|
|
30
30
|
'sticker': Types_1.WAProto.Message.StickerMessage,
|
|
31
31
|
'document': Types_1.WAProto.Message.DocumentMessage,
|
|
32
32
|
};
|
|
33
|
-
const ButtonType = WAProto_1.proto.Message.ButtonsMessage.HeaderType;
|
|
34
33
|
/**
|
|
35
34
|
* Uses a regex to test whether the string contains a URL, and returns the URL if it does.
|
|
36
35
|
* @param text eg. hello https://google.com
|
|
@@ -240,7 +239,7 @@ const generateForwardMessageContent = (message, forceForward) => {
|
|
|
240
239
|
exports.generateForwardMessageContent = generateForwardMessageContent;
|
|
241
240
|
const generateWAMessageContent = async (message, options) => {
|
|
242
241
|
var _a;
|
|
243
|
-
var _b;
|
|
242
|
+
var _b, _c;
|
|
244
243
|
let m = {};
|
|
245
244
|
if ('text' in message) {
|
|
246
245
|
const extContent = { text: message.text };
|
|
@@ -382,6 +381,7 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
382
381
|
}
|
|
383
382
|
else if ('poll' in message) {
|
|
384
383
|
(_b = message.poll).selectableCount || (_b.selectableCount = 0);
|
|
384
|
+
(_c = message.poll).toAnnouncementGroup || (_c.toAnnouncementGroup = false);
|
|
385
385
|
if (!Array.isArray(message.poll.values)) {
|
|
386
386
|
throw new boom_1.Boom('Invalid poll values', { statusCode: 400 });
|
|
387
387
|
}
|
|
@@ -393,11 +393,25 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
393
393
|
// encKey
|
|
394
394
|
messageSecret: message.poll.messageSecret || (0, crypto_1.randomBytes)(32),
|
|
395
395
|
};
|
|
396
|
-
|
|
396
|
+
const pollCreationMessage = {
|
|
397
397
|
name: message.poll.name,
|
|
398
398
|
selectableOptionsCount: message.poll.selectableCount,
|
|
399
399
|
options: message.poll.values.map(optionName => ({ optionName })),
|
|
400
400
|
};
|
|
401
|
+
if (message.poll.toAnnouncementGroup) {
|
|
402
|
+
// poll v2 is for community announcement groups (single select and multiple)
|
|
403
|
+
m.pollCreationMessageV2 = pollCreationMessage;
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
if (message.poll.selectableCount > 0) {
|
|
407
|
+
//poll v3 is for single select polls
|
|
408
|
+
m.pollCreationMessageV3 = pollCreationMessage;
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
// poll v3 for multiple choice polls
|
|
412
|
+
m.pollCreationMessage = pollCreationMessage;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
401
415
|
}
|
|
402
416
|
else if ('sharePhoneNumber' in message) {
|
|
403
417
|
m.protocolMessage = {
|
|
@@ -410,61 +424,6 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
410
424
|
else {
|
|
411
425
|
m = await (0, exports.prepareWAMessageMedia)(message, options);
|
|
412
426
|
}
|
|
413
|
-
if ('buttons' in message && !!message.buttons) {
|
|
414
|
-
const buttonsMessage = {
|
|
415
|
-
buttons: message.buttons.map(b => ({ ...b, type: WAProto_1.proto.Message.ButtonsMessage.Button.Type.RESPONSE }))
|
|
416
|
-
};
|
|
417
|
-
if ('text' in message) {
|
|
418
|
-
buttonsMessage.contentText = message.text;
|
|
419
|
-
buttonsMessage.headerType = ButtonType.EMPTY;
|
|
420
|
-
}
|
|
421
|
-
else {
|
|
422
|
-
if ('caption' in message) {
|
|
423
|
-
buttonsMessage.contentText = message.caption;
|
|
424
|
-
}
|
|
425
|
-
const type = Object.keys(m)[0].replace('Message', '').toUpperCase();
|
|
426
|
-
buttonsMessage.headerType = ButtonType[type];
|
|
427
|
-
Object.assign(buttonsMessage, m);
|
|
428
|
-
}
|
|
429
|
-
if ('footer' in message && !!message.footer) {
|
|
430
|
-
buttonsMessage.footerText = message.footer;
|
|
431
|
-
}
|
|
432
|
-
m = { buttonsMessage };
|
|
433
|
-
}
|
|
434
|
-
else if ('templateButtons' in message && !!message.templateButtons) {
|
|
435
|
-
const msg = {
|
|
436
|
-
hydratedButtons: message.templateButtons
|
|
437
|
-
};
|
|
438
|
-
if ('text' in message) {
|
|
439
|
-
msg.hydratedContentText = message.text;
|
|
440
|
-
}
|
|
441
|
-
else {
|
|
442
|
-
if ('caption' in message) {
|
|
443
|
-
msg.hydratedContentText = message.caption;
|
|
444
|
-
}
|
|
445
|
-
Object.assign(msg, m);
|
|
446
|
-
}
|
|
447
|
-
if ('footer' in message && !!message.footer) {
|
|
448
|
-
msg.hydratedFooterText = message.footer;
|
|
449
|
-
}
|
|
450
|
-
m = {
|
|
451
|
-
templateMessage: {
|
|
452
|
-
fourRowTemplate: msg,
|
|
453
|
-
hydratedTemplate: msg
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
}
|
|
457
|
-
if ('sections' in message && !!message.sections) {
|
|
458
|
-
const listMessage = {
|
|
459
|
-
sections: message.sections,
|
|
460
|
-
buttonText: message.buttonText,
|
|
461
|
-
title: message.title,
|
|
462
|
-
footerText: message.footer,
|
|
463
|
-
description: message.text,
|
|
464
|
-
listType: WAProto_1.proto.Message.ListMessage.ListType.SINGLE_SELECT
|
|
465
|
-
};
|
|
466
|
-
m = { listMessage };
|
|
467
|
-
}
|
|
468
427
|
if ('viewOnce' in message && !!message.viewOnce) {
|
|
469
428
|
m = { viewOnceMessage: { message: m } };
|
|
470
429
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import type { Logger } from 'pino';
|
|
3
3
|
import { proto } from '../../WAProto';
|
|
4
|
-
import { AuthenticationCreds, BaileysEventEmitter, SignalKeyStoreWithTransaction, SocketConfig } from '../Types';
|
|
4
|
+
import { AuthenticationCreds, BaileysEventEmitter, CacheStore, SignalKeyStoreWithTransaction, SocketConfig } from '../Types';
|
|
5
5
|
type ProcessMessageContext = {
|
|
6
6
|
shouldProcessHistoryMsg: boolean;
|
|
7
|
+
placeholderResendCache?: CacheStore;
|
|
7
8
|
creds: AuthenticationCreds;
|
|
8
9
|
keyStore: SignalKeyStoreWithTransaction;
|
|
9
10
|
ev: BaileysEventEmitter;
|
|
@@ -37,5 +38,5 @@ type PollContext = {
|
|
|
37
38
|
* @returns list of SHA256 options
|
|
38
39
|
*/
|
|
39
40
|
export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }: PollContext): proto.Message.PollVoteMessage;
|
|
40
|
-
declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
|
|
41
|
+
declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
|
|
41
42
|
export default processMessage;
|
|
@@ -102,8 +102,8 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
exports.decryptPollVote = decryptPollVote;
|
|
105
|
-
const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }) => {
|
|
106
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
105
|
+
const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }) => {
|
|
106
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
107
107
|
const meId = creds.me.id;
|
|
108
108
|
const { accountSettings } = creds;
|
|
109
109
|
const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
|
|
@@ -137,14 +137,21 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
137
137
|
isLatest,
|
|
138
138
|
}, 'got history notification');
|
|
139
139
|
if (process) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
if (histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
141
|
+
ev.emit('creds.update', {
|
|
142
|
+
processedHistoryMessages: [
|
|
143
|
+
...(creds.processedHistoryMessages || []),
|
|
144
|
+
{ key: message.key, messageTimestamp: message.messageTimestamp }
|
|
145
|
+
]
|
|
146
|
+
});
|
|
147
|
+
}
|
|
146
148
|
const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
|
|
147
|
-
ev.emit('messaging-history.set', {
|
|
149
|
+
ev.emit('messaging-history.set', {
|
|
150
|
+
...data,
|
|
151
|
+
isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
|
|
152
|
+
? isLatest
|
|
153
|
+
: undefined
|
|
154
|
+
});
|
|
148
155
|
}
|
|
149
156
|
break;
|
|
150
157
|
case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
|
|
@@ -187,14 +194,21 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
187
194
|
case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
|
|
188
195
|
const response = protocolMsg.peerDataOperationRequestResponseMessage;
|
|
189
196
|
if (response) {
|
|
197
|
+
placeholderResendCache === null || placeholderResendCache === void 0 ? void 0 : placeholderResendCache.del(response.stanzaId);
|
|
198
|
+
// TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
|
|
190
199
|
const { peerDataOperationResult } = response;
|
|
191
200
|
for (const result of peerDataOperationResult) {
|
|
192
201
|
const { placeholderMessageResendResponse: retryResponse } = result;
|
|
193
202
|
if (retryResponse) {
|
|
194
203
|
const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
204
|
+
// wait till another upsert event is available, don't want it to be part of the PDO response message
|
|
205
|
+
setTimeout(() => {
|
|
206
|
+
ev.emit('messages.upsert', {
|
|
207
|
+
messages: [webMessageInfo],
|
|
208
|
+
type: 'notify',
|
|
209
|
+
requestId: response.stanzaId
|
|
210
|
+
});
|
|
211
|
+
}, 500);
|
|
198
212
|
}
|
|
199
213
|
}
|
|
200
214
|
}
|
|
@@ -208,11 +222,11 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
208
222
|
};
|
|
209
223
|
ev.emit('messages.reaction', [{
|
|
210
224
|
reaction,
|
|
211
|
-
key: content.reactionMessage.key,
|
|
225
|
+
key: (_d = content.reactionMessage) === null || _d === void 0 ? void 0 : _d.key,
|
|
212
226
|
}]);
|
|
213
227
|
}
|
|
214
228
|
else if (message.messageStubType) {
|
|
215
|
-
const jid = message.key.remoteJid;
|
|
229
|
+
const jid = (_e = message.key) === null || _e === void 0 ? void 0 : _e.remoteJid;
|
|
216
230
|
//let actor = whatsappID (message.participant)
|
|
217
231
|
let participants;
|
|
218
232
|
const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
|
|
@@ -256,39 +270,39 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
256
270
|
emitParticipantsUpdate('promote');
|
|
257
271
|
break;
|
|
258
272
|
case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
|
|
259
|
-
const announceValue = (
|
|
273
|
+
const announceValue = (_f = message.messageStubParameters) === null || _f === void 0 ? void 0 : _f[0];
|
|
260
274
|
emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
|
|
261
275
|
break;
|
|
262
276
|
case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
|
|
263
|
-
const restrictValue = (
|
|
277
|
+
const restrictValue = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
|
|
264
278
|
emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
|
|
265
279
|
break;
|
|
266
280
|
case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
|
|
267
|
-
const name = (
|
|
281
|
+
const name = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
|
|
268
282
|
chat.name = name;
|
|
269
283
|
emitGroupUpdate({ subject: name });
|
|
270
284
|
break;
|
|
271
285
|
case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
|
|
272
|
-
const description = (
|
|
286
|
+
const description = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
|
|
273
287
|
chat.description = description;
|
|
274
288
|
emitGroupUpdate({ desc: description });
|
|
275
289
|
break;
|
|
276
290
|
case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
|
|
277
|
-
const code = (
|
|
291
|
+
const code = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
|
|
278
292
|
emitGroupUpdate({ inviteCode: code });
|
|
279
293
|
break;
|
|
280
294
|
case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
|
|
281
|
-
const memberAddValue = (
|
|
295
|
+
const memberAddValue = (_l = message.messageStubParameters) === null || _l === void 0 ? void 0 : _l[0];
|
|
282
296
|
emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
|
|
283
297
|
break;
|
|
284
298
|
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
|
|
285
|
-
const approvalMode = (
|
|
299
|
+
const approvalMode = (_m = message.messageStubParameters) === null || _m === void 0 ? void 0 : _m[0];
|
|
286
300
|
emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
|
|
287
301
|
break;
|
|
288
302
|
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
|
|
289
|
-
const participant = (
|
|
290
|
-
const action = (
|
|
291
|
-
const method = (
|
|
303
|
+
const participant = (_o = message.messageStubParameters) === null || _o === void 0 ? void 0 : _o[0];
|
|
304
|
+
const action = (_p = message.messageStubParameters) === null || _p === void 0 ? void 0 : _p[1];
|
|
305
|
+
const method = (_q = message.messageStubParameters) === null || _q === void 0 ? void 0 : _q[2];
|
|
292
306
|
emitGroupRequestJoin(participant, action, method);
|
|
293
307
|
break;
|
|
294
308
|
}
|
|
@@ -301,7 +315,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
301
315
|
const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
|
|
302
316
|
const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
|
|
303
317
|
const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
|
|
304
|
-
const pollEncKey = (
|
|
318
|
+
const pollEncKey = (_r = pollMsg.messageContextInfo) === null || _r === void 0 ? void 0 : _r.messageSecret;
|
|
305
319
|
try {
|
|
306
320
|
const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
|
|
307
321
|
pollEncKey,
|
|
@@ -24,8 +24,8 @@ export declare const isLidUser: (jid: string | undefined) => boolean | undefined
|
|
|
24
24
|
export declare const isJidBroadcast: (jid: string | undefined) => boolean | undefined;
|
|
25
25
|
/** is the jid a group */
|
|
26
26
|
export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
|
|
27
|
-
/** is the jid a newsletter */
|
|
28
|
-
export declare const isJidNewsletter: (jid: string | undefined) => boolean | undefined;
|
|
29
27
|
/** is the jid the status broadcast */
|
|
30
28
|
export declare const isJidStatusBroadcast: (jid: string) => boolean;
|
|
29
|
+
/** is the jid a newsletter */
|
|
30
|
+
export declare const isJidNewsletter: (jid: string | undefined) => boolean | undefined;
|
|
31
31
|
export declare const jidNormalizedUser: (jid: string | undefined) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jidNormalizedUser = exports.
|
|
3
|
+
exports.jidNormalizedUser = exports.isJidNewsletter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
|
|
4
4
|
exports.S_WHATSAPP_NET = '@s.whatsapp.net';
|
|
5
5
|
exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
|
|
6
6
|
exports.SERVER_JID = 'server@c.us';
|
|
@@ -45,12 +45,12 @@ exports.isJidBroadcast = isJidBroadcast;
|
|
|
45
45
|
/** is the jid a group */
|
|
46
46
|
const isJidGroup = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@g.us'));
|
|
47
47
|
exports.isJidGroup = isJidGroup;
|
|
48
|
-
/** is the jid a newsletter */
|
|
49
|
-
const isJidNewsletter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@newsletter'));
|
|
50
|
-
exports.isJidNewsletter = isJidNewsletter;
|
|
51
48
|
/** is the jid the status broadcast */
|
|
52
49
|
const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
|
|
53
50
|
exports.isJidStatusBroadcast = isJidStatusBroadcast;
|
|
51
|
+
/** is the jid a newsletter */
|
|
52
|
+
const isJidNewsletter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@newsletter'));
|
|
53
|
+
exports.isJidNewsletter = isJidNewsletter;
|
|
54
54
|
const jidNormalizedUser = (jid) => {
|
|
55
55
|
const result = (0, exports.jidDecode)(jid);
|
|
56
56
|
if (!result) {
|