@queenanya/baileys 7.1.8 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +3 -1
- package/lib/Socket/business.d.ts +13 -5
- package/lib/Socket/chats.d.ts +2 -2
- package/lib/Socket/chats.js +9 -0
- package/lib/Socket/groups.d.ts +1 -1
- package/lib/Socket/index.d.ts +13 -5
- package/lib/Socket/messages-recv.d.ts +12 -5
- package/lib/Socket/messages-recv.js +94 -12
- package/lib/Socket/messages-send.d.ts +9 -4
- package/lib/Socket/messages-send.js +90 -31
- package/lib/Socket/newsletter.d.ts +1 -1
- package/lib/Socket/registration.d.ts +13 -5
- package/lib/Store/make-in-memory-store.js +5 -1
- package/lib/Types/Chat.d.ts +1 -0
- package/lib/Types/Events.d.ts +5 -1
- package/lib/Types/Message.d.ts +15 -25
- package/lib/Types/Socket.d.ts +5 -0
- package/lib/Utils/decode-wa-message.d.ts +1 -0
- package/lib/Utils/decode-wa-message.js +5 -5
- package/lib/Utils/history.d.ts +4 -0
- package/lib/Utils/history.js +3 -0
- package/lib/Utils/messages.js +17 -58
- package/lib/Utils/process-message.d.ts +3 -2
- package/lib/Utils/process-message.js +39 -25
- package/lib/WABinary/jid-utils.d.ts +2 -2
- package/lib/WABinary/jid-utils.js +4 -4
- package/package.json +1 -1
package/lib/Defaults/index.js
CHANGED
|
@@ -44,7 +44,8 @@ exports.PROCESSABLE_HISTORY_TYPES = [
|
|
|
44
44
|
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
|
|
45
45
|
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
|
|
46
46
|
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
|
|
47
|
-
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL
|
|
47
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
|
|
48
|
+
WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND,
|
|
48
49
|
];
|
|
49
50
|
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
50
51
|
version: baileys_version_json_1.version,
|
|
@@ -76,6 +77,7 @@ exports.DEFAULT_CONNECTION_CONFIG = {
|
|
|
76
77
|
snapshot: false,
|
|
77
78
|
},
|
|
78
79
|
getMessage: async () => undefined,
|
|
80
|
+
cachedGroupMetadata: async () => undefined,
|
|
79
81
|
makeSignalRepository: libsignal_1.makeLibSignalRepository
|
|
80
82
|
};
|
|
81
83
|
exports.MEDIA_PATH_MAP = {
|
package/lib/Socket/business.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="long" />
|
|
1
2
|
/// <reference types="node" />
|
|
2
3
|
import { GetCatalogOptions, ProductCreate, ProductUpdate, SocketConfig } from '../Types';
|
|
3
4
|
import { BinaryNode } from '../WABinary';
|
|
@@ -19,20 +20,27 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
19
20
|
sendMessageAck: ({ tag, attrs, content }: BinaryNode) => Promise<void>;
|
|
20
21
|
sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
|
|
21
22
|
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
|
23
|
+
fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | import("long").Long) => Promise<string>;
|
|
24
|
+
requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
|
|
22
25
|
getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
|
|
23
26
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
24
|
-
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache,
|
|
27
|
+
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
25
28
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
26
29
|
sendReceipts: (keys: import("../Types").WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
27
|
-
getButtonArgs: (message: import("../Types").WAProto.IMessage) => {
|
|
28
|
-
[key: string]: string;
|
|
29
|
-
};
|
|
30
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<{
|
|
34
34
|
[_: string]: string;
|
|
35
35
|
}>;
|
|
36
|
+
sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
|
37
|
+
createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: {
|
|
38
|
+
[key: string]: string;
|
|
39
|
+
} | undefined) => Promise<{
|
|
40
|
+
nodes: BinaryNode[];
|
|
41
|
+
shouldIncludeDeviceIdentity: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
|
|
36
44
|
updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
|
|
37
45
|
sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
|
|
38
46
|
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
@@ -119,7 +127,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
|
|
|
119
127
|
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
120
128
|
updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
121
129
|
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
|
122
|
-
updateGroupsAddPrivacy: (value: import("../Types").
|
|
130
|
+
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
|
|
123
131
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
124
132
|
getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
|
|
125
133
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
package/lib/Socket/chats.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Boom } from '@hapi/boom';
|
|
3
3
|
import { proto } from '../../WAProto';
|
|
4
|
-
import { ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAPatchCreate, WAPresence, WAPrivacyCallValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
|
|
4
|
+
import { ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAPatchCreate, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
|
|
5
5
|
import { BinaryNode } from '../WABinary';
|
|
6
6
|
import { LabelActionBody } from '../Types/Label';
|
|
7
7
|
export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
@@ -41,7 +41,7 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
|
|
|
41
41
|
updateProfilePicturePrivacy: (value: WAPrivacyValue) => Promise<void>;
|
|
42
42
|
updateStatusPrivacy: (value: WAPrivacyValue) => Promise<void>;
|
|
43
43
|
updateReadReceiptsPrivacy: (value: WAReadReceiptsValue) => Promise<void>;
|
|
44
|
-
updateGroupsAddPrivacy: (value:
|
|
44
|
+
updateGroupsAddPrivacy: (value: WAPrivacyGroupAddValue) => Promise<void>;
|
|
45
45
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
46
46
|
getBusinessProfile: (jid: string) => Promise<WABusinessProfile | void>;
|
|
47
47
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
package/lib/Socket/chats.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.makeChatsSocket = void 0;
|
|
7
7
|
const boom_1 = require("@hapi/boom");
|
|
8
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
|
8
9
|
const WAProto_1 = require("../../WAProto");
|
|
9
10
|
const Defaults_1 = require("../Defaults");
|
|
10
11
|
const Types_1 = require("../Types");
|
|
@@ -23,6 +24,13 @@ const makeChatsSocket = (config) => {
|
|
|
23
24
|
let pendingAppStateSync = false;
|
|
24
25
|
/** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
|
|
25
26
|
const processingMutex = (0, make_mutex_1.makeMutex)();
|
|
27
|
+
const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
|
|
28
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
29
|
+
useClones: false
|
|
30
|
+
});
|
|
31
|
+
if (!config.placeholderResendCache) {
|
|
32
|
+
config.placeholderResendCache = placeholderResendCache;
|
|
33
|
+
}
|
|
26
34
|
/** helper function to fetch the given app state sync key */
|
|
27
35
|
const getAppStateSyncKey = async (keyId) => {
|
|
28
36
|
const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
|
|
@@ -757,6 +765,7 @@ const makeChatsSocket = (config) => {
|
|
|
757
765
|
})(),
|
|
758
766
|
(0, process_message_1.default)(msg, {
|
|
759
767
|
shouldProcessHistoryMsg,
|
|
768
|
+
placeholderResendCache,
|
|
760
769
|
ev,
|
|
761
770
|
creds: authState.creds,
|
|
762
771
|
keyStore: authState.keys,
|
package/lib/Socket/groups.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
|
80
80
|
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
81
81
|
updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
82
82
|
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
|
83
|
-
updateGroupsAddPrivacy: (value: import("../Types").
|
|
83
|
+
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
|
|
84
84
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
85
85
|
getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
|
|
86
86
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
package/lib/Socket/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="long" />
|
|
1
2
|
/// <reference types="node" />
|
|
2
3
|
import { UserFacingSocketConfig } from '../Types';
|
|
3
4
|
declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
@@ -20,20 +21,27 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
20
21
|
sendMessageAck: ({ tag, attrs, content }: import("../index").BinaryNode) => Promise<void>;
|
|
21
22
|
sendRetryRequest: (node: import("../index").BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
|
|
22
23
|
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
|
24
|
+
fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | import("long").Long) => Promise<string>;
|
|
25
|
+
requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
|
|
23
26
|
getPrivacyTokens: (jids: string[]) => Promise<import("../index").BinaryNode>;
|
|
24
27
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
25
|
-
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache,
|
|
28
|
+
relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
|
|
26
29
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
27
30
|
sendReceipts: (keys: import("../Types").WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
|
|
28
|
-
getButtonArgs: (message: import("../Types").WAProto.IMessage) => {
|
|
29
|
-
[key: string]: string;
|
|
30
|
-
};
|
|
31
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<{
|
|
35
35
|
[_: string]: string;
|
|
36
36
|
}>;
|
|
37
|
+
sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
|
38
|
+
createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: {
|
|
39
|
+
[key: string]: string;
|
|
40
|
+
} | undefined) => Promise<{
|
|
41
|
+
nodes: import("../index").BinaryNode[];
|
|
42
|
+
shouldIncludeDeviceIdentity: boolean;
|
|
43
|
+
}>;
|
|
44
|
+
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../index").JidWithDevice[]>;
|
|
37
45
|
updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
|
|
38
46
|
sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
|
|
39
47
|
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
@@ -120,7 +128,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
|
|
|
120
128
|
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
121
129
|
updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
122
130
|
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
|
123
|
-
updateGroupsAddPrivacy: (value: import("../Types").
|
|
131
|
+
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
|
|
124
132
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
125
133
|
getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
|
|
126
134
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
@@ -7,20 +7,27 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
7
7
|
sendMessageAck: ({ tag, attrs, content }: BinaryNode) => Promise<void>;
|
|
8
8
|
sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
|
|
9
9
|
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
|
10
|
+
fetchMessageHistory: (count: number, oldestMsgKey: WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
|
|
11
|
+
requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<'RESOLVED' | string | undefined>;
|
|
10
12
|
getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
|
|
11
13
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
12
|
-
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache,
|
|
14
|
+
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
|
|
13
15
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
|
|
14
16
|
sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
|
|
15
|
-
getButtonArgs: (message: proto.IMessage) => {
|
|
16
|
-
[key: string]: string;
|
|
17
|
-
};
|
|
18
17
|
readMessages: (keys: WAMessageKey[]) => Promise<void>;
|
|
19
18
|
refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
|
|
20
19
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
|
21
20
|
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
22
21
|
[_: string]: string;
|
|
23
22
|
}>;
|
|
23
|
+
sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
|
24
|
+
createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: {
|
|
25
|
+
[key: string]: string;
|
|
26
|
+
} | undefined) => Promise<{
|
|
27
|
+
nodes: BinaryNode[];
|
|
28
|
+
shouldIncludeDeviceIdentity: boolean;
|
|
29
|
+
}>;
|
|
30
|
+
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
|
|
24
31
|
updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
|
|
25
32
|
sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
|
|
26
33
|
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
@@ -107,7 +114,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
107
114
|
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
108
115
|
updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
109
116
|
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
|
110
|
-
updateGroupsAddPrivacy: (value: import("../Types").
|
|
117
|
+
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
|
|
111
118
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
112
119
|
getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
|
|
113
120
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
@@ -19,7 +19,7 @@ const messages_send_1 = require("./messages-send");
|
|
|
19
19
|
const makeMessagesRecvSocket = (config) => {
|
|
20
20
|
const { logger, retryRequestDelayMs, maxMsgRetryCount, ignoreMsgLoading, getMessage, shouldIgnoreJid } = config;
|
|
21
21
|
const sock = (0, messages_send_1.makeMessagesSocket)(config);
|
|
22
|
-
const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, } = sock;
|
|
22
|
+
const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage, } = sock;
|
|
23
23
|
/** this mutex ensures that each retryRequest will wait for the previous one to finish */
|
|
24
24
|
const retryMutex = (0, make_mutex_1.makeMutex)();
|
|
25
25
|
const msgRetryCache = config.msgRetryCounterCache || new node_cache_1.default({
|
|
@@ -30,6 +30,10 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
30
30
|
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.CALL_OFFER,
|
|
31
31
|
useClones: false
|
|
32
32
|
});
|
|
33
|
+
const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
|
|
34
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
35
|
+
useClones: false
|
|
36
|
+
});
|
|
33
37
|
let sendActiveReceipts = false;
|
|
34
38
|
const sendMessageAck = async ({ tag, attrs, content }) => {
|
|
35
39
|
const stanza = {
|
|
@@ -75,8 +79,10 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
75
79
|
await query(stanza);
|
|
76
80
|
};
|
|
77
81
|
const sendRetryRequest = async (node, forceIncludeKeys = false) => {
|
|
78
|
-
const {
|
|
79
|
-
const key =
|
|
82
|
+
const { fullMessage } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '');
|
|
83
|
+
const { key: msgKey } = fullMessage;
|
|
84
|
+
const msgId = msgKey.id;
|
|
85
|
+
const key = `${msgId}:${msgKey === null || msgKey === void 0 ? void 0 : msgKey.participant}`;
|
|
80
86
|
let retryCount = msgRetryCache.get(key) || 0;
|
|
81
87
|
if (retryCount >= maxMsgRetryCount) {
|
|
82
88
|
logger.debug({ retryCount, msgId }, 'reached retry limit, clearing');
|
|
@@ -86,6 +92,11 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
86
92
|
retryCount += 1;
|
|
87
93
|
msgRetryCache.set(key, retryCount);
|
|
88
94
|
const { account, signedPreKey, signedIdentityKey: identityKey } = authState.creds;
|
|
95
|
+
if (retryCount === 1) {
|
|
96
|
+
//request a resend via phone
|
|
97
|
+
const msgId = await requestPlaceholderResend(msgKey);
|
|
98
|
+
logger.debug(`sendRetryRequest: requested placeholder resend for message ${msgId}`);
|
|
99
|
+
}
|
|
89
100
|
const deviceIdentity = (0, Utils_1.encodeSignedDeviceIdentity)(account, true);
|
|
90
101
|
await authState.keys.transaction(async () => {
|
|
91
102
|
const receipt = {
|
|
@@ -362,7 +373,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
362
373
|
const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
|
|
363
374
|
const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
|
|
364
375
|
ev.emit('contacts.update', [{
|
|
365
|
-
id: (0, WABinary_1.jidNormalizedUser)((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.
|
|
376
|
+
id: (0, WABinary_1.jidNormalizedUser)((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.from) || ((_c = (_b = (setPicture || delPicture)) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.hash) || '',
|
|
366
377
|
imgUrl: setPicture ? 'changed' : 'removed'
|
|
367
378
|
}]);
|
|
368
379
|
if ((0, WABinary_1.isJidGroup)(from)) {
|
|
@@ -630,19 +641,37 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
630
641
|
]);
|
|
631
642
|
};
|
|
632
643
|
const handleMessage = async (node) => {
|
|
633
|
-
var _a, _b;
|
|
634
|
-
if (ignoreMsgLoading && node.attrs.offline) {
|
|
635
|
-
logger.debug({ key: node.attrs.key }, 'ignored offline message');
|
|
636
|
-
await sendMessageAck(node);
|
|
637
|
-
return;
|
|
638
|
-
}
|
|
644
|
+
var _a, _b, _c;
|
|
639
645
|
if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
|
|
646
|
+
if (ignoreMsgLoading && node.attrs.offline) {
|
|
647
|
+
logger.debug({ key: node.attrs.key }, 'ignored offline message');
|
|
648
|
+
await sendMessageAck(node);
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
640
651
|
logger.debug({ key: node.attrs.key }, 'ignored message');
|
|
641
652
|
await sendMessageAck(node);
|
|
642
653
|
return;
|
|
643
654
|
}
|
|
655
|
+
let response;
|
|
656
|
+
if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !(0, WABinary_1.getBinaryNodeChild)(node, 'enc')) {
|
|
657
|
+
await sendMessageAck(node);
|
|
658
|
+
const { key } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
|
|
659
|
+
response = await requestPlaceholderResend(key);
|
|
660
|
+
if (response === 'RESOLVED') {
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
logger.debug('received unavailable message, acked and requested resend from phone');
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
if (placeholderResendCache.get(node.attrs.id)) {
|
|
667
|
+
placeholderResendCache.del(node.attrs.id);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
644
670
|
const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
|
|
645
|
-
if (
|
|
671
|
+
if (response && ((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT) {
|
|
672
|
+
msg.messageStubParameters = [Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT, response];
|
|
673
|
+
}
|
|
674
|
+
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER) {
|
|
646
675
|
if (node.attrs.sender_pn) {
|
|
647
676
|
ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
|
|
648
677
|
}
|
|
@@ -654,6 +683,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
654
683
|
if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
|
|
655
684
|
retryMutex.mutex(async () => {
|
|
656
685
|
if (ws.isOpen) {
|
|
686
|
+
if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable')) {
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
657
689
|
const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
|
|
658
690
|
await sendRetryRequest(node, !encNode);
|
|
659
691
|
if (retryRequestDelayMs) {
|
|
@@ -696,6 +728,54 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
696
728
|
sendMessageAck(node)
|
|
697
729
|
]);
|
|
698
730
|
};
|
|
731
|
+
const fetchMessageHistory = async (count, oldestMsgKey, oldestMsgTimestamp) => {
|
|
732
|
+
var _a;
|
|
733
|
+
if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
734
|
+
throw new boom_1.Boom('Not authenticated');
|
|
735
|
+
}
|
|
736
|
+
const pdoMessage = {
|
|
737
|
+
historySyncOnDemandRequest: {
|
|
738
|
+
chatJid: oldestMsgKey.remoteJid,
|
|
739
|
+
oldestMsgFromMe: oldestMsgKey.fromMe,
|
|
740
|
+
oldestMsgId: oldestMsgKey.id,
|
|
741
|
+
oldestMsgTimestampMs: oldestMsgTimestamp,
|
|
742
|
+
onDemandMsgCount: count
|
|
743
|
+
},
|
|
744
|
+
peerDataOperationRequestType: WAProto_1.proto.Message.PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND
|
|
745
|
+
};
|
|
746
|
+
return sendPeerDataOperationMessage(pdoMessage);
|
|
747
|
+
};
|
|
748
|
+
const requestPlaceholderResend = async (messageKey) => {
|
|
749
|
+
var _a;
|
|
750
|
+
if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
751
|
+
throw new boom_1.Boom('Not authenticated');
|
|
752
|
+
}
|
|
753
|
+
if (placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
|
|
754
|
+
logger.debug('already requested resend', { messageKey });
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
else {
|
|
758
|
+
placeholderResendCache.set(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id, true);
|
|
759
|
+
}
|
|
760
|
+
await (0, Utils_1.delay)(5000);
|
|
761
|
+
if (!placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
|
|
762
|
+
logger.debug('message received while resend requested', { messageKey });
|
|
763
|
+
return 'RESOLVED';
|
|
764
|
+
}
|
|
765
|
+
const pdoMessage = {
|
|
766
|
+
placeholderMessageResendRequest: [{
|
|
767
|
+
messageKey
|
|
768
|
+
}],
|
|
769
|
+
peerDataOperationRequestType: WAProto_1.proto.Message.PeerDataOperationRequestType.PLACEHOLDER_MESSAGE_RESEND
|
|
770
|
+
};
|
|
771
|
+
setTimeout(() => {
|
|
772
|
+
if (placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
|
|
773
|
+
logger.debug('PDO message without response after 15 seconds. Phone possibly offline', { messageKey });
|
|
774
|
+
placeholderResendCache.del(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id);
|
|
775
|
+
}
|
|
776
|
+
}, 15000);
|
|
777
|
+
return sendPeerDataOperationMessage(pdoMessage);
|
|
778
|
+
};
|
|
699
779
|
const handleCall = async (node) => {
|
|
700
780
|
const { attrs } = node;
|
|
701
781
|
const [infoChild] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
|
|
@@ -825,7 +905,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
825
905
|
...sock,
|
|
826
906
|
sendMessageAck,
|
|
827
907
|
sendRetryRequest,
|
|
828
|
-
rejectCall
|
|
908
|
+
rejectCall,
|
|
909
|
+
fetchMessageHistory,
|
|
910
|
+
requestPlaceholderResend,
|
|
829
911
|
};
|
|
830
912
|
};
|
|
831
913
|
exports.makeMessagesRecvSocket = makeMessagesRecvSocket;
|
|
@@ -2,20 +2,25 @@
|
|
|
2
2
|
import { Boom } from '@hapi/boom';
|
|
3
3
|
import { proto } from '../../WAProto';
|
|
4
4
|
import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types';
|
|
5
|
-
import { BinaryNode } from '../WABinary';
|
|
5
|
+
import { BinaryNode, JidWithDevice } from '../WABinary';
|
|
6
6
|
export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
7
7
|
getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
|
|
8
8
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
9
|
-
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache,
|
|
9
|
+
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
|
|
10
10
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
|
|
11
11
|
sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
|
|
12
|
-
getButtonArgs: (message: proto.IMessage) => BinaryNode['attrs'];
|
|
13
12
|
readMessages: (keys: WAMessageKey[]) => Promise<void>;
|
|
14
13
|
refreshMediaConn: (forceGet?: boolean) => Promise<MediaConnInfo>;
|
|
15
14
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
|
16
15
|
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
17
16
|
[_: string]: string;
|
|
18
17
|
}>;
|
|
18
|
+
sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
|
19
|
+
createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode['attrs']) => Promise<{
|
|
20
|
+
nodes: BinaryNode[];
|
|
21
|
+
shouldIncludeDeviceIdentity: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<JidWithDevice[]>;
|
|
19
24
|
updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
|
|
20
25
|
sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
|
|
21
26
|
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
@@ -102,7 +107,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
102
107
|
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
103
108
|
updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
104
109
|
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
|
105
|
-
updateGroupsAddPrivacy: (value: import("../Types").
|
|
110
|
+
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
|
|
106
111
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
107
112
|
getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
|
|
108
113
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|