@d0v3riz/baileys 6.3.1 → 6.4.1
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/WAProto/WAProto.proto +58 -24
- package/WAProto/index.d.ts +649 -410
- package/WAProto/index.js +1632 -985
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +1 -1
- package/lib/Socket/Client/abstract-socket-client.d.ts +1 -0
- package/lib/Socket/Client/web-socket-client.d.ts +1 -1
- package/lib/Socket/Client/web-socket-client.js +1 -1
- package/lib/Socket/business.d.ts +4 -3
- package/lib/Socket/chats.d.ts +6 -5
- package/lib/Socket/groups.d.ts +3 -2
- package/lib/Socket/index.d.ts +9 -8
- package/lib/Socket/messages-recv.d.ts +5 -3
- package/lib/Socket/messages-recv.js +75 -2
- package/lib/Socket/messages-send.d.ts +3 -2
- package/lib/Socket/messages-send.js +13 -8
- package/lib/Socket/registration.d.ts +5 -4
- package/lib/Socket/socket.d.ts +4 -3
- package/lib/Socket/socket.js +69 -9
- package/lib/Store/make-in-memory-store.d.ts +2 -2
- package/lib/Types/Auth.d.ts +19 -17
- package/lib/Types/Call.d.ts +2 -2
- package/lib/Types/Chat.d.ts +13 -13
- package/lib/Types/Events.d.ts +3 -3
- package/lib/Types/GroupMetadata.d.ts +2 -2
- package/lib/Types/LabelAssociation.d.ts +2 -2
- package/lib/Types/Message.d.ts +57 -45
- package/lib/Types/Product.d.ts +14 -14
- package/lib/Types/Signal.d.ts +10 -10
- package/lib/Types/Socket.d.ts +5 -4
- package/lib/Types/State.d.ts +2 -2
- package/lib/Types/index.d.ts +5 -5
- package/lib/Utils/auth-utils.js +3 -1
- package/lib/Utils/chat-utils.d.ts +4 -4
- package/lib/Utils/crypto.d.ts +3 -0
- package/lib/Utils/crypto.js +15 -1
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +3 -3
- package/lib/Utils/generics.d.ts +7 -6
- package/lib/Utils/generics.js +25 -27
- package/lib/Utils/link-preview.d.ts +1 -1
- package/lib/Utils/link-preview.js +1 -24
- package/lib/Utils/make-mutex.d.ts +1 -1
- package/lib/Utils/messages-media.d.ts +9 -3
- package/lib/Utils/messages-media.js +54 -6
- package/lib/Utils/messages.d.ts +6 -5
- package/lib/Utils/messages.js +35 -1
- package/lib/Utils/process-message.d.ts +2 -2
- package/lib/Utils/validate-connection.js +1 -2
- package/lib/WABinary/jid-utils.d.ts +4 -4
- package/lib/WABinary/types.d.ts +4 -4
- package/lib/index.d.ts +1 -1
- package/package.json +8 -6
package/lib/Socket/socket.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeSocket = void 0;
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
4
|
const boom_1 = require("@hapi/boom");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
6
|
const url_1 = require("url");
|
|
7
7
|
const util_1 = require("util");
|
|
8
8
|
const WAProto_1 = require("../../WAProto");
|
|
9
9
|
const Defaults_1 = require("../Defaults");
|
|
10
10
|
const Types_1 = require("../Types");
|
|
11
11
|
const Utils_1 = require("../Utils");
|
|
12
|
-
const event_buffer_1 = require("../Utils/event-buffer");
|
|
13
12
|
const WABinary_1 = require("../WABinary");
|
|
14
13
|
const Client_1 = require("./Client");
|
|
15
14
|
/**
|
|
@@ -19,16 +18,15 @@ const Client_1 = require("./Client");
|
|
|
19
18
|
* - query phone connection
|
|
20
19
|
*/
|
|
21
20
|
const makeSocket = (config) => {
|
|
22
|
-
var _a, _b;
|
|
23
21
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
24
22
|
let url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
|
|
25
|
-
config.mobile = config.mobile ||
|
|
23
|
+
config.mobile = config.mobile || url.protocol === 'tcp:';
|
|
26
24
|
if (config.mobile && url.protocol !== 'tcp:') {
|
|
27
25
|
url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
|
|
28
26
|
}
|
|
29
27
|
const ws = config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
|
|
30
28
|
ws.connect();
|
|
31
|
-
const ev = (0,
|
|
29
|
+
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
32
30
|
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
33
31
|
const ephemeralKeyPair = Utils_1.Curve.generateKeyPair();
|
|
34
32
|
/** WA noise protocol wrapper */
|
|
@@ -106,15 +104,14 @@ const makeSocket = (config) => {
|
|
|
106
104
|
};
|
|
107
105
|
/**
|
|
108
106
|
* Wait for a message with a certain tag to be received
|
|
109
|
-
* @param
|
|
110
|
-
* @param json query that was sent
|
|
107
|
+
* @param msgId the message tag to await
|
|
111
108
|
* @param timeoutMs timeout after which the promise will reject
|
|
112
109
|
*/
|
|
113
110
|
const waitForMessage = async (msgId, timeoutMs = defaultQueryTimeoutMs) => {
|
|
114
111
|
let onRecv;
|
|
115
112
|
let onErr;
|
|
116
113
|
try {
|
|
117
|
-
|
|
114
|
+
return await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
|
118
115
|
onRecv = resolve;
|
|
119
116
|
onErr = err => {
|
|
120
117
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
@@ -123,7 +120,6 @@ const makeSocket = (config) => {
|
|
|
123
120
|
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
|
124
121
|
ws.off('error', onErr);
|
|
125
122
|
});
|
|
126
|
-
return result;
|
|
127
123
|
}
|
|
128
124
|
finally {
|
|
129
125
|
ws.off(`TAG:${msgId}`, onRecv);
|
|
@@ -364,6 +360,69 @@ const makeSocket = (config) => {
|
|
|
364
360
|
}
|
|
365
361
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
366
362
|
};
|
|
363
|
+
const requestPairingCode = async (phoneNumber) => {
|
|
364
|
+
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
365
|
+
authState.creds.me = {
|
|
366
|
+
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
367
|
+
name: '~'
|
|
368
|
+
};
|
|
369
|
+
ev.emit('creds.update', authState.creds);
|
|
370
|
+
await sendNode({
|
|
371
|
+
tag: 'iq',
|
|
372
|
+
attrs: {
|
|
373
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
374
|
+
type: 'set',
|
|
375
|
+
id: generateMessageTag(),
|
|
376
|
+
xmlns: 'md'
|
|
377
|
+
},
|
|
378
|
+
content: [
|
|
379
|
+
{
|
|
380
|
+
tag: 'link_code_companion_reg',
|
|
381
|
+
attrs: {
|
|
382
|
+
jid: authState.creds.me.id,
|
|
383
|
+
stage: 'companion_hello',
|
|
384
|
+
// eslint-disable-next-line camelcase
|
|
385
|
+
should_show_push_notification: 'true'
|
|
386
|
+
},
|
|
387
|
+
content: [
|
|
388
|
+
{
|
|
389
|
+
tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
|
|
390
|
+
attrs: {},
|
|
391
|
+
content: await generatePairingKey()
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
tag: 'companion_server_auth_key_pub',
|
|
395
|
+
attrs: {},
|
|
396
|
+
content: authState.creds.noiseKey.public
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
tag: 'companion_platform_id',
|
|
400
|
+
attrs: {},
|
|
401
|
+
content: '49' // Chrome
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
tag: 'companion_platform_display',
|
|
405
|
+
attrs: {},
|
|
406
|
+
content: config.browser[0]
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
tag: 'link_code_pairing_nonce',
|
|
410
|
+
attrs: {},
|
|
411
|
+
content: '0'
|
|
412
|
+
}
|
|
413
|
+
]
|
|
414
|
+
}
|
|
415
|
+
]
|
|
416
|
+
});
|
|
417
|
+
return authState.creds.pairingCode;
|
|
418
|
+
};
|
|
419
|
+
async function generatePairingKey() {
|
|
420
|
+
const salt = (0, crypto_1.randomBytes)(32);
|
|
421
|
+
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
422
|
+
const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
423
|
+
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
424
|
+
return Buffer.concat([salt, randomIv, ciphered]);
|
|
425
|
+
}
|
|
367
426
|
ws.on('message', onMessageRecieved);
|
|
368
427
|
ws.on('open', async () => {
|
|
369
428
|
try {
|
|
@@ -511,6 +570,7 @@ const makeSocket = (config) => {
|
|
|
511
570
|
onUnexpectedError,
|
|
512
571
|
uploadPreKeys,
|
|
513
572
|
uploadPreKeysToServerIfRequired,
|
|
573
|
+
requestPairingCode,
|
|
514
574
|
/** Waits for the connection to WA to reach a state */
|
|
515
575
|
waitForConnectionUpdate: (0, Utils_1.bindWaitForConnectionUpdate)(ev),
|
|
516
576
|
};
|
|
@@ -7,14 +7,14 @@ import type { BaileysEventEmitter, Chat, ConnectionState, Contact, GroupMetadata
|
|
|
7
7
|
import { Label } from '../Types/Label';
|
|
8
8
|
import { LabelAssociation } from '../Types/LabelAssociation';
|
|
9
9
|
import { ObjectRepository } from './object-repository';
|
|
10
|
-
|
|
10
|
+
type WASocket = ReturnType<typeof makeMDSocket>;
|
|
11
11
|
export declare const waChatKey: (pin: boolean) => {
|
|
12
12
|
key: (c: Chat) => string;
|
|
13
13
|
compare: (k1: string, k2: string) => number;
|
|
14
14
|
};
|
|
15
15
|
export declare const waMessageID: (m: WAMessage) => string;
|
|
16
16
|
export declare const waLabelAssociationKey: Comparable<LabelAssociation, string>;
|
|
17
|
-
export
|
|
17
|
+
export type BaileysInMemoryStoreConfig = {
|
|
18
18
|
chatKey?: Comparable<Chat, string>;
|
|
19
19
|
labelAssociationKey?: Comparable<LabelAssociation, string>;
|
|
20
20
|
logger?: Logger;
|
package/lib/Types/Auth.d.ts
CHANGED
|
@@ -3,25 +3,25 @@ import type { proto } from '../../WAProto';
|
|
|
3
3
|
import { RegistrationOptions } from '../Socket/registration';
|
|
4
4
|
import type { Contact } from './Contact';
|
|
5
5
|
import type { MinimalMessage } from './Message';
|
|
6
|
-
export
|
|
6
|
+
export type KeyPair = {
|
|
7
7
|
public: Uint8Array;
|
|
8
8
|
private: Uint8Array;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type SignedKeyPair = {
|
|
11
11
|
keyPair: KeyPair;
|
|
12
12
|
signature: Uint8Array;
|
|
13
13
|
keyId: number;
|
|
14
14
|
timestampS?: number;
|
|
15
15
|
};
|
|
16
|
-
export
|
|
16
|
+
export type ProtocolAddress = {
|
|
17
17
|
name: string;
|
|
18
18
|
deviceId: number;
|
|
19
19
|
};
|
|
20
|
-
export
|
|
20
|
+
export type SignalIdentity = {
|
|
21
21
|
identifier: ProtocolAddress;
|
|
22
22
|
identifierKey: Uint8Array;
|
|
23
23
|
};
|
|
24
|
-
export
|
|
24
|
+
export type LTHashState = {
|
|
25
25
|
version: number;
|
|
26
26
|
hash: Buffer;
|
|
27
27
|
indexValueMap: {
|
|
@@ -30,20 +30,21 @@ export declare type LTHashState = {
|
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
|
-
export
|
|
33
|
+
export type SignalCreds = {
|
|
34
34
|
readonly signedIdentityKey: KeyPair;
|
|
35
35
|
readonly signedPreKey: SignedKeyPair;
|
|
36
36
|
readonly registrationId: number;
|
|
37
37
|
};
|
|
38
|
-
export
|
|
38
|
+
export type AccountSettings = {
|
|
39
39
|
/** unarchive chats when a new message is received */
|
|
40
40
|
unarchiveChats: boolean;
|
|
41
41
|
/** the default mode to start new conversations with */
|
|
42
42
|
defaultDisappearingMode?: Pick<proto.IConversation, 'ephemeralExpiration' | 'ephemeralSettingTimestamp'>;
|
|
43
43
|
};
|
|
44
|
-
export
|
|
44
|
+
export type AuthenticationCreds = SignalCreds & {
|
|
45
45
|
readonly noiseKey: KeyPair;
|
|
46
|
-
readonly
|
|
46
|
+
readonly pairingEphemeralKeyPair: KeyPair;
|
|
47
|
+
advSecretKey: string;
|
|
47
48
|
me?: Contact;
|
|
48
49
|
account?: proto.IADVSignedDeviceIdentity;
|
|
49
50
|
signalIdentities?: SignalIdentity[];
|
|
@@ -62,8 +63,9 @@ export declare type AuthenticationCreds = SignalCreds & {
|
|
|
62
63
|
registered: boolean;
|
|
63
64
|
backupToken: Buffer;
|
|
64
65
|
registration: RegistrationOptions;
|
|
66
|
+
pairingCode: string | undefined;
|
|
65
67
|
};
|
|
66
|
-
export
|
|
68
|
+
export type SignalDataTypeMap = {
|
|
67
69
|
'pre-key': KeyPair;
|
|
68
70
|
'session': Uint8Array;
|
|
69
71
|
'sender-key': Uint8Array;
|
|
@@ -73,13 +75,13 @@ export declare type SignalDataTypeMap = {
|
|
|
73
75
|
'app-state-sync-key': proto.Message.IAppStateSyncKeyData;
|
|
74
76
|
'app-state-sync-version': LTHashState;
|
|
75
77
|
};
|
|
76
|
-
export
|
|
78
|
+
export type SignalDataSet = {
|
|
77
79
|
[T in keyof SignalDataTypeMap]?: {
|
|
78
80
|
[id: string]: SignalDataTypeMap[T] | null;
|
|
79
81
|
};
|
|
80
82
|
};
|
|
81
|
-
|
|
82
|
-
export
|
|
83
|
+
type Awaitable<T> = T | Promise<T>;
|
|
84
|
+
export type SignalKeyStore = {
|
|
83
85
|
get<T extends keyof SignalDataTypeMap>(type: T, ids: string[]): Awaitable<{
|
|
84
86
|
[id: string]: SignalDataTypeMap[T];
|
|
85
87
|
}>;
|
|
@@ -87,19 +89,19 @@ export declare type SignalKeyStore = {
|
|
|
87
89
|
/** clear all the data in the store */
|
|
88
90
|
clear?(): Awaitable<void>;
|
|
89
91
|
};
|
|
90
|
-
export
|
|
92
|
+
export type SignalKeyStoreWithTransaction = SignalKeyStore & {
|
|
91
93
|
isInTransaction: () => boolean;
|
|
92
94
|
transaction<T>(exec: () => Promise<T>): Promise<T>;
|
|
93
95
|
};
|
|
94
|
-
export
|
|
96
|
+
export type TransactionCapabilityOptions = {
|
|
95
97
|
maxCommitRetries: number;
|
|
96
98
|
delayBetweenTriesMs: number;
|
|
97
99
|
};
|
|
98
|
-
export
|
|
100
|
+
export type SignalAuthState = {
|
|
99
101
|
creds: SignalCreds;
|
|
100
102
|
keys: SignalKeyStore | SignalKeyStoreWithTransaction;
|
|
101
103
|
};
|
|
102
|
-
export
|
|
104
|
+
export type AuthenticationState = {
|
|
103
105
|
creds: AuthenticationCreds;
|
|
104
106
|
keys: SignalKeyStore;
|
|
105
107
|
};
|
package/lib/Types/Call.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export type WACallUpdateType = 'offer' | 'ringing' | 'timeout' | 'reject' | 'accept';
|
|
2
|
+
export type WACallEvent = {
|
|
3
3
|
chatId: string;
|
|
4
4
|
from: string;
|
|
5
5
|
isGroup?: boolean;
|
package/lib/Types/Chat.d.ts
CHANGED
|
@@ -5,33 +5,33 @@ import type { ChatLabelAssociationActionBody } from './LabelAssociation';
|
|
|
5
5
|
import type { MessageLabelAssociationActionBody } from './LabelAssociation';
|
|
6
6
|
import type { MinimalMessage } from './Message';
|
|
7
7
|
/** privacy settings in WhatsApp Web */
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
8
|
+
export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none';
|
|
9
|
+
export type WAPrivacyOnlineValue = 'all' | 'match_last_seen';
|
|
10
|
+
export type WAReadReceiptsValue = 'all' | 'none';
|
|
11
11
|
/** set of statuses visible to other people; see updatePresence() in WhatsAppWeb.Send */
|
|
12
|
-
export
|
|
12
|
+
export type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused';
|
|
13
13
|
export declare const ALL_WA_PATCH_NAMES: readonly ["critical_block", "critical_unblock_low", "regular_high", "regular_low", "regular"];
|
|
14
|
-
export
|
|
14
|
+
export type WAPatchName = typeof ALL_WA_PATCH_NAMES[number];
|
|
15
15
|
export interface PresenceData {
|
|
16
16
|
lastKnownPresence: WAPresence;
|
|
17
17
|
lastSeen?: number;
|
|
18
18
|
}
|
|
19
|
-
export
|
|
19
|
+
export type ChatMutation = {
|
|
20
20
|
syncAction: proto.ISyncActionData;
|
|
21
21
|
index: string[];
|
|
22
22
|
};
|
|
23
|
-
export
|
|
23
|
+
export type WAPatchCreate = {
|
|
24
24
|
syncAction: proto.ISyncActionValue;
|
|
25
25
|
index: string[];
|
|
26
26
|
type: WAPatchName;
|
|
27
27
|
apiVersion: number;
|
|
28
28
|
operation: proto.SyncdMutation.SyncdOperation;
|
|
29
29
|
};
|
|
30
|
-
export
|
|
30
|
+
export type Chat = proto.IConversation & {
|
|
31
31
|
/** unix timestamp of when the last message was received in the chat */
|
|
32
32
|
lastMessageRecvTimestamp?: number;
|
|
33
33
|
};
|
|
34
|
-
export
|
|
34
|
+
export type ChatUpdate = Partial<Chat & {
|
|
35
35
|
/**
|
|
36
36
|
* if specified in the update,
|
|
37
37
|
* the EV buffer will check if the condition gets fulfilled before applying the update
|
|
@@ -47,8 +47,8 @@ export declare type ChatUpdate = Partial<Chat & {
|
|
|
47
47
|
* the last messages in a chat, sorted reverse-chronologically. That is, the latest message should be first in the chat
|
|
48
48
|
* for MD modifications, the last message in the array (i.e. the earlist message) must be the last message recv in the chat
|
|
49
49
|
* */
|
|
50
|
-
export
|
|
51
|
-
export
|
|
50
|
+
export type LastMessageList = MinimalMessage[] | proto.SyncActionValue.ISyncActionMessageRange;
|
|
51
|
+
export type ChatModification = {
|
|
52
52
|
archive: boolean;
|
|
53
53
|
lastMessages: LastMessageList;
|
|
54
54
|
} | {
|
|
@@ -89,7 +89,7 @@ export declare type ChatModification = {
|
|
|
89
89
|
} | {
|
|
90
90
|
removeMessageLabel: MessageLabelAssociationActionBody;
|
|
91
91
|
};
|
|
92
|
-
export
|
|
92
|
+
export type InitialReceivedChatsState = {
|
|
93
93
|
[jid: string]: {
|
|
94
94
|
/** the last message received from the other party */
|
|
95
95
|
lastMsgRecvTimestamp?: number;
|
|
@@ -97,6 +97,6 @@ export declare type InitialReceivedChatsState = {
|
|
|
97
97
|
lastMsgTimestamp: number;
|
|
98
98
|
};
|
|
99
99
|
};
|
|
100
|
-
export
|
|
100
|
+
export type InitialAppStateSyncOptions = {
|
|
101
101
|
accountSettings: AccountSettings;
|
|
102
102
|
};
|
package/lib/Types/Events.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { Label } from './Label';
|
|
|
9
9
|
import { LabelAssociation } from './LabelAssociation';
|
|
10
10
|
import { MessageUpsertType, MessageUserReceiptUpdate, WAMessage, WAMessageKey, WAMessageUpdate } from './Message';
|
|
11
11
|
import { ConnectionState } from './State';
|
|
12
|
-
export
|
|
12
|
+
export type BaileysEventMap = {
|
|
13
13
|
/** connection state has been updated -- WS closed, opened, connecting etc. */
|
|
14
14
|
'connection.update': Partial<ConnectionState>;
|
|
15
15
|
/** credentials updated -- some metadata, keys or something */
|
|
@@ -88,7 +88,7 @@ export declare type BaileysEventMap = {
|
|
|
88
88
|
type: 'add' | 'remove';
|
|
89
89
|
};
|
|
90
90
|
};
|
|
91
|
-
export
|
|
91
|
+
export type BufferedEventData = {
|
|
92
92
|
historySets: {
|
|
93
93
|
chats: {
|
|
94
94
|
[jid: string]: Chat;
|
|
@@ -143,7 +143,7 @@ export declare type BufferedEventData = {
|
|
|
143
143
|
[jid: string]: Partial<GroupMetadata>;
|
|
144
144
|
};
|
|
145
145
|
};
|
|
146
|
-
export
|
|
146
|
+
export type BaileysEvent = keyof BaileysEventMap;
|
|
147
147
|
export interface BaileysEventEmitter {
|
|
148
148
|
on<T extends keyof BaileysEventMap>(event: T, listener: (arg: BaileysEventMap[T]) => void): void;
|
|
149
149
|
off<T extends keyof BaileysEventMap>(event: T, listener: (arg: BaileysEventMap[T]) => void): void;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Contact } from './Contact';
|
|
2
|
-
export
|
|
2
|
+
export type GroupParticipant = (Contact & {
|
|
3
3
|
isAdmin?: boolean;
|
|
4
4
|
isSuperAdmin?: boolean;
|
|
5
5
|
admin?: 'admin' | 'superadmin' | null;
|
|
6
6
|
});
|
|
7
|
-
export
|
|
7
|
+
export type ParticipantAction = 'add' | 'remove' | 'promote' | 'demote';
|
|
8
8
|
export interface GroupMetadata {
|
|
9
9
|
id: string;
|
|
10
10
|
owner: string | undefined;
|
|
@@ -3,7 +3,7 @@ export declare enum LabelAssociationType {
|
|
|
3
3
|
Chat = "label_jid",
|
|
4
4
|
Message = "label_message"
|
|
5
5
|
}
|
|
6
|
-
export
|
|
6
|
+
export type LabelAssociationTypes = `${LabelAssociationType}`;
|
|
7
7
|
/** Association for chat */
|
|
8
8
|
export interface ChatLabelAssociation {
|
|
9
9
|
type: LabelAssociationType.Chat;
|
|
@@ -17,7 +17,7 @@ export interface MessageLabelAssociation {
|
|
|
17
17
|
messageId: string;
|
|
18
18
|
labelId: string;
|
|
19
19
|
}
|
|
20
|
-
export
|
|
20
|
+
export type LabelAssociation = ChatLabelAssociation | MessageLabelAssociation;
|
|
21
21
|
/** Body for add/remove chat label association action */
|
|
22
22
|
export interface ChatLabelAssociationActionBody {
|
|
23
23
|
labelId: string;
|
package/lib/Types/Message.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
2
4
|
import { AxiosRequestConfig } from 'axios';
|
|
3
5
|
import type { Logger } from 'pino';
|
|
4
6
|
import type { Readable } from 'stream';
|
|
@@ -8,31 +10,31 @@ import { MEDIA_HKDF_KEY_MAPPING } from '../Defaults';
|
|
|
8
10
|
import type { GroupMetadata } from './GroupMetadata';
|
|
9
11
|
import { CacheStore } from './Socket';
|
|
10
12
|
export { proto as WAProto };
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
13
|
+
export type WAMessage = proto.IWebMessageInfo;
|
|
14
|
+
export type WAMessageContent = proto.IMessage;
|
|
15
|
+
export type WAContactMessage = proto.Message.IContactMessage;
|
|
16
|
+
export type WAContactsArrayMessage = proto.Message.IContactsArrayMessage;
|
|
17
|
+
export type WAMessageKey = proto.IMessageKey;
|
|
18
|
+
export type WATextMessage = proto.Message.IExtendedTextMessage;
|
|
19
|
+
export type WAContextInfo = proto.IContextInfo;
|
|
20
|
+
export type WALocationMessage = proto.Message.ILocationMessage;
|
|
21
|
+
export type WAGenericMediaMessage = proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
|
|
20
22
|
export import WAMessageStubType = proto.WebMessageInfo.StubType;
|
|
21
23
|
export import WAMessageStatus = proto.WebMessageInfo.Status;
|
|
22
|
-
export
|
|
24
|
+
export type WAMediaUpload = Buffer | {
|
|
23
25
|
url: URL | string;
|
|
24
26
|
} | {
|
|
25
27
|
stream: Readable;
|
|
26
28
|
};
|
|
27
29
|
/** Set of message types that are supported by the library */
|
|
28
|
-
export
|
|
29
|
-
export
|
|
30
|
+
export type MessageType = keyof proto.Message;
|
|
31
|
+
export type DownloadableMessage = {
|
|
30
32
|
mediaKey?: Uint8Array | null;
|
|
31
33
|
directPath?: string | null;
|
|
32
34
|
url?: string | null;
|
|
33
35
|
};
|
|
34
|
-
export
|
|
35
|
-
export
|
|
36
|
+
export type MessageReceiptType = 'read' | 'read-self' | 'hist_sync' | 'peer_msg' | 'sender' | 'inactive' | 'played' | undefined;
|
|
37
|
+
export type MediaConnInfo = {
|
|
36
38
|
auth: string;
|
|
37
39
|
ttl: number;
|
|
38
40
|
hosts: {
|
|
@@ -50,30 +52,30 @@ export interface WAUrlInfo {
|
|
|
50
52
|
highQualityThumbnail?: proto.Message.IImageMessage;
|
|
51
53
|
originalThumbnailUrl?: string;
|
|
52
54
|
}
|
|
53
|
-
|
|
55
|
+
type Mentionable = {
|
|
54
56
|
/** list of jids that are mentioned in the accompanying text */
|
|
55
57
|
mentions?: string[];
|
|
56
58
|
};
|
|
57
|
-
|
|
59
|
+
type Contextable = {
|
|
58
60
|
/** add contextInfo to the message */
|
|
59
61
|
contextInfo?: proto.IContextInfo;
|
|
60
62
|
};
|
|
61
|
-
|
|
63
|
+
type ViewOnce = {
|
|
62
64
|
viewOnce?: boolean;
|
|
63
65
|
};
|
|
64
|
-
|
|
66
|
+
type Buttonable = {
|
|
65
67
|
/** add buttons to the message */
|
|
66
68
|
buttons?: proto.Message.ButtonsMessage.IButton[];
|
|
67
69
|
};
|
|
68
|
-
|
|
70
|
+
type Templatable = {
|
|
69
71
|
/** add buttons to the message (conflicts with normal buttons)*/
|
|
70
72
|
templateButtons?: proto.IHydratedTemplateButton[];
|
|
71
73
|
footer?: string;
|
|
72
74
|
};
|
|
73
|
-
|
|
75
|
+
type Editable = {
|
|
74
76
|
edit?: WAMessageKey;
|
|
75
77
|
};
|
|
76
|
-
|
|
78
|
+
type Listable = {
|
|
77
79
|
/** Sections of the List */
|
|
78
80
|
sections?: proto.Message.ListMessage.ISection[];
|
|
79
81
|
/** Title of a List Message only */
|
|
@@ -81,19 +83,19 @@ declare type Listable = {
|
|
|
81
83
|
/** Text of the bnutton on the list (required) */
|
|
82
84
|
buttonText?: string;
|
|
83
85
|
};
|
|
84
|
-
|
|
86
|
+
type WithDimensions = {
|
|
85
87
|
width?: number;
|
|
86
88
|
height?: number;
|
|
87
89
|
};
|
|
88
|
-
export
|
|
90
|
+
export type PollMessageOptions = {
|
|
89
91
|
name: string;
|
|
90
92
|
selectableCount?: number;
|
|
91
93
|
values: string[];
|
|
92
94
|
/** 32 byte message secret to encrypt poll selections */
|
|
93
95
|
messageSecret?: Uint8Array;
|
|
94
96
|
};
|
|
95
|
-
export
|
|
96
|
-
export
|
|
97
|
+
export type MediaType = keyof typeof MEDIA_HKDF_KEY_MAPPING;
|
|
98
|
+
export type AnyMediaMessageContent = (({
|
|
97
99
|
image: WAMediaUpload;
|
|
98
100
|
caption?: string;
|
|
99
101
|
jpegThumbnail?: string;
|
|
@@ -119,15 +121,15 @@ export declare type AnyMediaMessageContent = (({
|
|
|
119
121
|
} & Contextable & Buttonable & Templatable)) & {
|
|
120
122
|
mimetype?: string;
|
|
121
123
|
} & Editable;
|
|
122
|
-
export
|
|
124
|
+
export type ButtonReplyInfo = {
|
|
123
125
|
displayText: string;
|
|
124
126
|
id: string;
|
|
125
127
|
index: number;
|
|
126
128
|
};
|
|
127
|
-
export
|
|
129
|
+
export type WASendableProduct = Omit<proto.Message.ProductMessage.IProductSnapshot, 'productImage'> & {
|
|
128
130
|
productImage: WAMediaUpload;
|
|
129
131
|
};
|
|
130
|
-
export
|
|
132
|
+
export type AnyRegularMessageContent = (({
|
|
131
133
|
text: string;
|
|
132
134
|
linkPreview?: WAUrlInfo | null;
|
|
133
135
|
} & Mentionable & Contextable & Buttonable & Templatable & Listable & Editable) | AnyMediaMessageContent | ({
|
|
@@ -152,7 +154,7 @@ export declare type AnyRegularMessageContent = (({
|
|
|
152
154
|
body?: string;
|
|
153
155
|
footer?: string;
|
|
154
156
|
}) & ViewOnce;
|
|
155
|
-
export
|
|
157
|
+
export type AnyMessageContent = AnyRegularMessageContent | {
|
|
156
158
|
forward: WAMessage;
|
|
157
159
|
force?: boolean;
|
|
158
160
|
} | {
|
|
@@ -161,14 +163,14 @@ export declare type AnyMessageContent = AnyRegularMessageContent | {
|
|
|
161
163
|
} | {
|
|
162
164
|
disappearingMessagesInChat: boolean | number;
|
|
163
165
|
};
|
|
164
|
-
export
|
|
165
|
-
|
|
166
|
+
export type GroupMetadataParticipants = Pick<GroupMetadata, 'participants'>;
|
|
167
|
+
type MinimalRelayOptions = {
|
|
166
168
|
/** override the message ID with a custom provided string */
|
|
167
169
|
messageId?: string;
|
|
168
170
|
/** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
|
|
169
171
|
cachedGroupMetadata?: (jid: string) => Promise<GroupMetadataParticipants | undefined>;
|
|
170
172
|
};
|
|
171
|
-
export
|
|
173
|
+
export type MessageRelayOptions = MinimalRelayOptions & {
|
|
172
174
|
/** only send to a specific participant; used when a message decryption fails for a single user */
|
|
173
175
|
participant?: {
|
|
174
176
|
jid: string;
|
|
@@ -180,8 +182,10 @@ export declare type MessageRelayOptions = MinimalRelayOptions & {
|
|
|
180
182
|
};
|
|
181
183
|
/** should we use the devices cache, or fetch afresh from the server; default assumed to be "true" */
|
|
182
184
|
useUserDevicesCache?: boolean;
|
|
185
|
+
/** jid list of participants for status@broadcast */
|
|
186
|
+
statusJidList?: string[];
|
|
183
187
|
};
|
|
184
|
-
export
|
|
188
|
+
export type MiscMessageGenerationOptions = MinimalRelayOptions & {
|
|
185
189
|
/** optional, if you want to manually set the timestamp of the message */
|
|
186
190
|
timestamp?: Date;
|
|
187
191
|
/** the message you want to quote */
|
|
@@ -192,11 +196,17 @@ export declare type MiscMessageGenerationOptions = MinimalRelayOptions & {
|
|
|
192
196
|
ephemeralExpiration?: number | string;
|
|
193
197
|
/** timeout for media upload to WA server */
|
|
194
198
|
mediaUploadTimeoutMs?: number;
|
|
199
|
+
/** jid list of participants for status@broadcast */
|
|
200
|
+
statusJidList?: string[];
|
|
201
|
+
/** backgroundcolor for status */
|
|
202
|
+
backgroundColor?: string;
|
|
203
|
+
/** font type for status */
|
|
204
|
+
font?: number;
|
|
195
205
|
};
|
|
196
|
-
export
|
|
206
|
+
export type MessageGenerationOptionsFromContent = MiscMessageGenerationOptions & {
|
|
197
207
|
userJid: string;
|
|
198
208
|
};
|
|
199
|
-
export
|
|
209
|
+
export type WAMediaUploadFunction = (readStream: Readable, opts: {
|
|
200
210
|
fileEncSha256B64: string;
|
|
201
211
|
mediaType: MediaType;
|
|
202
212
|
timeoutMs?: number;
|
|
@@ -204,7 +214,7 @@ export declare type WAMediaUploadFunction = (readStream: Readable, opts: {
|
|
|
204
214
|
mediaUrl: string;
|
|
205
215
|
directPath: string;
|
|
206
216
|
}>;
|
|
207
|
-
export
|
|
217
|
+
export type MediaGenerationOptions = {
|
|
208
218
|
logger?: Logger;
|
|
209
219
|
mediaTypeOverride?: MediaType;
|
|
210
220
|
upload: WAMediaUploadFunction;
|
|
@@ -212,34 +222,36 @@ export declare type MediaGenerationOptions = {
|
|
|
212
222
|
mediaCache?: CacheStore;
|
|
213
223
|
mediaUploadTimeoutMs?: number;
|
|
214
224
|
options?: AxiosRequestConfig;
|
|
225
|
+
backgroundColor?: string;
|
|
226
|
+
font?: number;
|
|
215
227
|
};
|
|
216
|
-
export
|
|
228
|
+
export type MessageContentGenerationOptions = MediaGenerationOptions & {
|
|
217
229
|
getUrlInfo?: (text: string) => Promise<WAUrlInfo | undefined>;
|
|
218
230
|
};
|
|
219
|
-
export
|
|
231
|
+
export type MessageGenerationOptions = MessageContentGenerationOptions & MessageGenerationOptionsFromContent;
|
|
220
232
|
/**
|
|
221
233
|
* Type of message upsert
|
|
222
234
|
* 1. notify => notify the user, this message was just received
|
|
223
235
|
* 2. append => append the message to the chat history, no notification required
|
|
224
236
|
*/
|
|
225
|
-
export
|
|
226
|
-
export
|
|
227
|
-
export
|
|
237
|
+
export type MessageUpsertType = 'append' | 'notify';
|
|
238
|
+
export type MessageUserReceipt = proto.IUserReceipt;
|
|
239
|
+
export type WAMessageUpdate = {
|
|
228
240
|
update: Partial<WAMessage>;
|
|
229
241
|
key: proto.IMessageKey;
|
|
230
242
|
};
|
|
231
|
-
export
|
|
243
|
+
export type WAMessageCursor = {
|
|
232
244
|
before: WAMessageKey | undefined;
|
|
233
245
|
} | {
|
|
234
246
|
after: WAMessageKey | undefined;
|
|
235
247
|
};
|
|
236
|
-
export
|
|
248
|
+
export type MessageUserReceiptUpdate = {
|
|
237
249
|
key: proto.IMessageKey;
|
|
238
250
|
receipt: MessageUserReceipt;
|
|
239
251
|
};
|
|
240
|
-
export
|
|
252
|
+
export type MediaDecryptionKeyInfo = {
|
|
241
253
|
iv: Buffer;
|
|
242
254
|
cipherKey: Buffer;
|
|
243
255
|
macKey?: Buffer;
|
|
244
256
|
};
|
|
245
|
-
export
|
|
257
|
+
export type MinimalMessage = Pick<proto.IWebMessageInfo, 'key' | 'messageTimestamp'>;
|