@queenanya/baileys 7.1.3 → 7.1.6
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 +13 -13
- package/lib/Defaults/index.js +4 -4
- package/lib/Socket/business.d.ts +29 -3
- package/lib/Socket/chats.d.ts +5 -0
- package/lib/Socket/chats.js +14 -0
- package/lib/Socket/groups.d.ts +7 -2
- package/lib/Socket/index.d.ts +29 -3
- package/lib/Socket/messages-recv.d.ts +30 -4
- package/lib/Socket/messages-recv.js +55 -2
- package/lib/Socket/messages-send.d.ts +27 -1
- package/lib/Socket/messages-send.js +54 -7
- package/lib/Socket/newsletter.d.ts +138 -0
- package/lib/Socket/newsletter.js +249 -0
- package/lib/Socket/registration.d.ts +29 -3
- package/lib/Socket/socket.js +2 -1
- package/lib/Types/Events.d.ts +27 -0
- package/lib/Types/Message.d.ts +15 -3
- package/lib/Types/Newsletter.d.ts +79 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/index.d.ts +2 -0
- package/lib/Types/index.js +1 -0
- package/lib/Utils/decode-wa-message.js +46 -18
- package/lib/Utils/generics.d.ts +11 -0
- package/lib/Utils/generics.js +17 -6
- package/lib/Utils/messages-media.d.ts +10 -1
- package/lib/Utils/messages-media.js +53 -4
- package/lib/Utils/messages.js +32 -11
- package/lib/Utils/signal.js +0 -5
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +3 -7
- package/lib/WABinary/jid-utils.d.ts +3 -1
- package/lib/WABinary/jid-utils.js +4 -1
- package/package.json +10 -8
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
This library was originally a project for **CS-2362 at Ashoka University** and is in no way affiliated with or endorsed by WhatsApp. Use at your own discretion. Do not spam people with this. We discourage any stalkerware, bulk or automated messaging usage.
|
|
6
6
|
|
|
7
7
|
#### Liability and License Notice
|
|
8
|
-
Baileys and its maintainers cannot be held liable for misuse of this application, as stated in the [MIT license](https://github.com/
|
|
8
|
+
Baileys and its maintainers cannot be held liable for misuse of this application, as stated in the [MIT license](https://github.com/queenanya/Baileys/blob/master/LICENSE).
|
|
9
9
|
The maintainers of Baileys do not in any way condone the use of this application in practices that violate the Terms of Service of WhatsApp. The maintainers of this application call upon the personal responsibility of its users to use this application in a fair way, as it is intended to be used.
|
|
10
10
|
##
|
|
11
11
|
|
|
@@ -33,17 +33,17 @@ To run the example script, download or clone the repo and then type the followin
|
|
|
33
33
|
|
|
34
34
|
Use the stable version:
|
|
35
35
|
```
|
|
36
|
-
yarn add @
|
|
36
|
+
yarn add @queenanya/baileys
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
Use the edge version (no guarantee of stability, but latest fixes + features)
|
|
40
40
|
```
|
|
41
|
-
yarn add github:
|
|
41
|
+
yarn add github:QueenAnya/Baileys
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
Then import your code using:
|
|
45
45
|
``` ts
|
|
46
|
-
import makeWASocket from '@
|
|
46
|
+
import makeWASocket from '@queenanya/baileys'
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
## Unit Tests
|
|
@@ -55,7 +55,7 @@ TODO
|
|
|
55
55
|
WhatsApp provides a multi-device API that allows Baileys to be authenticated as a second WhatsApp client by scanning a QR code with WhatsApp on your phone.
|
|
56
56
|
|
|
57
57
|
``` ts
|
|
58
|
-
import makeWASocket, { DisconnectReason } from '@
|
|
58
|
+
import makeWASocket, { DisconnectReason } from '@queenanya/baileys'
|
|
59
59
|
import { Boom } from '@hapi/boom'
|
|
60
60
|
|
|
61
61
|
async function connectToWhatsApp () {
|
|
@@ -193,7 +193,7 @@ You obviously don't want to keep scanning the QR code every time you want to con
|
|
|
193
193
|
|
|
194
194
|
So, you can load the credentials to log back in:
|
|
195
195
|
``` ts
|
|
196
|
-
import makeWASocket, { BufferJSON, useMultiFileAuthState } from '@
|
|
196
|
+
import makeWASocket, { BufferJSON, useMultiFileAuthState } from '@queenanya/baileys'
|
|
197
197
|
import * as fs from 'fs'
|
|
198
198
|
|
|
199
199
|
// utility function to help save the auth state in a single folder
|
|
@@ -308,7 +308,7 @@ Baileys does not come with a defacto storage for chats, contacts, or messages. H
|
|
|
308
308
|
It can be used as follows:
|
|
309
309
|
|
|
310
310
|
``` ts
|
|
311
|
-
import makeWASocket, { makeInMemoryStore } from '@
|
|
311
|
+
import makeWASocket, { makeInMemoryStore } from '@queenanya/baileys'
|
|
312
312
|
// the store maintains the data of the WA connection in memory
|
|
313
313
|
// can be written out to a file & read from it
|
|
314
314
|
const store = makeInMemoryStore({ })
|
|
@@ -324,13 +324,13 @@ const sock = makeWASocket({ })
|
|
|
324
324
|
// the store can listen from a new socket once the current socket outlives its lifetime
|
|
325
325
|
store.bind(sock.ev)
|
|
326
326
|
|
|
327
|
-
sock.ev.on('chats.
|
|
327
|
+
sock.ev.on('chats.set', () => {
|
|
328
328
|
// can use "store.chats" however you want, even after the socket dies out
|
|
329
329
|
// "chats" => a KeyedDB instance
|
|
330
330
|
console.log('got chats', store.chats.all())
|
|
331
331
|
})
|
|
332
332
|
|
|
333
|
-
sock.ev.on('contacts.
|
|
333
|
+
sock.ev.on('contacts.set', () => {
|
|
334
334
|
console.log('got contacts', Object.values(store.contacts))
|
|
335
335
|
})
|
|
336
336
|
|
|
@@ -347,7 +347,7 @@ The store also provides some simple functions such as `loadMessages` that utiliz
|
|
|
347
347
|
### Non-Media Messages
|
|
348
348
|
|
|
349
349
|
``` ts
|
|
350
|
-
import { MessageType, MessageOptions, Mimetype } from '@
|
|
350
|
+
import { MessageType, MessageOptions, Mimetype } from '@queenanya/baileys'
|
|
351
351
|
|
|
352
352
|
const id = 'abcd@s.whatsapp.net' // the WhatsApp ID
|
|
353
353
|
// send a simple text!
|
|
@@ -406,7 +406,7 @@ Sending media (video, stickers, images) is easier & more efficient than ever.
|
|
|
406
406
|
- When specifying a media url, Baileys never loads the entire buffer into memory; it even encrypts the media as a readable stream.
|
|
407
407
|
|
|
408
408
|
``` ts
|
|
409
|
-
import { MessageType, MessageOptions, Mimetype } from '@
|
|
409
|
+
import { MessageType, MessageOptions, Mimetype } from '@queenanya/baileys'
|
|
410
410
|
// Sending gifs
|
|
411
411
|
await sock.sendMessage(
|
|
412
412
|
id,
|
|
@@ -456,7 +456,7 @@ await sock.sendMessage(
|
|
|
456
456
|
Do not enter this field if you want to automatically generate a thumb
|
|
457
457
|
*/
|
|
458
458
|
mimetype: Mimetype.pdf, /* (for media messages) specify the type of media (optional for all media types except documents),
|
|
459
|
-
import {Mimetype} from '@
|
|
459
|
+
import {Mimetype} from '@queenanya/baileys'
|
|
460
460
|
*/
|
|
461
461
|
fileName: 'somefile.pdf', // (for media messages) file name for the media
|
|
462
462
|
/* will send audio messages as voice notes, if set to true */
|
|
@@ -515,7 +515,7 @@ The presence expires after about 10 seconds.
|
|
|
515
515
|
If you want to save the media you received
|
|
516
516
|
``` ts
|
|
517
517
|
import { writeFile } from 'fs/promises'
|
|
518
|
-
import { downloadMediaMessage } from '@
|
|
518
|
+
import { downloadMediaMessage } from '@queenanya/baileys'
|
|
519
519
|
|
|
520
520
|
sock.ev.on('messages.upsert', async ({ messages }) => {
|
|
521
521
|
const m = messages[0]
|
package/lib/Defaults/index.js
CHANGED
|
@@ -48,14 +48,14 @@ exports.PROCESSABLE_HISTORY_TYPES = [
|
|
|
48
48
|
];
|
|
49
49
|
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
50
50
|
version: baileys_version_json_1.version,
|
|
51
|
-
browser: Utils_1.Browsers.ubuntu('
|
|
51
|
+
browser: Utils_1.Browsers.ubuntu('Firefox'),
|
|
52
52
|
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
53
53
|
connectTimeoutMs: 20000,
|
|
54
54
|
keepAliveIntervalMs: 30000,
|
|
55
55
|
logger: logger_1.default.child({ class: 'baileys' }),
|
|
56
|
-
printQRInTerminal:
|
|
56
|
+
printQRInTerminal: true,
|
|
57
57
|
emitOwnEvents: true,
|
|
58
|
-
defaultQueryTimeoutMs:
|
|
58
|
+
defaultQueryTimeoutMs: undefined,
|
|
59
59
|
customUploadHosts: [],
|
|
60
60
|
retryRequestDelayMs: 250,
|
|
61
61
|
maxMsgRetryCount: 5,
|
|
@@ -68,7 +68,7 @@ exports.DEFAULT_CONNECTION_CONFIG = {
|
|
|
68
68
|
shouldIgnoreJid: () => false,
|
|
69
69
|
linkPreviewImageThumbnailWidth: 192,
|
|
70
70
|
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
|
|
71
|
-
generateHighQualityLinkPreview:
|
|
71
|
+
generateHighQualityLinkPreview: true,
|
|
72
72
|
options: {},
|
|
73
73
|
appStateMacVerification: {
|
|
74
74
|
patch: false,
|
package/lib/Socket/business.d.ts
CHANGED
|
@@ -23,11 +23,11 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
23
23
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
24
24
|
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
25
25
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
26
|
-
sendReceipts: (keys: import("../Types").
|
|
26
|
+
sendReceipts: (keys: import("../Types").WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
27
27
|
getButtonArgs: (message: import("../Types").WAProto.IMessage) => {
|
|
28
28
|
[key: string]: string;
|
|
29
29
|
};
|
|
30
|
-
readMessages: (keys: import("../Types").
|
|
30
|
+
readMessages: (keys: import("../Types").WAMessageKey[]) => Promise<void>;
|
|
31
31
|
refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
|
|
32
32
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
|
33
33
|
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
@@ -35,6 +35,27 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
35
35
|
}>;
|
|
36
36
|
updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
|
|
37
37
|
sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
|
|
38
|
+
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
39
|
+
duration: string;
|
|
40
|
+
}>;
|
|
41
|
+
newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
|
|
42
|
+
newsletterUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
|
|
43
|
+
newsletterUpdateName: (jid: string, name: string) => Promise<void>;
|
|
44
|
+
newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
|
45
|
+
newsletterRemovePicture: (jid: string) => Promise<void>;
|
|
46
|
+
newsletterUnfollow: (jid: string) => Promise<void>;
|
|
47
|
+
newsletterFollow: (jid: string) => Promise<void>;
|
|
48
|
+
newsletterUnmute: (jid: string) => Promise<void>;
|
|
49
|
+
newsletterMute: (jid: string) => Promise<void>;
|
|
50
|
+
newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
|
|
51
|
+
newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
|
|
52
|
+
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
53
|
+
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
|
54
|
+
newsletterDemote: (jid: string, user: string) => Promise<void>;
|
|
55
|
+
newsletterDelete: (jid: string) => Promise<void>;
|
|
56
|
+
newsletterReactMessage: (jid: string, server_id: string, code?: string | undefined) => Promise<void>;
|
|
57
|
+
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
|
58
|
+
newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
|
38
59
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
39
60
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
40
61
|
groupLeave: (id: string) => Promise<void>;
|
|
@@ -55,7 +76,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
55
76
|
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
|
56
77
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
57
78
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
58
|
-
groupAcceptInviteV4: (key: string | import("../Types").
|
|
79
|
+
groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
|
|
59
80
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
60
81
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
61
82
|
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
@@ -77,6 +98,11 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
77
98
|
jid: string;
|
|
78
99
|
}[]>;
|
|
79
100
|
fetchBlocklist: () => Promise<string[]>;
|
|
101
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<{
|
|
102
|
+
user: string;
|
|
103
|
+
duration: number;
|
|
104
|
+
setAt: Date;
|
|
105
|
+
}[]>;
|
|
80
106
|
fetchStatus: (jid: string) => Promise<{
|
|
81
107
|
status: string | undefined;
|
|
82
108
|
setAt: Date;
|
package/lib/Socket/chats.d.ts
CHANGED
|
@@ -20,6 +20,11 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
20
20
|
jid: string;
|
|
21
21
|
}[]>;
|
|
22
22
|
fetchBlocklist: () => Promise<string[]>;
|
|
23
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<{
|
|
24
|
+
user: string;
|
|
25
|
+
duration: number;
|
|
26
|
+
setAt: Date;
|
|
27
|
+
}[]>;
|
|
23
28
|
fetchStatus: (jid: string) => Promise<{
|
|
24
29
|
status: string | undefined;
|
|
25
30
|
setAt: Date;
|
package/lib/Socket/chats.js
CHANGED
|
@@ -173,6 +173,19 @@ const makeChatsSocket = (config) => {
|
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
175
|
};
|
|
176
|
+
/** Fetching The Disappearing Duration of a specific chats by their jids*/
|
|
177
|
+
const fetchDisappearingDuration = async (...jids) => {
|
|
178
|
+
const list = jids.map((jid) => ({ tag: 'user', attrs: { jid } }));
|
|
179
|
+
const results = await interactiveQuery(list, { tag: 'disappearing_mode', attrs: {} });
|
|
180
|
+
return results.map(item => {
|
|
181
|
+
const result = (0, WABinary_1.getBinaryNodeChild)(item, 'disappearing_mode');
|
|
182
|
+
return {
|
|
183
|
+
user: item.attrs.jid,
|
|
184
|
+
duration: parseInt(result === null || result === void 0 ? void 0 : result.attrs.duration),
|
|
185
|
+
setAt: new Date(+((result === null || result === void 0 ? void 0 : result.attrs.t) || 0) * 1000)
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
};
|
|
176
189
|
/** update the profile picture for yourself or a group */
|
|
177
190
|
const updateProfilePicture = async (jid, content) => {
|
|
178
191
|
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
@@ -815,6 +828,7 @@ const makeChatsSocket = (config) => {
|
|
|
815
828
|
profilePictureUrl,
|
|
816
829
|
onWhatsApp,
|
|
817
830
|
fetchBlocklist,
|
|
831
|
+
fetchDisappearingDuration,
|
|
818
832
|
fetchStatus,
|
|
819
833
|
updateProfilePicture,
|
|
820
834
|
removeProfilePicture,
|
package/lib/Socket/groups.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { proto } from '../../WAProto';
|
|
3
|
-
import { GroupMetadata, ParticipantAction, SocketConfig } from '../Types';
|
|
3
|
+
import { GroupMetadata, ParticipantAction, SocketConfig, WAMessageKey } from '../Types';
|
|
4
4
|
import { BinaryNode } from '../WABinary';
|
|
5
5
|
export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
6
6
|
groupMetadata: (jid: string) => Promise<GroupMetadata>;
|
|
@@ -28,7 +28,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
28
28
|
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
29
29
|
* @param inviteMessage the message to accept
|
|
30
30
|
*/
|
|
31
|
-
groupAcceptInviteV4: (key: string |
|
|
31
|
+
groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
|
|
32
32
|
groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
|
|
33
33
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
34
34
|
groupSettingUpdate: (jid: string, setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked') => Promise<void>;
|
|
@@ -53,6 +53,11 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
53
53
|
jid: string;
|
|
54
54
|
}[]>;
|
|
55
55
|
fetchBlocklist: () => Promise<string[]>;
|
|
56
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<{
|
|
57
|
+
user: string;
|
|
58
|
+
duration: number;
|
|
59
|
+
setAt: Date;
|
|
60
|
+
}[]>;
|
|
56
61
|
fetchStatus: (jid: string) => Promise<{
|
|
57
62
|
status: string | undefined;
|
|
58
63
|
setAt: Date;
|
package/lib/Socket/index.d.ts
CHANGED
|
@@ -24,11 +24,11 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
24
24
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
25
25
|
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
26
26
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
27
|
-
sendReceipts: (keys: import("../Types").
|
|
27
|
+
sendReceipts: (keys: import("../Types").WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
28
28
|
getButtonArgs: (message: import("../Types").WAProto.IMessage) => {
|
|
29
29
|
[key: string]: string;
|
|
30
30
|
};
|
|
31
|
-
readMessages: (keys: import("../Types").
|
|
31
|
+
readMessages: (keys: import("../Types").WAMessageKey[]) => Promise<void>;
|
|
32
32
|
refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
|
|
33
33
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
|
34
34
|
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
@@ -36,6 +36,27 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
36
36
|
}>;
|
|
37
37
|
updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
|
|
38
38
|
sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
|
|
39
|
+
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
40
|
+
duration: string;
|
|
41
|
+
}>;
|
|
42
|
+
newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
|
|
43
|
+
newsletterUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
|
|
44
|
+
newsletterUpdateName: (jid: string, name: string) => Promise<void>;
|
|
45
|
+
newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
|
46
|
+
newsletterRemovePicture: (jid: string) => Promise<void>;
|
|
47
|
+
newsletterUnfollow: (jid: string) => Promise<void>;
|
|
48
|
+
newsletterFollow: (jid: string) => Promise<void>;
|
|
49
|
+
newsletterUnmute: (jid: string) => Promise<void>;
|
|
50
|
+
newsletterMute: (jid: string) => Promise<void>;
|
|
51
|
+
newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
|
|
52
|
+
newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
|
|
53
|
+
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
54
|
+
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
|
55
|
+
newsletterDemote: (jid: string, user: string) => Promise<void>;
|
|
56
|
+
newsletterDelete: (jid: string) => Promise<void>;
|
|
57
|
+
newsletterReactMessage: (jid: string, server_id: string, code?: string | undefined) => Promise<void>;
|
|
58
|
+
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
|
59
|
+
newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
|
39
60
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
40
61
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
41
62
|
groupLeave: (id: string) => Promise<void>;
|
|
@@ -56,7 +77,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
56
77
|
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
|
57
78
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
58
79
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
59
|
-
groupAcceptInviteV4: (key: string | import("../Types").
|
|
80
|
+
groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
|
|
60
81
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
61
82
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
62
83
|
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
@@ -78,6 +99,11 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
78
99
|
jid: string;
|
|
79
100
|
}[]>;
|
|
80
101
|
fetchBlocklist: () => Promise<string[]>;
|
|
102
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<{
|
|
103
|
+
user: string;
|
|
104
|
+
duration: number;
|
|
105
|
+
setAt: Date;
|
|
106
|
+
}[]>;
|
|
81
107
|
fetchStatus: (jid: string) => Promise<{
|
|
82
108
|
status: string | undefined;
|
|
83
109
|
setAt: Date;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Boom } from '@hapi/boom';
|
|
3
3
|
import { proto } from '../../WAProto';
|
|
4
|
-
import { MessageReceiptType, MessageRelayOptions, SocketConfig } from '../Types';
|
|
4
|
+
import { MessageReceiptType, MessageRelayOptions, SocketConfig, WAMessageKey } from '../Types';
|
|
5
5
|
import { BinaryNode } from '../WABinary';
|
|
6
6
|
export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
7
7
|
sendMessageAck: ({ tag, attrs, content }: BinaryNode) => Promise<void>;
|
|
@@ -11,11 +11,11 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
11
11
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
12
12
|
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
|
|
13
13
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
|
|
14
|
-
sendReceipts: (keys:
|
|
14
|
+
sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
|
|
15
15
|
getButtonArgs: (message: proto.IMessage) => {
|
|
16
16
|
[key: string]: string;
|
|
17
17
|
};
|
|
18
|
-
readMessages: (keys:
|
|
18
|
+
readMessages: (keys: WAMessageKey[]) => Promise<void>;
|
|
19
19
|
refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
|
|
20
20
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
|
21
21
|
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
@@ -23,6 +23,27 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
23
23
|
}>;
|
|
24
24
|
updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
|
|
25
25
|
sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
|
|
26
|
+
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
27
|
+
duration: string;
|
|
28
|
+
}>;
|
|
29
|
+
newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
|
|
30
|
+
newsletterUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
|
|
31
|
+
newsletterUpdateName: (jid: string, name: string) => Promise<void>;
|
|
32
|
+
newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
|
33
|
+
newsletterRemovePicture: (jid: string) => Promise<void>;
|
|
34
|
+
newsletterUnfollow: (jid: string) => Promise<void>;
|
|
35
|
+
newsletterFollow: (jid: string) => Promise<void>;
|
|
36
|
+
newsletterUnmute: (jid: string) => Promise<void>;
|
|
37
|
+
newsletterMute: (jid: string) => Promise<void>;
|
|
38
|
+
newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
|
|
39
|
+
newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
|
|
40
|
+
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
41
|
+
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
|
42
|
+
newsletterDemote: (jid: string, user: string) => Promise<void>;
|
|
43
|
+
newsletterDelete: (jid: string) => Promise<void>;
|
|
44
|
+
newsletterReactMessage: (jid: string, server_id: string, code?: string | undefined) => Promise<void>;
|
|
45
|
+
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
|
46
|
+
newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
|
26
47
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
27
48
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
28
49
|
groupLeave: (id: string) => Promise<void>;
|
|
@@ -43,7 +64,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
43
64
|
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
|
44
65
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
45
66
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
46
|
-
groupAcceptInviteV4: (key: string |
|
|
67
|
+
groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
|
|
47
68
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
48
69
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
49
70
|
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
@@ -65,6 +86,11 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
65
86
|
jid: string;
|
|
66
87
|
}[]>;
|
|
67
88
|
fetchBlocklist: () => Promise<string[]>;
|
|
89
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<{
|
|
90
|
+
user: string;
|
|
91
|
+
duration: number;
|
|
92
|
+
setAt: Date;
|
|
93
|
+
}[]>;
|
|
68
94
|
fetchStatus: (jid: string) => Promise<{
|
|
69
95
|
status: string | undefined;
|
|
70
96
|
setAt: Date;
|
|
@@ -256,6 +256,50 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
256
256
|
break;
|
|
257
257
|
}
|
|
258
258
|
};
|
|
259
|
+
const handleNewsletterNotification = (id, node) => {
|
|
260
|
+
const messages = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
261
|
+
const message = (0, WABinary_1.getBinaryNodeChild)(messages, 'message');
|
|
262
|
+
const server_id = message.attrs.server_id;
|
|
263
|
+
const reactionsList = (0, WABinary_1.getBinaryNodeChild)(message, 'reactions');
|
|
264
|
+
const viewsList = (0, WABinary_1.getBinaryNodeChildren)(message, 'views_count');
|
|
265
|
+
if (reactionsList) {
|
|
266
|
+
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionsList, 'reaction');
|
|
267
|
+
if (reactions.length === 0) {
|
|
268
|
+
ev.emit('newsletter.reaction', { id, server_id, reaction: { removed: true } });
|
|
269
|
+
}
|
|
270
|
+
reactions.forEach(item => {
|
|
271
|
+
var _a, _b;
|
|
272
|
+
ev.emit('newsletter.reaction', { id, server_id, reaction: { code: (_a = item.attrs) === null || _a === void 0 ? void 0 : _a.code, count: +((_b = item.attrs) === null || _b === void 0 ? void 0 : _b.count) } });
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
if (viewsList.length) {
|
|
276
|
+
viewsList.forEach(item => {
|
|
277
|
+
ev.emit('newsletter.view', { id, server_id, count: +item.attrs.count });
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
const handleMexNewsletterNotification = (id, node) => {
|
|
282
|
+
var _a;
|
|
283
|
+
const operation = node === null || node === void 0 ? void 0 : node.attrs.op_name;
|
|
284
|
+
const content = JSON.parse((_a = node === null || node === void 0 ? void 0 : node.content) === null || _a === void 0 ? void 0 : _a.toString());
|
|
285
|
+
let contentPath;
|
|
286
|
+
if (operation === Types_1.MexOperations.PROMOTE || operation === Types_1.MexOperations.DEMOTE) {
|
|
287
|
+
let action;
|
|
288
|
+
if (operation === Types_1.MexOperations.PROMOTE) {
|
|
289
|
+
action = 'promote';
|
|
290
|
+
contentPath = content.data[Types_1.XWAPaths.PROMOTE];
|
|
291
|
+
}
|
|
292
|
+
if (operation === Types_1.MexOperations.DEMOTE) {
|
|
293
|
+
action = 'demote';
|
|
294
|
+
contentPath = content.data[Types_1.XWAPaths.DEMOTE];
|
|
295
|
+
}
|
|
296
|
+
ev.emit('newsletter-participants.update', { id, author: contentPath.actor.pn, user: contentPath.user.pn, new_role: contentPath.user_new_role, action });
|
|
297
|
+
}
|
|
298
|
+
if (operation === Types_1.MexOperations.UPDATE) {
|
|
299
|
+
contentPath = content.data[Types_1.XWAPaths.METADATA_UPDATE];
|
|
300
|
+
ev.emit('newsletter-settings.update', { id, update: contentPath.thread_metadata.settings });
|
|
301
|
+
}
|
|
302
|
+
};
|
|
259
303
|
const processNotification = async (node) => {
|
|
260
304
|
var _a, _b, _c;
|
|
261
305
|
const result = {};
|
|
@@ -276,6 +320,12 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
276
320
|
logger.debug({ jid }, 'got privacy token update');
|
|
277
321
|
}
|
|
278
322
|
break;
|
|
323
|
+
case 'newsletter':
|
|
324
|
+
handleNewsletterNotification(node.attrs.from, child);
|
|
325
|
+
break;
|
|
326
|
+
case 'mex':
|
|
327
|
+
handleMexNewsletterNotification(node.attrs.from, child);
|
|
328
|
+
break;
|
|
279
329
|
case 'w:gp2':
|
|
280
330
|
handleGroupNotification(node.attrs.participant, child, result);
|
|
281
331
|
break;
|
|
@@ -286,6 +336,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
286
336
|
case 'encrypt':
|
|
287
337
|
await handleEncryptNotification(node);
|
|
288
338
|
break;
|
|
339
|
+
case 'newsletter':
|
|
340
|
+
// TO DO
|
|
341
|
+
break;
|
|
289
342
|
case 'devices':
|
|
290
343
|
const devices = (0, WABinary_1.getBinaryNodeChildren)(child, 'device');
|
|
291
344
|
if ((0, WABinary_1.areJidsSameUser)(child.attrs.jid, authState.creds.me.id)) {
|
|
@@ -304,7 +357,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
304
357
|
const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
|
|
305
358
|
const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
|
|
306
359
|
ev.emit('contacts.update', [{
|
|
307
|
-
id: (0, WABinary_1.jidNormalizedUser)((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.jid) || ((_c = (_b = (setPicture || delPicture)) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.hash) || '',
|
|
360
|
+
id: (0, WABinary_1.jidNormalizedUser)((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.jid) || from || ((_c = (_b = (setPicture || delPicture)) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.hash) || '',
|
|
308
361
|
imgUrl: setPicture ? 'changed' : 'removed'
|
|
309
362
|
}]);
|
|
310
363
|
if ((0, WABinary_1.isJidGroup)(from)) {
|
|
@@ -667,7 +720,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
667
720
|
await sendMessageAck(node);
|
|
668
721
|
};
|
|
669
722
|
const handleBadAck = async ({ attrs }) => {
|
|
670
|
-
const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id };
|
|
723
|
+
const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id, server_id: attrs === null || attrs === void 0 ? void 0 : attrs.server_id };
|
|
671
724
|
// current hypothesis is that if pash is sent in the ack
|
|
672
725
|
// it means -- the message hasn't reached all devices yet
|
|
673
726
|
// we'll retry sending the message here
|
|
@@ -18,6 +18,27 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
18
18
|
}>;
|
|
19
19
|
updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
|
|
20
20
|
sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
|
|
21
|
+
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
22
|
+
duration: string;
|
|
23
|
+
}>;
|
|
24
|
+
newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
|
|
25
|
+
newsletterUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
|
|
26
|
+
newsletterUpdateName: (jid: string, name: string) => Promise<void>;
|
|
27
|
+
newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
|
28
|
+
newsletterRemovePicture: (jid: string) => Promise<void>;
|
|
29
|
+
newsletterUnfollow: (jid: string) => Promise<void>;
|
|
30
|
+
newsletterFollow: (jid: string) => Promise<void>;
|
|
31
|
+
newsletterUnmute: (jid: string) => Promise<void>;
|
|
32
|
+
newsletterMute: (jid: string) => Promise<void>;
|
|
33
|
+
newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
|
|
34
|
+
newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
|
|
35
|
+
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
36
|
+
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
|
37
|
+
newsletterDemote: (jid: string, user: string) => Promise<void>;
|
|
38
|
+
newsletterDelete: (jid: string) => Promise<void>;
|
|
39
|
+
newsletterReactMessage: (jid: string, server_id: string, code?: string | undefined) => Promise<void>;
|
|
40
|
+
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
|
41
|
+
newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
|
21
42
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
22
43
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
23
44
|
groupLeave: (id: string) => Promise<void>;
|
|
@@ -38,7 +59,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
38
59
|
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
|
39
60
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
40
61
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
41
|
-
groupAcceptInviteV4: (key: string |
|
|
62
|
+
groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
|
|
42
63
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
43
64
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
44
65
|
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
@@ -60,6 +81,11 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
60
81
|
jid: string;
|
|
61
82
|
}[]>;
|
|
62
83
|
fetchBlocklist: () => Promise<string[]>;
|
|
84
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<{
|
|
85
|
+
user: string;
|
|
86
|
+
duration: number;
|
|
87
|
+
setAt: Date;
|
|
88
|
+
}[]>;
|
|
63
89
|
fetchStatus: (jid: string) => Promise<{
|
|
64
90
|
status: string | undefined;
|
|
65
91
|
setAt: Date;
|