@d0v3riz/baileys 6.7.21 → 6.7.22
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/GenerateStatics.sh +2 -3
- package/WAProto/index.js +4138 -4136
- package/lib/Defaults/index.d.ts +2 -3
- package/lib/Defaults/index.js +40 -36
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
- package/lib/Signal/Group/ciphertext-message.js +5 -2
- package/lib/Signal/Group/group-session-builder.d.ts +3 -4
- package/lib/Signal/Group/group-session-builder.js +41 -7
- package/lib/Signal/Group/group_cipher.d.ts +2 -3
- package/lib/Signal/Group/group_cipher.js +16 -14
- package/lib/Signal/Group/index.d.ts +11 -12
- package/lib/Signal/Group/index.js +57 -12
- package/lib/Signal/Group/keyhelper.d.ts +1 -2
- package/lib/Signal/Group/keyhelper.js +44 -8
- package/lib/Signal/Group/queue-job.d.ts +0 -2
- package/lib/Signal/Group/queue-job.js +5 -5
- package/lib/Signal/Group/sender-chain-key.d.ts +1 -2
- package/lib/Signal/Group/sender-chain-key.js +9 -7
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +9 -6
- package/lib/Signal/Group/sender-key-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-message.js +12 -10
- package/lib/Signal/Group/sender-key-name.d.ts +0 -1
- package/lib/Signal/Group/sender-key-name.js +5 -2
- package/lib/Signal/Group/sender-key-record.d.ts +1 -2
- package/lib/Signal/Group/sender-key-record.js +12 -9
- package/lib/Signal/Group/sender-key-state.d.ts +2 -3
- package/lib/Signal/Group/sender-key-state.js +9 -6
- package/lib/Signal/Group/sender-message-key.d.ts +0 -1
- package/lib/Signal/Group/sender-message-key.js +7 -5
- package/lib/Signal/libsignal.d.ts +2 -3
- package/lib/Signal/libsignal.js +55 -22
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +18 -3
- package/lib/Socket/Client/types.d.ts +1 -2
- package/lib/Socket/Client/types.js +6 -4
- package/lib/Socket/Client/websocket.d.ts +1 -2
- package/lib/Socket/Client/websocket.js +26 -14
- package/lib/Socket/business.d.ts +64 -66
- package/lib/Socket/business.js +37 -32
- package/lib/Socket/chats.d.ts +19 -21
- package/lib/Socket/chats.js +141 -176
- package/lib/Socket/groups.d.ts +35 -37
- package/lib/Socket/groups.js +63 -56
- package/lib/Socket/index.d.ts +70 -102
- package/lib/Socket/index.js +9 -16
- package/lib/Socket/messages-recv.d.ts +49 -51
- package/lib/Socket/messages-recv.js +173 -180
- package/lib/Socket/messages-send.d.ts +46 -48
- package/lib/Socket/messages-send.js +84 -75
- package/lib/Socket/mex.d.ts +1 -2
- package/lib/Socket/mex.js +16 -12
- package/lib/Socket/newsletter.d.ts +44 -46
- package/lib/Socket/newsletter.js +27 -23
- package/lib/Socket/socket.d.ts +12 -13
- package/lib/Socket/socket.js +115 -135
- package/lib/Socket/usync.d.ts +14 -15
- package/lib/Socket/usync.js +11 -9
- package/lib/Types/Auth.d.ts +3 -4
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +0 -1
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +7 -10
- package/lib/Types/Chat.js +4 -2
- package/lib/Types/Contact.d.ts +0 -1
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +10 -11
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +2 -3
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +0 -1
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.d.ts +0 -1
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.d.ts +7 -9
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.d.ts +0 -1
- package/lib/Types/Newsletter.js +7 -5
- package/lib/Types/Product.d.ts +1 -2
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +1 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +7 -8
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.d.ts +2 -14
- package/lib/Types/State.js +2 -13
- package/lib/Types/USync.d.ts +2 -3
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.d.ts +14 -15
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.d.ts +2 -3
- package/lib/Utils/auth-utils.js +34 -25
- package/lib/Utils/baileys-event-stream.d.ts +1 -2
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.d.ts +2 -3
- package/lib/Utils/business.js +70 -61
- package/lib/Utils/chat-utils.d.ts +7 -8
- package/lib/Utils/chat-utils.js +137 -130
- package/lib/Utils/crypto.d.ts +1 -2
- package/lib/Utils/crypto.js +86 -37
- package/lib/Utils/decode-wa-message.d.ts +4 -5
- package/lib/Utils/decode-wa-message.js +44 -38
- package/lib/Utils/event-buffer.d.ts +4 -4
- package/lib/Utils/event-buffer.js +50 -37
- package/lib/Utils/generics.d.ts +8 -9
- package/lib/Utils/generics.js +114 -87
- package/lib/Utils/history.d.ts +3 -4
- package/lib/Utils/history.js +40 -32
- package/lib/Utils/index.d.ts +17 -18
- package/lib/Utils/index.js +33 -18
- package/lib/Utils/link-preview.d.ts +3 -4
- package/lib/Utils/link-preview.js +47 -10
- package/lib/Utils/logger.d.ts +6 -8
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +8 -9
- package/lib/Utils/lt-hash.js +26 -23
- package/lib/Utils/make-mutex.d.ts +0 -1
- package/lib/Utils/make-mutex.js +9 -5
- package/lib/Utils/messages-media.d.ts +10 -11
- package/lib/Utils/messages-media.js +203 -141
- package/lib/Utils/messages.d.ts +6 -7
- package/lib/Utils/messages.js +199 -190
- package/lib/Utils/noise-handler.d.ts +4 -5
- package/lib/Utils/noise-handler.js +26 -22
- package/lib/Utils/process-message.d.ts +4 -5
- package/lib/Utils/process-message.js +104 -95
- package/lib/Utils/signal.d.ts +4 -5
- package/lib/Utils/signal.js +52 -47
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
- package/lib/Utils/use-multi-file-auth-state.js +26 -23
- package/lib/Utils/validate-connection.d.ts +3 -4
- package/lib/Utils/validate-connection.js +58 -52
- package/lib/WABinary/constants.d.ts +0 -1
- package/lib/WABinary/constants.js +11 -9
- package/lib/WABinary/decode.d.ts +1 -2
- package/lib/WABinary/decode.js +51 -13
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +41 -5
- package/lib/WABinary/generic-utils.d.ts +3 -4
- package/lib/WABinary/generic-utils.js +38 -30
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.d.ts +0 -1
- package/lib/WABinary/jid-utils.js +35 -21
- package/lib/WABinary/types.d.ts +1 -2
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +1 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.d.ts +0 -1
- package/lib/WAM/constants.js +6 -4
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAM/encode.js +14 -12
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +9 -6
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -6
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +11 -7
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +21 -19
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +5 -2
- package/lib/WAUSync/Protocols/index.d.ts +4 -5
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.d.ts +3 -4
- package/lib/WAUSync/USyncQuery.js +20 -18
- package/lib/WAUSync/USyncUser.d.ts +5 -6
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.d.ts +8 -9
- package/lib/index.js +30 -11
- package/package.json +26 -26
- package/WAProto/fix-imports.js +0 -29
- package/lib/Defaults/index.d.ts.map +0 -1
- package/lib/Defaults/index.js.map +0 -1
- package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
- package/lib/Signal/Group/ciphertext-message.js.map +0 -1
- package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
- package/lib/Signal/Group/group-session-builder.js.map +0 -1
- package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
- package/lib/Signal/Group/group_cipher.js.map +0 -1
- package/lib/Signal/Group/index.d.ts.map +0 -1
- package/lib/Signal/Group/index.js.map +0 -1
- package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
- package/lib/Signal/Group/keyhelper.js.map +0 -1
- package/lib/Signal/Group/queue-job.d.ts.map +0 -1
- package/lib/Signal/Group/queue-job.js.map +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-chain-key.js.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-name.js.map +0 -1
- package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-record.js.map +0 -1
- package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-state.js.map +0 -1
- package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-message-key.js.map +0 -1
- package/lib/Signal/libsignal.d.ts.map +0 -1
- package/lib/Signal/libsignal.js.map +0 -1
- package/lib/Socket/Client/index.d.ts.map +0 -1
- package/lib/Socket/Client/index.js.map +0 -1
- package/lib/Socket/Client/types.d.ts.map +0 -1
- package/lib/Socket/Client/types.js.map +0 -1
- package/lib/Socket/Client/websocket.d.ts.map +0 -1
- package/lib/Socket/Client/websocket.js.map +0 -1
- package/lib/Socket/business.d.ts.map +0 -1
- package/lib/Socket/business.js.map +0 -1
- package/lib/Socket/chats.d.ts.map +0 -1
- package/lib/Socket/chats.js.map +0 -1
- package/lib/Socket/communities.d.ts +0 -219
- package/lib/Socket/communities.d.ts.map +0 -1
- package/lib/Socket/communities.js +0 -351
- package/lib/Socket/communities.js.map +0 -1
- package/lib/Socket/groups.d.ts.map +0 -1
- package/lib/Socket/groups.js.map +0 -1
- package/lib/Socket/index.d.ts.map +0 -1
- package/lib/Socket/index.js.map +0 -1
- package/lib/Socket/messages-recv.d.ts.map +0 -1
- package/lib/Socket/messages-recv.js.map +0 -1
- package/lib/Socket/messages-send.d.ts.map +0 -1
- package/lib/Socket/messages-send.js.map +0 -1
- package/lib/Socket/mex.d.ts.map +0 -1
- package/lib/Socket/mex.js.map +0 -1
- package/lib/Socket/newsletter.d.ts.map +0 -1
- package/lib/Socket/newsletter.js.map +0 -1
- package/lib/Socket/socket.d.ts.map +0 -1
- package/lib/Socket/socket.js.map +0 -1
- package/lib/Socket/usync.d.ts.map +0 -1
- package/lib/Socket/usync.js.map +0 -1
- package/lib/Types/Auth.d.ts.map +0 -1
- package/lib/Types/Auth.js.map +0 -1
- package/lib/Types/Call.d.ts.map +0 -1
- package/lib/Types/Call.js.map +0 -1
- package/lib/Types/Chat.d.ts.map +0 -1
- package/lib/Types/Chat.js.map +0 -1
- package/lib/Types/Contact.d.ts.map +0 -1
- package/lib/Types/Contact.js.map +0 -1
- package/lib/Types/Events.d.ts.map +0 -1
- package/lib/Types/Events.js.map +0 -1
- package/lib/Types/GroupMetadata.d.ts.map +0 -1
- package/lib/Types/GroupMetadata.js.map +0 -1
- package/lib/Types/Label.d.ts.map +0 -1
- package/lib/Types/Label.js.map +0 -1
- package/lib/Types/LabelAssociation.d.ts.map +0 -1
- package/lib/Types/LabelAssociation.js.map +0 -1
- package/lib/Types/Message.d.ts.map +0 -1
- package/lib/Types/Message.js.map +0 -1
- package/lib/Types/Newsletter.d.ts.map +0 -1
- package/lib/Types/Newsletter.js.map +0 -1
- package/lib/Types/Product.d.ts.map +0 -1
- package/lib/Types/Product.js.map +0 -1
- package/lib/Types/Signal.d.ts.map +0 -1
- package/lib/Types/Signal.js.map +0 -1
- package/lib/Types/Socket.d.ts.map +0 -1
- package/lib/Types/Socket.js.map +0 -1
- package/lib/Types/State.d.ts.map +0 -1
- package/lib/Types/State.js.map +0 -1
- package/lib/Types/USync.d.ts.map +0 -1
- package/lib/Types/USync.js.map +0 -1
- package/lib/Types/index.d.ts.map +0 -1
- package/lib/Types/index.js.map +0 -1
- package/lib/Utils/auth-utils.d.ts.map +0 -1
- package/lib/Utils/auth-utils.js.map +0 -1
- package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
- package/lib/Utils/baileys-event-stream.js.map +0 -1
- package/lib/Utils/business.d.ts.map +0 -1
- package/lib/Utils/business.js.map +0 -1
- package/lib/Utils/chat-utils.d.ts.map +0 -1
- package/lib/Utils/chat-utils.js.map +0 -1
- package/lib/Utils/crypto.d.ts.map +0 -1
- package/lib/Utils/crypto.js.map +0 -1
- package/lib/Utils/decode-wa-message.d.ts.map +0 -1
- package/lib/Utils/decode-wa-message.js.map +0 -1
- package/lib/Utils/event-buffer.d.ts.map +0 -1
- package/lib/Utils/event-buffer.js.map +0 -1
- package/lib/Utils/generics.d.ts.map +0 -1
- package/lib/Utils/generics.js.map +0 -1
- package/lib/Utils/history.d.ts.map +0 -1
- package/lib/Utils/history.js.map +0 -1
- package/lib/Utils/index.d.ts.map +0 -1
- package/lib/Utils/index.js.map +0 -1
- package/lib/Utils/link-preview.d.ts.map +0 -1
- package/lib/Utils/link-preview.js.map +0 -1
- package/lib/Utils/logger.d.ts.map +0 -1
- package/lib/Utils/logger.js.map +0 -1
- package/lib/Utils/lt-hash.d.ts.map +0 -1
- package/lib/Utils/lt-hash.js.map +0 -1
- package/lib/Utils/make-mutex.d.ts.map +0 -1
- package/lib/Utils/make-mutex.js.map +0 -1
- package/lib/Utils/messages-media.d.ts.map +0 -1
- package/lib/Utils/messages-media.js.map +0 -1
- package/lib/Utils/messages.d.ts.map +0 -1
- package/lib/Utils/messages.js.map +0 -1
- package/lib/Utils/noise-handler.d.ts.map +0 -1
- package/lib/Utils/noise-handler.js.map +0 -1
- package/lib/Utils/process-message.d.ts.map +0 -1
- package/lib/Utils/process-message.js.map +0 -1
- package/lib/Utils/signal.d.ts.map +0 -1
- package/lib/Utils/signal.js.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
- package/lib/Utils/validate-connection.d.ts.map +0 -1
- package/lib/Utils/validate-connection.js.map +0 -1
- package/lib/WABinary/constants.d.ts.map +0 -1
- package/lib/WABinary/constants.js.map +0 -1
- package/lib/WABinary/decode.d.ts.map +0 -1
- package/lib/WABinary/decode.js.map +0 -1
- package/lib/WABinary/encode.d.ts.map +0 -1
- package/lib/WABinary/encode.js.map +0 -1
- package/lib/WABinary/generic-utils.d.ts.map +0 -1
- package/lib/WABinary/generic-utils.js.map +0 -1
- package/lib/WABinary/index.d.ts.map +0 -1
- package/lib/WABinary/index.js.map +0 -1
- package/lib/WABinary/jid-utils.d.ts.map +0 -1
- package/lib/WABinary/jid-utils.js.map +0 -1
- package/lib/WABinary/types.d.ts.map +0 -1
- package/lib/WABinary/types.js.map +0 -1
- package/lib/WAM/BinaryInfo.d.ts.map +0 -1
- package/lib/WAM/BinaryInfo.js.map +0 -1
- package/lib/WAM/constants.d.ts.map +0 -1
- package/lib/WAM/constants.js.map +0 -1
- package/lib/WAM/encode.d.ts.map +0 -1
- package/lib/WAM/encode.js.map +0 -1
- package/lib/WAM/index.d.ts.map +0 -1
- package/lib/WAM/index.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/index.js.map +0 -1
- package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
- package/lib/WAUSync/USyncQuery.js.map +0 -1
- package/lib/WAUSync/USyncUser.d.ts.map +0 -1
- package/lib/WAUSync/USyncUser.js.map +0 -1
- package/lib/WAUSync/index.d.ts.map +0 -1
- package/lib/WAUSync/index.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
package/lib/Utils/generics.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { proto } from '../../WAProto
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { proto } from '../../WAProto';
|
|
3
|
+
import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, WACallUpdateType, WAVersion } from '../Types';
|
|
4
|
+
import { BinaryNode } from '../WABinary';
|
|
5
5
|
export declare const Browsers: BrowsersMap;
|
|
6
|
-
export declare const getPlatformId: (browser: string) =>
|
|
6
|
+
export declare const getPlatformId: (browser: string) => any;
|
|
7
7
|
export declare const BufferJSON: {
|
|
8
8
|
replacer: (k: any, value: any) => any;
|
|
9
9
|
reviver: (_: any, value: any) => any;
|
|
@@ -45,7 +45,7 @@ export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<{}
|
|
|
45
45
|
} | {
|
|
46
46
|
version: WAVersion;
|
|
47
47
|
isLatest: boolean;
|
|
48
|
-
error:
|
|
48
|
+
error: any;
|
|
49
49
|
}>;
|
|
50
50
|
/**
|
|
51
51
|
* A utility that fetches the latest web version of whatsapp.
|
|
@@ -58,7 +58,7 @@ export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<{}>)
|
|
|
58
58
|
} | {
|
|
59
59
|
version: WAVersion;
|
|
60
60
|
isLatest: boolean;
|
|
61
|
-
error:
|
|
61
|
+
error: any;
|
|
62
62
|
}>;
|
|
63
63
|
/** unique message tag prefix for MD clients */
|
|
64
64
|
export declare const generateMdTagPrefix: () => string;
|
|
@@ -66,7 +66,7 @@ export declare const generateMdTagPrefix: () => string;
|
|
|
66
66
|
* Given a type of receipt, returns what the new status of the message should be
|
|
67
67
|
* @param type type from receipt
|
|
68
68
|
*/
|
|
69
|
-
export declare const getStatusFromReceiptType: (type: string | undefined) => proto.WebMessageInfo.Status
|
|
69
|
+
export declare const getStatusFromReceiptType: (type: string | undefined) => proto.WebMessageInfo.Status;
|
|
70
70
|
/**
|
|
71
71
|
* Stream errors generally provide a reason, map that to a baileys DisconnectReason
|
|
72
72
|
* @param reason the string reason given, eg. "conflict"
|
|
@@ -89,4 +89,3 @@ export declare function trimUndefined(obj: {
|
|
|
89
89
|
};
|
|
90
90
|
export declare function bytesToCrockford(buffer: Buffer): string;
|
|
91
91
|
export declare function encodeNewsletterMessage(message: proto.IMessage): Uint8Array;
|
|
92
|
-
//# sourceMappingURL=generics.d.ts.map
|
package/lib/Utils/generics.js
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isWABusinessPlatform = exports.getCodeFromWSError = exports.getCallStatusFromNode = exports.getErrorCodeFromStreamError = exports.getStatusFromReceiptType = exports.generateMdTagPrefix = exports.fetchLatestWaWebVersion = exports.fetchLatestBaileysVersion = exports.bindWaitForConnectionUpdate = exports.generateMessageID = exports.generateMessageIDV2 = exports.delayCancellable = exports.delay = exports.debouncedTimeout = exports.unixTimestampSeconds = exports.toNumber = exports.encodeBigEndian = exports.generateRegistrationId = exports.encodeWAMessage = exports.unpadRandomMax16 = exports.writeRandomPadMax16 = exports.getKeyAuthor = exports.BufferJSON = exports.getPlatformId = exports.Browsers = void 0;
|
|
7
|
+
exports.promiseTimeout = promiseTimeout;
|
|
8
|
+
exports.bindWaitForEvent = bindWaitForEvent;
|
|
9
|
+
exports.trimUndefined = trimUndefined;
|
|
10
|
+
exports.bytesToCrockford = bytesToCrockford;
|
|
11
|
+
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
12
|
+
const boom_1 = require("@hapi/boom");
|
|
13
|
+
const axios_1 = __importDefault(require("axios"));
|
|
14
|
+
const crypto_1 = require("crypto");
|
|
15
|
+
const os_1 = require("os");
|
|
16
|
+
const WAProto_1 = require("../../WAProto");
|
|
17
|
+
const baileys_version_json_1 = require("../Defaults/baileys-version.json");
|
|
18
|
+
const Types_1 = require("../Types");
|
|
19
|
+
const WABinary_1 = require("../WABinary");
|
|
10
20
|
const PLATFORM_MAP = {
|
|
11
21
|
aix: 'AIX',
|
|
12
22
|
darwin: 'Mac OS',
|
|
@@ -14,29 +24,26 @@ const PLATFORM_MAP = {
|
|
|
14
24
|
android: 'Android',
|
|
15
25
|
freebsd: 'FreeBSD',
|
|
16
26
|
openbsd: 'OpenBSD',
|
|
17
|
-
sunos: 'Solaris'
|
|
18
|
-
linux: undefined,
|
|
19
|
-
haiku: undefined,
|
|
20
|
-
cygwin: undefined,
|
|
21
|
-
netbsd: undefined
|
|
27
|
+
sunos: 'Solaris'
|
|
22
28
|
};
|
|
23
|
-
|
|
29
|
+
exports.Browsers = {
|
|
24
30
|
ubuntu: browser => ['Ubuntu', browser, '22.04.4'],
|
|
25
31
|
macOS: browser => ['Mac OS', browser, '14.4.1'],
|
|
26
32
|
baileys: browser => ['Baileys', browser, '6.5.0'],
|
|
27
33
|
windows: browser => ['Windows', browser, '10.0.22631'],
|
|
28
34
|
/** The appropriate browser based on your OS & release */
|
|
29
|
-
appropriate: browser => [PLATFORM_MAP[platform()] || 'Ubuntu', browser, release()]
|
|
35
|
+
appropriate: browser => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
|
|
30
36
|
};
|
|
31
|
-
|
|
32
|
-
const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
37
|
+
const getPlatformId = (browser) => {
|
|
38
|
+
const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
33
39
|
return platformType ? platformType.toString() : '1'; //chrome
|
|
34
40
|
};
|
|
35
|
-
|
|
41
|
+
exports.getPlatformId = getPlatformId;
|
|
42
|
+
exports.BufferJSON = {
|
|
36
43
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
44
|
replacer: (k, value) => {
|
|
38
|
-
if (Buffer.isBuffer(value) || value instanceof Uint8Array || value
|
|
39
|
-
return { type: 'Buffer', data: Buffer.from(value
|
|
45
|
+
if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
|
|
46
|
+
return { type: 'Buffer', data: Buffer.from((value === null || value === void 0 ? void 0 : value.data) || value).toString('base64') };
|
|
40
47
|
}
|
|
41
48
|
return value;
|
|
42
49
|
},
|
|
@@ -49,18 +56,18 @@ export const BufferJSON = {
|
|
|
49
56
|
return value;
|
|
50
57
|
}
|
|
51
58
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
else {
|
|
59
|
+
const getKeyAuthor = (key, meId = 'me') => ((key === null || key === void 0 ? void 0 : key.fromMe) ? meId : (key === null || key === void 0 ? void 0 : key.participant) || (key === null || key === void 0 ? void 0 : key.remoteJid)) || '';
|
|
60
|
+
exports.getKeyAuthor = getKeyAuthor;
|
|
61
|
+
const writeRandomPadMax16 = (msg) => {
|
|
62
|
+
const pad = (0, crypto_1.randomBytes)(1);
|
|
63
|
+
pad[0] &= 0xf;
|
|
64
|
+
if (!pad[0]) {
|
|
59
65
|
pad[0] = 0xf;
|
|
60
66
|
}
|
|
61
67
|
return Buffer.concat([msg, Buffer.alloc(pad[0], pad[0])]);
|
|
62
68
|
};
|
|
63
|
-
|
|
69
|
+
exports.writeRandomPadMax16 = writeRandomPadMax16;
|
|
70
|
+
const unpadRandomMax16 = (e) => {
|
|
64
71
|
const t = new Uint8Array(e);
|
|
65
72
|
if (0 === t.length) {
|
|
66
73
|
throw new Error('unpadPkcs7 given empty bytes');
|
|
@@ -71,11 +78,14 @@ export const unpadRandomMax16 = (e) => {
|
|
|
71
78
|
}
|
|
72
79
|
return new Uint8Array(t.buffer, t.byteOffset, t.length - r);
|
|
73
80
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
81
|
+
exports.unpadRandomMax16 = unpadRandomMax16;
|
|
82
|
+
const encodeWAMessage = (message) => (0, exports.writeRandomPadMax16)(WAProto_1.proto.Message.encode(message).finish());
|
|
83
|
+
exports.encodeWAMessage = encodeWAMessage;
|
|
84
|
+
const generateRegistrationId = () => {
|
|
85
|
+
return Uint16Array.from((0, crypto_1.randomBytes)(2))[0] & 16383;
|
|
77
86
|
};
|
|
78
|
-
|
|
87
|
+
exports.generateRegistrationId = generateRegistrationId;
|
|
88
|
+
const encodeBigEndian = (e, t = 4) => {
|
|
79
89
|
let r = e;
|
|
80
90
|
const a = new Uint8Array(t);
|
|
81
91
|
for (let i = t - 1; i >= 0; i--) {
|
|
@@ -84,17 +94,20 @@ export const encodeBigEndian = (e, t = 4) => {
|
|
|
84
94
|
}
|
|
85
95
|
return a;
|
|
86
96
|
};
|
|
87
|
-
|
|
97
|
+
exports.encodeBigEndian = encodeBigEndian;
|
|
98
|
+
const toNumber = (t) => typeof t === 'object' && t ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0;
|
|
99
|
+
exports.toNumber = toNumber;
|
|
88
100
|
/** unix timestamp of a date in seconds */
|
|
89
|
-
|
|
90
|
-
|
|
101
|
+
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
|
|
102
|
+
exports.unixTimestampSeconds = unixTimestampSeconds;
|
|
103
|
+
const debouncedTimeout = (intervalMs = 1000, task) => {
|
|
91
104
|
let timeout;
|
|
92
105
|
return {
|
|
93
106
|
start: (newIntervalMs, newTask) => {
|
|
94
107
|
task = newTask || task;
|
|
95
108
|
intervalMs = newIntervalMs || intervalMs;
|
|
96
109
|
timeout && clearTimeout(timeout);
|
|
97
|
-
timeout = setTimeout(() => task
|
|
110
|
+
timeout = setTimeout(() => task === null || task === void 0 ? void 0 : task(), intervalMs);
|
|
98
111
|
},
|
|
99
112
|
cancel: () => {
|
|
100
113
|
timeout && clearTimeout(timeout);
|
|
@@ -104,8 +117,10 @@ export const debouncedTimeout = (intervalMs = 1000, task) => {
|
|
|
104
117
|
setInterval: (newInterval) => (intervalMs = newInterval)
|
|
105
118
|
};
|
|
106
119
|
};
|
|
107
|
-
|
|
108
|
-
|
|
120
|
+
exports.debouncedTimeout = debouncedTimeout;
|
|
121
|
+
const delay = (ms) => (0, exports.delayCancellable)(ms).delay;
|
|
122
|
+
exports.delay = delay;
|
|
123
|
+
const delayCancellable = (ms) => {
|
|
109
124
|
const stack = new Error().stack;
|
|
110
125
|
let timeout;
|
|
111
126
|
let reject;
|
|
@@ -115,7 +130,7 @@ export const delayCancellable = (ms) => {
|
|
|
115
130
|
});
|
|
116
131
|
const cancel = () => {
|
|
117
132
|
clearTimeout(timeout);
|
|
118
|
-
reject(new Boom('Cancelled', {
|
|
133
|
+
reject(new boom_1.Boom('Cancelled', {
|
|
119
134
|
statusCode: 500,
|
|
120
135
|
data: {
|
|
121
136
|
stack
|
|
@@ -124,17 +139,18 @@ export const delayCancellable = (ms) => {
|
|
|
124
139
|
};
|
|
125
140
|
return { delay, cancel };
|
|
126
141
|
};
|
|
127
|
-
|
|
142
|
+
exports.delayCancellable = delayCancellable;
|
|
143
|
+
async function promiseTimeout(ms, promise) {
|
|
128
144
|
if (!ms) {
|
|
129
145
|
return new Promise(promise);
|
|
130
146
|
}
|
|
131
147
|
const stack = new Error().stack;
|
|
132
148
|
// Create a promise that rejects in <ms> milliseconds
|
|
133
|
-
const { delay, cancel } = delayCancellable(ms);
|
|
149
|
+
const { delay, cancel } = (0, exports.delayCancellable)(ms);
|
|
134
150
|
const p = new Promise((resolve, reject) => {
|
|
135
151
|
delay
|
|
136
|
-
.then(() => reject(new Boom('Timed Out', {
|
|
137
|
-
statusCode: DisconnectReason.timedOut,
|
|
152
|
+
.then(() => reject(new boom_1.Boom('Timed Out', {
|
|
153
|
+
statusCode: Types_1.DisconnectReason.timedOut,
|
|
138
154
|
data: {
|
|
139
155
|
stack
|
|
140
156
|
}
|
|
@@ -146,31 +162,33 @@ export async function promiseTimeout(ms, promise) {
|
|
|
146
162
|
}
|
|
147
163
|
// inspired from whatsmeow code
|
|
148
164
|
// https://github.com/tulir/whatsmeow/blob/64bc969fbe78d31ae0dd443b8d4c80a5d026d07a/send.go#L42
|
|
149
|
-
|
|
165
|
+
const generateMessageIDV2 = (userId) => {
|
|
150
166
|
const data = Buffer.alloc(8 + 20 + 16);
|
|
151
167
|
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)));
|
|
152
168
|
if (userId) {
|
|
153
|
-
const id = jidDecode(userId);
|
|
154
|
-
if (id
|
|
169
|
+
const id = (0, WABinary_1.jidDecode)(userId);
|
|
170
|
+
if (id === null || id === void 0 ? void 0 : id.user) {
|
|
155
171
|
data.write(id.user, 8);
|
|
156
172
|
data.write('@c.us', 8 + id.user.length);
|
|
157
173
|
}
|
|
158
174
|
}
|
|
159
|
-
const random = randomBytes(16);
|
|
175
|
+
const random = (0, crypto_1.randomBytes)(16);
|
|
160
176
|
random.copy(data, 28);
|
|
161
|
-
const hash = createHash('sha256').update(data).digest();
|
|
177
|
+
const hash = (0, crypto_1.createHash)('sha256').update(data).digest();
|
|
162
178
|
return (process.env.WHATSAPP_CONN_IDMSG || 'WHPI') + hash.toString('hex').toUpperCase().substring(0, 18);
|
|
163
179
|
};
|
|
180
|
+
exports.generateMessageIDV2 = generateMessageIDV2;
|
|
164
181
|
// generate a random ID to attach to a message
|
|
165
|
-
|
|
166
|
-
|
|
182
|
+
const generateMessageID = () => (process.env.WHATSAPP_CONN_IDMSG || 'WHPI') + (0, crypto_1.randomBytes)(18).toString('hex').toUpperCase();
|
|
183
|
+
exports.generateMessageID = generateMessageID;
|
|
184
|
+
function bindWaitForEvent(ev, event) {
|
|
167
185
|
return async (check, timeoutMs) => {
|
|
168
186
|
let listener;
|
|
169
187
|
let closeListener;
|
|
170
188
|
await promiseTimeout(timeoutMs, (resolve, reject) => {
|
|
171
189
|
closeListener = ({ connection, lastDisconnect }) => {
|
|
172
190
|
if (connection === 'close') {
|
|
173
|
-
reject(lastDisconnect
|
|
191
|
+
reject((lastDisconnect === null || lastDisconnect === void 0 ? void 0 : lastDisconnect.error) || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
174
192
|
}
|
|
175
193
|
};
|
|
176
194
|
ev.on('connection.update', closeListener);
|
|
@@ -186,15 +204,16 @@ export function bindWaitForEvent(ev, event) {
|
|
|
186
204
|
});
|
|
187
205
|
};
|
|
188
206
|
}
|
|
189
|
-
|
|
207
|
+
const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
|
208
|
+
exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
|
|
190
209
|
/**
|
|
191
210
|
* utility that fetches latest baileys version from the master branch.
|
|
192
211
|
* Use to ensure your WA connection is always on the latest version
|
|
193
212
|
*/
|
|
194
|
-
|
|
213
|
+
const fetchLatestBaileysVersion = async (options = {}) => {
|
|
195
214
|
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json';
|
|
196
215
|
try {
|
|
197
|
-
const result = await
|
|
216
|
+
const result = await axios_1.default.get(URL, {
|
|
198
217
|
...options,
|
|
199
218
|
responseType: 'json'
|
|
200
219
|
});
|
|
@@ -205,27 +224,28 @@ export const fetchLatestBaileysVersion = async (options = {}) => {
|
|
|
205
224
|
}
|
|
206
225
|
catch (error) {
|
|
207
226
|
return {
|
|
208
|
-
version:
|
|
227
|
+
version: baileys_version_json_1.version,
|
|
209
228
|
isLatest: false,
|
|
210
229
|
error
|
|
211
230
|
};
|
|
212
231
|
}
|
|
213
232
|
};
|
|
233
|
+
exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
|
|
214
234
|
/**
|
|
215
235
|
* A utility that fetches the latest web version of whatsapp.
|
|
216
236
|
* Use to ensure your WA connection is always on the latest version
|
|
217
237
|
*/
|
|
218
|
-
|
|
238
|
+
const fetchLatestWaWebVersion = async (options) => {
|
|
219
239
|
try {
|
|
220
|
-
const { data } = await
|
|
240
|
+
const { data } = await axios_1.default.get('https://web.whatsapp.com/sw.js', {
|
|
221
241
|
...options,
|
|
222
242
|
responseType: 'json'
|
|
223
243
|
});
|
|
224
244
|
const regex = /\\?"client_revision\\?":\s*(\d+)/;
|
|
225
245
|
const match = data.match(regex);
|
|
226
|
-
if (!match
|
|
246
|
+
if (!(match === null || match === void 0 ? void 0 : match[1])) {
|
|
227
247
|
return {
|
|
228
|
-
version:
|
|
248
|
+
version: baileys_version_json_1.version,
|
|
229
249
|
isLatest: false,
|
|
230
250
|
error: {
|
|
231
251
|
message: 'Could not find client revision in the fetched content'
|
|
@@ -240,46 +260,49 @@ export const fetchLatestWaWebVersion = async (options) => {
|
|
|
240
260
|
}
|
|
241
261
|
catch (error) {
|
|
242
262
|
return {
|
|
243
|
-
version:
|
|
263
|
+
version: baileys_version_json_1.version,
|
|
244
264
|
isLatest: false,
|
|
245
265
|
error
|
|
246
266
|
};
|
|
247
267
|
}
|
|
248
268
|
};
|
|
269
|
+
exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
|
|
249
270
|
/** unique message tag prefix for MD clients */
|
|
250
|
-
|
|
251
|
-
const bytes = randomBytes(4);
|
|
271
|
+
const generateMdTagPrefix = () => {
|
|
272
|
+
const bytes = (0, crypto_1.randomBytes)(4);
|
|
252
273
|
return `${bytes.readUInt16BE()}.${bytes.readUInt16BE(2)}-`;
|
|
253
274
|
};
|
|
275
|
+
exports.generateMdTagPrefix = generateMdTagPrefix;
|
|
254
276
|
const STATUS_MAP = {
|
|
255
|
-
sender: proto.WebMessageInfo.Status.SERVER_ACK,
|
|
256
|
-
played: proto.WebMessageInfo.Status.PLAYED,
|
|
257
|
-
read: proto.WebMessageInfo.Status.READ,
|
|
258
|
-
'read-self': proto.WebMessageInfo.Status.READ
|
|
277
|
+
sender: WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK,
|
|
278
|
+
played: WAProto_1.proto.WebMessageInfo.Status.PLAYED,
|
|
279
|
+
read: WAProto_1.proto.WebMessageInfo.Status.READ,
|
|
280
|
+
'read-self': WAProto_1.proto.WebMessageInfo.Status.READ
|
|
259
281
|
};
|
|
260
282
|
/**
|
|
261
283
|
* Given a type of receipt, returns what the new status of the message should be
|
|
262
284
|
* @param type type from receipt
|
|
263
285
|
*/
|
|
264
|
-
|
|
286
|
+
const getStatusFromReceiptType = (type) => {
|
|
265
287
|
const status = STATUS_MAP[type];
|
|
266
288
|
if (typeof type === 'undefined') {
|
|
267
|
-
return proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
289
|
+
return WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK;
|
|
268
290
|
}
|
|
269
291
|
return status;
|
|
270
292
|
};
|
|
293
|
+
exports.getStatusFromReceiptType = getStatusFromReceiptType;
|
|
271
294
|
const CODE_MAP = {
|
|
272
|
-
conflict: DisconnectReason.connectionReplaced
|
|
295
|
+
conflict: Types_1.DisconnectReason.connectionReplaced
|
|
273
296
|
};
|
|
274
297
|
/**
|
|
275
298
|
* Stream errors generally provide a reason, map that to a baileys DisconnectReason
|
|
276
299
|
* @param reason the string reason given, eg. "conflict"
|
|
277
300
|
*/
|
|
278
|
-
|
|
279
|
-
const [reasonNode] = getAllBinaryNodeChildren(node);
|
|
280
|
-
let reason = reasonNode
|
|
281
|
-
const statusCode = +(node.attrs.code || CODE_MAP[reason] || DisconnectReason.badSession);
|
|
282
|
-
if (statusCode === DisconnectReason.restartRequired) {
|
|
301
|
+
const getErrorCodeFromStreamError = (node) => {
|
|
302
|
+
const [reasonNode] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
|
|
303
|
+
let reason = (reasonNode === null || reasonNode === void 0 ? void 0 : reasonNode.tag) || 'unknown';
|
|
304
|
+
const statusCode = +(node.attrs.code || CODE_MAP[reason] || Types_1.DisconnectReason.badSession);
|
|
305
|
+
if (statusCode === Types_1.DisconnectReason.restartRequired) {
|
|
283
306
|
reason = 'restart required';
|
|
284
307
|
}
|
|
285
308
|
return {
|
|
@@ -287,7 +310,8 @@ export const getErrorCodeFromStreamError = (node) => {
|
|
|
287
310
|
statusCode
|
|
288
311
|
};
|
|
289
312
|
};
|
|
290
|
-
|
|
313
|
+
exports.getErrorCodeFromStreamError = getErrorCodeFromStreamError;
|
|
314
|
+
const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
291
315
|
let status;
|
|
292
316
|
switch (tag) {
|
|
293
317
|
case 'offer':
|
|
@@ -315,33 +339,37 @@ export const getCallStatusFromNode = ({ tag, attrs }) => {
|
|
|
315
339
|
}
|
|
316
340
|
return status;
|
|
317
341
|
};
|
|
342
|
+
exports.getCallStatusFromNode = getCallStatusFromNode;
|
|
318
343
|
const UNEXPECTED_SERVER_CODE_TEXT = 'Unexpected server response: ';
|
|
319
|
-
|
|
344
|
+
const getCodeFromWSError = (error) => {
|
|
345
|
+
var _a, _b, _c;
|
|
320
346
|
let statusCode = 500;
|
|
321
|
-
if (error
|
|
322
|
-
const code = +error
|
|
347
|
+
if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes(UNEXPECTED_SERVER_CODE_TEXT)) {
|
|
348
|
+
const code = +(error === null || error === void 0 ? void 0 : error.message.slice(UNEXPECTED_SERVER_CODE_TEXT.length));
|
|
323
349
|
if (!Number.isNaN(code) && code >= 400) {
|
|
324
350
|
statusCode = code;
|
|
325
351
|
}
|
|
326
352
|
}
|
|
327
353
|
else if (
|
|
328
354
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
329
|
-
error
|
|
330
|
-
error
|
|
355
|
+
((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E')) ||
|
|
356
|
+
((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) {
|
|
331
357
|
// handle ETIMEOUT, ENOTFOUND etc
|
|
332
358
|
statusCode = 408;
|
|
333
359
|
}
|
|
334
360
|
return statusCode;
|
|
335
361
|
};
|
|
362
|
+
exports.getCodeFromWSError = getCodeFromWSError;
|
|
336
363
|
/**
|
|
337
364
|
* Is the given platform WA business
|
|
338
365
|
* @param platform AuthenticationCreds.platform
|
|
339
366
|
*/
|
|
340
|
-
|
|
367
|
+
const isWABusinessPlatform = (platform) => {
|
|
341
368
|
return platform === 'smbi' || platform === 'smba';
|
|
342
369
|
};
|
|
370
|
+
exports.isWABusinessPlatform = isWABusinessPlatform;
|
|
343
371
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
344
|
-
|
|
372
|
+
function trimUndefined(obj) {
|
|
345
373
|
for (const key in obj) {
|
|
346
374
|
if (typeof obj[key] === 'undefined') {
|
|
347
375
|
delete obj[key];
|
|
@@ -350,7 +378,7 @@ export function trimUndefined(obj) {
|
|
|
350
378
|
return obj;
|
|
351
379
|
}
|
|
352
380
|
const CROCKFORD_CHARACTERS = '123456789ABCDEFGHJKLMNPQRSTVWXYZ';
|
|
353
|
-
|
|
381
|
+
function bytesToCrockford(buffer) {
|
|
354
382
|
let value = 0;
|
|
355
383
|
let bitCount = 0;
|
|
356
384
|
const crockford = [];
|
|
@@ -367,7 +395,6 @@ export function bytesToCrockford(buffer) {
|
|
|
367
395
|
}
|
|
368
396
|
return crockford.join('');
|
|
369
397
|
}
|
|
370
|
-
|
|
371
|
-
return proto.Message.encode(message).finish();
|
|
398
|
+
function encodeNewsletterMessage(message) {
|
|
399
|
+
return WAProto_1.proto.Message.encode(message).finish();
|
|
372
400
|
}
|
|
373
|
-
//# sourceMappingURL=generics.js.map
|
package/lib/Utils/history.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { proto } from '../../WAProto
|
|
3
|
-
import
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { proto } from '../../WAProto';
|
|
3
|
+
import { Chat, Contact } from '../Types';
|
|
4
4
|
export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<proto.HistorySync>;
|
|
5
5
|
export declare const processHistoryMessage: (item: proto.IHistorySync) => {
|
|
6
6
|
chats: Chat[];
|
|
@@ -17,4 +17,3 @@ export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Mess
|
|
|
17
17
|
progress: number | null | undefined;
|
|
18
18
|
}>;
|
|
19
19
|
export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
|
|
20
|
-
//# sourceMappingURL=history.d.ts.map
|
package/lib/Utils/history.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHistoryMsg = exports.downloadAndProcessHistorySyncNotification = exports.processHistoryMessage = exports.downloadHistory = void 0;
|
|
4
|
+
const util_1 = require("util");
|
|
5
|
+
const zlib_1 = require("zlib");
|
|
6
|
+
const WAProto_1 = require("../../WAProto");
|
|
7
|
+
const Types_1 = require("../Types");
|
|
8
|
+
const WABinary_1 = require("../WABinary");
|
|
9
|
+
const generics_1 = require("./generics");
|
|
10
|
+
const messages_1 = require("./messages");
|
|
11
|
+
const messages_media_1 = require("./messages-media");
|
|
12
|
+
const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
|
|
13
|
+
const downloadHistory = async (msg, options) => {
|
|
14
|
+
const stream = await (0, messages_media_1.downloadContentFromMessage)(msg, 'md-msg-hist', { options });
|
|
12
15
|
const bufferArray = [];
|
|
13
16
|
for await (const chunk of stream) {
|
|
14
17
|
bufferArray.push(chunk);
|
|
@@ -16,50 +19,52 @@ export const downloadHistory = async (msg, options) => {
|
|
|
16
19
|
let buffer = Buffer.concat(bufferArray);
|
|
17
20
|
// decompress buffer
|
|
18
21
|
buffer = await inflatePromise(buffer);
|
|
19
|
-
const syncData = proto.HistorySync.decode(buffer);
|
|
22
|
+
const syncData = WAProto_1.proto.HistorySync.decode(buffer);
|
|
20
23
|
return syncData;
|
|
21
24
|
};
|
|
22
|
-
|
|
25
|
+
exports.downloadHistory = downloadHistory;
|
|
26
|
+
const processHistoryMessage = (item) => {
|
|
27
|
+
var _a, _b, _c;
|
|
23
28
|
const messages = [];
|
|
24
29
|
const contacts = [];
|
|
25
30
|
const chats = [];
|
|
26
31
|
switch (item.syncType) {
|
|
27
|
-
case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
28
|
-
case proto.HistorySync.HistorySyncType.RECENT:
|
|
29
|
-
case proto.HistorySync.HistorySyncType.FULL:
|
|
30
|
-
case proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
32
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
|
|
33
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:
|
|
34
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.FULL:
|
|
35
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:
|
|
31
36
|
for (const chat of item.conversations) {
|
|
32
37
|
contacts.push({
|
|
33
38
|
id: chat.id,
|
|
34
39
|
name: chat.name || undefined,
|
|
35
40
|
lid: chat.lidJid || undefined,
|
|
36
|
-
jid: isJidUser(chat.id) ? chat.id : undefined
|
|
41
|
+
jid: (0, WABinary_1.isJidUser)(chat.id) ? chat.id : undefined
|
|
37
42
|
});
|
|
38
43
|
const msgs = chat.messages || [];
|
|
39
44
|
delete chat.messages;
|
|
40
45
|
for (const item of msgs) {
|
|
41
46
|
const message = item.message;
|
|
42
47
|
messages.push(message);
|
|
43
|
-
if (!chat.messages
|
|
48
|
+
if (!((_a = chat.messages) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
44
49
|
// keep only the most recent message in the chat array
|
|
45
50
|
chat.messages = [{ message }];
|
|
46
51
|
}
|
|
47
52
|
if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
|
|
48
|
-
chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
|
|
53
|
+
chat.lastMessageRecvTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
|
|
49
54
|
}
|
|
50
|
-
if ((message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
|
|
51
|
-
message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
|
|
52
|
-
message.messageStubParameters
|
|
55
|
+
if ((message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
|
|
56
|
+
message.messageStubType === Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
|
|
57
|
+
((_b = message.messageStubParameters) === null || _b === void 0 ? void 0 : _b[0])) {
|
|
53
58
|
contacts.push({
|
|
54
59
|
id: message.key.participant || message.key.remoteJid,
|
|
55
|
-
verifiedName: message.messageStubParameters
|
|
60
|
+
verifiedName: (_c = message.messageStubParameters) === null || _c === void 0 ? void 0 : _c[0]
|
|
56
61
|
});
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
64
|
chats.push({ ...chat });
|
|
60
65
|
}
|
|
61
66
|
break;
|
|
62
|
-
case proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
67
|
+
case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:
|
|
63
68
|
for (const c of item.pushnames) {
|
|
64
69
|
contacts.push({ id: c.id, notify: c.pushname });
|
|
65
70
|
}
|
|
@@ -73,13 +78,16 @@ export const processHistoryMessage = (item) => {
|
|
|
73
78
|
progress: item.progress
|
|
74
79
|
};
|
|
75
80
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
exports.processHistoryMessage = processHistoryMessage;
|
|
82
|
+
const downloadAndProcessHistorySyncNotification = async (msg, options) => {
|
|
83
|
+
const historyMsg = await (0, exports.downloadHistory)(msg, options);
|
|
84
|
+
return (0, exports.processHistoryMessage)(historyMsg);
|
|
79
85
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
exports.downloadAndProcessHistorySyncNotification = downloadAndProcessHistorySyncNotification;
|
|
87
|
+
const getHistoryMsg = (message) => {
|
|
88
|
+
var _a;
|
|
89
|
+
const normalizedContent = !!message ? (0, messages_1.normalizeMessageContent)(message) : undefined;
|
|
90
|
+
const anyHistoryMsg = (_a = normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage) === null || _a === void 0 ? void 0 : _a.historySyncNotification;
|
|
83
91
|
return anyHistoryMsg;
|
|
84
92
|
};
|
|
85
|
-
|
|
93
|
+
exports.getHistoryMsg = getHistoryMsg;
|
package/lib/Utils/index.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
export * from './generics
|
|
2
|
-
export * from './decode-wa-message
|
|
3
|
-
export * from './messages
|
|
4
|
-
export * from './messages-media
|
|
5
|
-
export * from './validate-connection
|
|
6
|
-
export * from './crypto
|
|
7
|
-
export * from './signal
|
|
8
|
-
export * from './noise-handler
|
|
9
|
-
export * from './history
|
|
10
|
-
export * from './chat-utils
|
|
11
|
-
export * from './lt-hash
|
|
12
|
-
export * from './auth-utils
|
|
13
|
-
export * from './baileys-event-stream
|
|
14
|
-
export * from './use-multi-file-auth-state
|
|
15
|
-
export * from './link-preview
|
|
16
|
-
export * from './event-buffer
|
|
17
|
-
export * from './process-message
|
|
18
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
export * from './generics';
|
|
2
|
+
export * from './decode-wa-message';
|
|
3
|
+
export * from './messages';
|
|
4
|
+
export * from './messages-media';
|
|
5
|
+
export * from './validate-connection';
|
|
6
|
+
export * from './crypto';
|
|
7
|
+
export * from './signal';
|
|
8
|
+
export * from './noise-handler';
|
|
9
|
+
export * from './history';
|
|
10
|
+
export * from './chat-utils';
|
|
11
|
+
export * from './lt-hash';
|
|
12
|
+
export * from './auth-utils';
|
|
13
|
+
export * from './baileys-event-stream';
|
|
14
|
+
export * from './use-multi-file-auth-state';
|
|
15
|
+
export * from './link-preview';
|
|
16
|
+
export * from './event-buffer';
|
|
17
|
+
export * from './process-message';
|