@d0v3riz/baileys 6.7.17 → 6.7.19

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.
@@ -20,7 +20,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
20
20
  rejectCall: (callId: string, callFrom: string) => Promise<void>;
21
21
  fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | import("long").default) => Promise<string>;
22
22
  requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
23
- getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
23
+ getPrivacyTokens: (jids: string[]) => Promise<any>;
24
24
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
25
25
  relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
26
26
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
@@ -60,7 +60,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
60
60
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
61
61
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
62
62
  groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
63
- groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
63
+ groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
64
64
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
65
65
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
66
66
  groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
@@ -130,8 +130,8 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
130
130
  signalRepository: import("../Types").SignalRepository;
131
131
  user: import("../Types").Contact | undefined;
132
132
  generateMessageTag: () => string;
133
- query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
134
- waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
133
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
134
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
135
135
  waitForSocketOpen: () => Promise<void>;
136
136
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
137
137
  sendNode: (frame: BinaryNode) => Promise<void>;
@@ -142,5 +142,5 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
142
142
  uploadPreKeysToServerIfRequired: () => Promise<void>;
143
143
  requestPairingCode: (phoneNumber: string) => Promise<string>;
144
144
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
145
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
145
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
146
146
  };
@@ -69,8 +69,8 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
69
69
  signalRepository: import("../Types").SignalRepository;
70
70
  user: import("../Types").Contact | undefined;
71
71
  generateMessageTag: () => string;
72
- query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
73
- waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
72
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
73
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
74
74
  waitForSocketOpen: () => Promise<void>;
75
75
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
76
76
  sendNode: (frame: BinaryNode) => Promise<void>;
@@ -81,5 +81,5 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
81
81
  uploadPreKeysToServerIfRequired: () => Promise<void>;
82
82
  requestPairingCode: (phoneNumber: string) => Promise<string>;
83
83
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
84
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
84
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
85
85
  };
@@ -34,7 +34,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
34
34
  * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
35
35
  * @param inviteMessage the message to accept
36
36
  */
37
- groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
37
+ groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
38
38
  groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
39
39
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
40
40
  groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
@@ -107,8 +107,8 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
107
107
  signalRepository: import("../Types").SignalRepository;
108
108
  user: import("../Types").Contact | undefined;
109
109
  generateMessageTag: () => string;
110
- query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
111
- waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
110
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
111
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
112
112
  waitForSocketOpen: () => Promise<void>;
113
113
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
114
114
  sendNode: (frame: BinaryNode) => Promise<void>;
@@ -119,6 +119,6 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
119
119
  uploadPreKeysToServerIfRequired: () => Promise<void>;
120
120
  requestPairingCode: (phoneNumber: string) => Promise<string>;
121
121
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
122
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
122
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
123
123
  };
124
124
  export declare const extractGroupMetadata: (result: BinaryNode) => GroupMetadata;
@@ -69,7 +69,7 @@ const makeGroupsSocket = (config) => {
69
69
  ...sock,
70
70
  groupMetadata,
71
71
  groupCreate: async (subject, participants) => {
72
- const key = (0, Utils_1.generateMessageID)();
72
+ const key = (0, Utils_1.generateMessageIDV2)();
73
73
  const result = await groupQuery('@g.us', 'set', [
74
74
  {
75
75
  tag: 'create',
@@ -163,7 +163,7 @@ const makeGroupsSocket = (config) => {
163
163
  {
164
164
  tag: 'description',
165
165
  attrs: {
166
- ...(description ? { id: (0, Utils_1.generateMessageID)() } : { delete: 'true' }),
166
+ ...(description ? { id: (0, Utils_1.generateMessageIDV2)() } : { delete: 'true' }),
167
167
  ...(prev ? { prev } : {})
168
168
  },
169
169
  content: description ? [
@@ -286,6 +286,7 @@ const extractGroupMetadata = (result) => {
286
286
  const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
287
287
  const metadata = {
288
288
  id: groupId,
289
+ addressingMode: group.attrs.addressing_mode,
289
290
  subject: group.attrs.subject,
290
291
  subjectOwner: group.attrs.s_o,
291
292
  subjectTime: +group.attrs.s_t,
@@ -19,7 +19,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
19
19
  rejectCall: (callId: string, callFrom: string) => Promise<void>;
20
20
  fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | import("long").default) => Promise<string>;
21
21
  requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
22
- getPrivacyTokens: (jids: string[]) => Promise<import("..").BinaryNode>;
22
+ getPrivacyTokens: (jids: string[]) => Promise<any>;
23
23
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
24
24
  relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
25
25
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
@@ -59,7 +59,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
59
59
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
60
60
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
61
61
  groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
62
- groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
62
+ groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
63
63
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
64
64
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
65
65
  groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
@@ -129,8 +129,8 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
129
129
  signalRepository: import("../Types").SignalRepository;
130
130
  user: import("../Types").Contact | undefined;
131
131
  generateMessageTag: () => string;
132
- query: (node: import("..").BinaryNode, timeoutMs?: number) => Promise<import("..").BinaryNode>;
133
- waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
132
+ query: (node: import("..").BinaryNode, timeoutMs?: number) => Promise<any>;
133
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
134
134
  waitForSocketOpen: () => Promise<void>;
135
135
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
136
136
  sendNode: (frame: import("..").BinaryNode) => Promise<void>;
@@ -141,6 +141,6 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
141
141
  uploadPreKeysToServerIfRequired: () => Promise<void>;
142
142
  requestPairingCode: (phoneNumber: string) => Promise<string>;
143
143
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
144
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<import("..").BinaryNode>;
144
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
145
145
  };
146
146
  export default makeWASocket;
@@ -9,7 +9,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
9
9
  rejectCall: (callId: string, callFrom: string) => Promise<void>;
10
10
  fetchMessageHistory: (count: number, oldestMsgKey: WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
11
11
  requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<string | undefined>;
12
- getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
12
+ getPrivacyTokens: (jids: string[]) => Promise<any>;
13
13
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
14
14
  relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
15
15
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
@@ -49,7 +49,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
49
49
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
50
50
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
51
51
  groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
52
- groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
52
+ groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
53
53
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
54
54
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
55
55
  groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
@@ -119,8 +119,8 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
119
119
  signalRepository: import("../Types").SignalRepository;
120
120
  user: import("../Types").Contact | undefined;
121
121
  generateMessageTag: () => string;
122
- query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
123
- waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
122
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
123
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
124
124
  waitForSocketOpen: () => Promise<void>;
125
125
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
126
126
  sendNode: (frame: BinaryNode) => Promise<void>;
@@ -131,5 +131,5 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
131
131
  uploadPreKeysToServerIfRequired: () => Promise<void>;
132
132
  requestPairingCode: (phoneNumber: string) => Promise<string>;
133
133
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
134
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
134
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
135
135
  };
@@ -4,7 +4,7 @@ import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptio
4
4
  import { BinaryNode, JidWithDevice } from '../WABinary';
5
5
  import { USyncQuery } from '../WAUSync';
6
6
  export declare const makeMessagesSocket: (config: SocketConfig) => {
7
- getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
7
+ getPrivacyTokens: (jids: string[]) => Promise<any>;
8
8
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
9
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>;
@@ -44,7 +44,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
44
44
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
45
45
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
46
46
  groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
47
- groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
47
+ groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
48
48
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
49
49
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
50
50
  groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
@@ -114,8 +114,8 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
114
114
  signalRepository: import("../Types").SignalRepository;
115
115
  user: import("../Types").Contact | undefined;
116
116
  generateMessageTag: () => string;
117
- query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
118
- waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
117
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
118
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
119
119
  waitForSocketOpen: () => Promise<void>;
120
120
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
121
121
  sendNode: (frame: BinaryNode) => Promise<void>;
@@ -126,5 +126,5 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
126
126
  uploadPreKeysToServerIfRequired: () => Promise<void>;
127
127
  requestPairingCode: (phoneNumber: string) => Promise<string>;
128
128
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
129
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
129
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
130
130
  };
@@ -325,6 +325,12 @@ const makeMessagesSocket = (config) => {
325
325
  if (isStatus && statusJidList) {
326
326
  participantsList.push(...statusJidList);
327
327
  }
328
+ if (!isStatus) {
329
+ additionalAttributes = {
330
+ ...additionalAttributes,
331
+ addressing_mode: (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) || 'pn'
332
+ };
333
+ }
328
334
  const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
329
335
  devices.push(...additionalDevices);
330
336
  }
@@ -341,7 +347,7 @@ const makeMessagesSocket = (config) => {
341
347
  const senderKeyJids = [];
342
348
  // ensure a connection is established with every device
343
349
  for (const { user, device } of devices) {
344
- const jid = (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : 's.whatsapp.net', device);
350
+ const jid = (0, WABinary_1.jidEncode)(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
345
351
  if (!senderKeyMap[jid] || !!participant) {
346
352
  senderKeyJids.push(jid);
347
353
  // store that this person has had the sender keys sent to them
@@ -25,8 +25,8 @@ export declare const makeSocket: (config: SocketConfig) => {
25
25
  signalRepository: import("../Types").SignalRepository;
26
26
  readonly user: import("../Types").Contact | undefined;
27
27
  generateMessageTag: () => string;
28
- query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
29
- waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
28
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
29
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
30
30
  waitForSocketOpen: () => Promise<void>;
31
31
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
32
32
  sendNode: (frame: BinaryNode) => Promise<void>;
@@ -38,5 +38,5 @@ export declare const makeSocket: (config: SocketConfig) => {
38
38
  requestPairingCode: (phoneNumber: string) => Promise<string>;
39
39
  /** Waits for the connection to WA to reach a state */
40
40
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
41
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
41
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
42
42
  };
@@ -117,7 +117,7 @@ const makeSocket = (config) => {
117
117
  let onRecv;
118
118
  let onErr;
119
119
  try {
120
- return await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
120
+ const result = await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
121
121
  onRecv = resolve;
122
122
  onErr = err => {
123
123
  reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
@@ -126,6 +126,7 @@ const makeSocket = (config) => {
126
126
  ws.on('close', onErr); // if the socket closes, you'll never receive the message
127
127
  ws.off('error', onErr);
128
128
  });
129
+ return result;
129
130
  }
130
131
  finally {
131
132
  ws.off(`TAG:${msgId}`, onRecv);
@@ -139,9 +140,10 @@ const makeSocket = (config) => {
139
140
  node.attrs.id = generateMessageTag();
140
141
  }
141
142
  const msgId = node.attrs.id;
142
- const wait = waitForMessage(msgId, timeoutMs);
143
- await sendNode(node);
144
- const result = await wait;
143
+ const [result] = await Promise.all([
144
+ waitForMessage(msgId, timeoutMs),
145
+ sendNode(node)
146
+ ]);
145
147
  if ('tag' in result) {
146
148
  (0, WABinary_1.assertNodeErrorFree)(result);
147
149
  }
@@ -20,8 +20,8 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
20
20
  signalRepository: import("../Types").SignalRepository;
21
21
  user: import("../Types").Contact | undefined;
22
22
  generateMessageTag: () => string;
23
- query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
24
- waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
23
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
24
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
25
25
  waitForSocketOpen: () => Promise<void>;
26
26
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
27
27
  sendNode: (frame: BinaryNode) => Promise<void>;
@@ -32,5 +32,5 @@ export declare const makeUSyncSocket: (config: SocketConfig) => {
32
32
  uploadPreKeysToServerIfRequired: () => Promise<void>;
33
33
  requestPairingCode: (phoneNumber: string) => Promise<string>;
34
34
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
35
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
35
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
36
36
  };
@@ -9,6 +9,8 @@ export type RequestJoinAction = 'created' | 'revoked' | 'rejected';
9
9
  export type RequestJoinMethod = 'invite_link' | 'linked_group_join' | 'non_admin_add' | undefined;
10
10
  export interface GroupMetadata {
11
11
  id: string;
12
+ /** group uses 'lid' or 'pn' to send messages */
13
+ addressingMode: "pn" | "lid";
12
14
  owner: string | undefined;
13
15
  subject: string;
14
16
  /** group subject owner */
@@ -217,7 +217,7 @@ export type MiscMessageGenerationOptions = MinimalRelayOptions & {
217
217
  export type MessageGenerationOptionsFromContent = MiscMessageGenerationOptions & {
218
218
  userJid: string;
219
219
  };
220
- export type WAMediaUploadFunction = (readStream: Readable, opts: {
220
+ export type WAMediaUploadFunction = (encFilePath: string, opts: {
221
221
  fileEncSha256B64: string;
222
222
  mediaType: MediaType;
223
223
  timeoutMs?: number;
@@ -4,7 +4,11 @@ exports.uploadingNecessaryImages = exports.parseProductNode = exports.toProductN
4
4
  exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
5
5
  const boom_1 = require("@hapi/boom");
6
6
  const crypto_1 = require("crypto");
7
+ const fs_1 = require("fs");
8
+ const os_1 = require("os");
9
+ const path_1 = require("path");
7
10
  const WABinary_1 = require("../WABinary");
11
+ const generics_1 = require("./generics");
8
12
  const messages_media_1 = require("./messages-media");
9
13
  const parseCatalogNode = (node) => {
10
14
  const catalogNode = (0, WABinary_1.getBinaryNodeChild)(node, 'product_catalog');
@@ -202,17 +206,21 @@ const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30
202
206
  }
203
207
  const { stream } = await (0, messages_media_1.getStream)(img);
204
208
  const hasher = (0, crypto_1.createHash)('sha256');
205
- const contentBlocks = [];
209
+ const filePath = (0, path_1.join)((0, os_1.tmpdir)(), 'img' + (0, generics_1.generateMessageIDV2)());
210
+ const encFileWriteStream = (0, fs_1.createWriteStream)(filePath);
206
211
  for await (const block of stream) {
207
212
  hasher.update(block);
208
- contentBlocks.push(block);
213
+ encFileWriteStream.write(block);
209
214
  }
210
215
  const sha = hasher.digest('base64');
211
- const { directPath } = await waUploadToServer((0, messages_media_1.toReadable)(Buffer.concat(contentBlocks)), {
216
+ const { directPath } = await waUploadToServer(filePath, {
212
217
  mediaType: 'product-catalog-image',
213
218
  fileEncSha256B64: sha,
214
219
  timeoutMs
215
220
  });
221
+ await fs_1.promises
222
+ .unlink(filePath)
223
+ .catch(err => console.log('Error deleting temp file ', err));
216
224
  return { url: (0, messages_media_1.getUrlFromDirectPath)(directPath) };
217
225
  }));
218
226
  return results;
@@ -38,22 +38,9 @@ function decodeMessageNode(stanza, meId, meLid) {
38
38
  const recipient = stanza.attrs.recipient;
39
39
  const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
40
40
  const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
41
- if ((0, WABinary_1.isJidUser)(from)) {
42
- if (recipient) {
43
- if (!isMe(from)) {
44
- throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
45
- }
46
- chatId = recipient;
47
- }
48
- else {
49
- chatId = from;
50
- }
51
- msgType = 'chat';
52
- author = from;
53
- }
54
- else if ((0, WABinary_1.isLidUser)(from)) {
55
- if (recipient) {
56
- if (!isMeLid(from)) {
41
+ if ((0, WABinary_1.isJidUser)(from) || (0, WABinary_1.isLidUser)(from)) {
42
+ if (recipient && !(0, WABinary_1.isJidMetaIa)(recipient)) {
43
+ if (!isMe(from) && !isMeLid(from)) {
57
44
  throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
58
45
  }
59
46
  chatId = recipient;
@@ -35,7 +35,7 @@ exports.Browsers = {
35
35
  };
36
36
  const getPlatformId = (browser) => {
37
37
  const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
38
- return platformType ? platformType.toString().charCodeAt(0).toString() : '49'; //chrome
38
+ return platformType ? platformType.toString() : '1'; //chrome
39
39
  };
40
40
  exports.getPlatformId = getPlatformId;
41
41
  exports.BufferJSON = {
@@ -62,13 +62,12 @@ type EncryptedStreamOptions = {
62
62
  };
63
63
  export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
64
64
  mediaKey: Buffer<ArrayBufferLike>;
65
- encWriteStream: Readable;
66
- bodyPath: string | undefined;
65
+ originalFilePath: string | undefined;
66
+ encFilePath: string;
67
67
  mac: Buffer<ArrayBuffer>;
68
68
  fileEncSha256: Buffer<ArrayBufferLike>;
69
69
  fileSha256: Buffer<ArrayBufferLike>;
70
70
  fileLength: number;
71
- didSaveToTmpPath: boolean;
72
71
  }>;
73
72
  export type MediaDownloadOptions = {
74
73
  startByte?: number;
@@ -309,7 +309,7 @@ async function generateThumbnail(file, mediaType, options) {
309
309
  }
310
310
  }
311
311
  else if (mediaType === 'video') {
312
- const imgFilename = (0, path_1.join)(getTmpFilesDirectory(), (0, generics_1.generateMessageID)() + '.jpg');
312
+ const imgFilename = (0, path_1.join)(getTmpFilesDirectory(), (0, generics_1.generateMessageIDV2)() + '.jpg');
313
313
  try {
314
314
  await extractVideoThumb(file, imgFilename, '00:00:00', { width: 32, height: 32 });
315
315
  const buff = await fs_1.promises.readFile(imgFilename);
@@ -331,27 +331,29 @@ const getHttpStream = async (url, options = {}) => {
331
331
  };
332
332
  exports.getHttpStream = getHttpStream;
333
333
  const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
334
+ var _a, _b;
334
335
  const { stream, type } = await (0, exports.getStream)(media, opts);
335
336
  logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
336
337
  const mediaKey = Crypto.randomBytes(32);
337
338
  const { cipherKey, iv, macKey } = await getMediaKeys(mediaKey, mediaType);
338
- const encWriteStream = new stream_1.Readable({ read: () => { } });
339
- let bodyPath;
340
- let writeStream;
341
- let didSaveToTmpPath = false;
342
- if (type === 'file') {
343
- bodyPath = media.url.toString();
344
- }
345
- else if (saveOriginalFileIfRequired) {
346
- bodyPath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageID)());
347
- writeStream = (0, fs_1.createWriteStream)(bodyPath);
348
- didSaveToTmpPath = true;
339
+ const encFilePath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageIDV2)() + '-enc');
340
+ const encFileWriteStream = (0, fs_1.createWriteStream)(encFilePath);
341
+ let originalFileStream;
342
+ let originalFilePath;
343
+ if (saveOriginalFileIfRequired) {
344
+ originalFilePath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageIDV2)() + '-original');
345
+ originalFileStream = (0, fs_1.createWriteStream)(originalFilePath);
349
346
  }
350
347
  let fileLength = 0;
351
348
  const aes = Crypto.createCipheriv('aes-256-cbc', cipherKey, iv);
352
- let hmac = Crypto.createHmac('sha256', macKey).update(iv);
353
- let sha256Plain = Crypto.createHash('sha256');
354
- let sha256Enc = Crypto.createHash('sha256');
349
+ const hmac = Crypto.createHmac('sha256', macKey).update(iv);
350
+ const sha256Plain = Crypto.createHash('sha256');
351
+ const sha256Enc = Crypto.createHash('sha256');
352
+ const onChunk = (buff) => {
353
+ sha256Enc.update(buff);
354
+ hmac.update(buff);
355
+ encFileWriteStream.write(buff);
356
+ };
355
357
  try {
356
358
  for await (const data of stream) {
357
359
  fileLength += data.length;
@@ -362,57 +364,54 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
362
364
  data: { media, type }
363
365
  });
364
366
  }
365
- sha256Plain = sha256Plain.update(data);
366
- if (writeStream && !writeStream.write(data)) {
367
- await (0, events_1.once)(writeStream, 'drain');
367
+ if (originalFileStream) {
368
+ if (!originalFileStream.write(data)) {
369
+ await (0, events_1.once)(originalFileStream, 'drain');
370
+ }
368
371
  }
372
+ sha256Plain.update(data);
369
373
  onChunk(aes.update(data));
370
374
  }
371
375
  onChunk(aes.final());
372
376
  const mac = hmac.digest().slice(0, 10);
373
- sha256Enc = sha256Enc.update(mac);
377
+ sha256Enc.update(mac);
374
378
  const fileSha256 = sha256Plain.digest();
375
379
  const fileEncSha256 = sha256Enc.digest();
376
- encWriteStream.push(mac);
377
- encWriteStream.push(null);
378
- writeStream === null || writeStream === void 0 ? void 0 : writeStream.end();
380
+ encFileWriteStream.write(mac);
381
+ encFileWriteStream.end();
382
+ (_a = originalFileStream === null || originalFileStream === void 0 ? void 0 : originalFileStream.end) === null || _a === void 0 ? void 0 : _a.call(originalFileStream);
379
383
  stream.destroy();
380
384
  logger === null || logger === void 0 ? void 0 : logger.debug('encrypted data successfully');
381
385
  return {
382
386
  mediaKey,
383
- encWriteStream,
384
- bodyPath,
387
+ originalFilePath,
388
+ encFilePath,
385
389
  mac,
386
390
  fileEncSha256,
387
391
  fileSha256,
388
- fileLength,
389
- didSaveToTmpPath
392
+ fileLength
390
393
  };
391
394
  }
392
395
  catch (error) {
393
396
  // destroy all streams with error
394
- encWriteStream.destroy();
395
- writeStream === null || writeStream === void 0 ? void 0 : writeStream.destroy();
397
+ encFileWriteStream.destroy();
398
+ (_b = originalFileStream === null || originalFileStream === void 0 ? void 0 : originalFileStream.destroy) === null || _b === void 0 ? void 0 : _b.call(originalFileStream);
396
399
  aes.destroy();
397
400
  hmac.destroy();
398
401
  sha256Plain.destroy();
399
402
  sha256Enc.destroy();
400
403
  stream.destroy();
401
- if (didSaveToTmpPath) {
402
- try {
403
- await fs_1.promises.unlink(bodyPath);
404
- }
405
- catch (err) {
406
- logger === null || logger === void 0 ? void 0 : logger.error({ err }, 'failed to save to tmp path');
404
+ try {
405
+ await fs_1.promises.unlink(encFilePath);
406
+ if (originalFilePath) {
407
+ await fs_1.promises.unlink(originalFilePath);
407
408
  }
408
409
  }
410
+ catch (err) {
411
+ logger === null || logger === void 0 ? void 0 : logger.error({ err }, 'failed deleting tmp files');
412
+ }
409
413
  throw error;
410
414
  }
411
- function onChunk(buff) {
412
- sha256Enc = sha256Enc.update(buff);
413
- hmac = hmac.update(buff);
414
- encWriteStream.push(buff);
415
- }
416
415
  };
417
416
  exports.encryptedStream = encryptedStream;
418
417
  const DEF_HOST = 'mmg.whatsapp.net';
@@ -532,7 +531,7 @@ function extensionForMediaMessage(message) {
532
531
  return extension;
533
532
  }
534
533
  const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
535
- return async (stream, { mediaType, fileEncSha256B64, timeoutMs }) => {
534
+ return async (filePath, { mediaType, fileEncSha256B64, timeoutMs }) => {
536
535
  var _a, _b;
537
536
  // send a query JSON to obtain the url & auth token to upload our media
538
537
  let uploadInfo = await refreshMediaConn(false);
@@ -546,8 +545,9 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
546
545
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
547
546
  let result;
548
547
  try {
549
- const body = await axios_1.default.post(url, stream, {
548
+ const body = await axios_1.default.post(url, (0, fs_1.createReadStream)(filePath), {
550
549
  ...options,
550
+ maxRedirects: 0,
551
551
  headers: {
552
552
  ...options.headers || {},
553
553
  'Content-Type': 'application/octet-stream',
@@ -111,7 +111,7 @@ const prepareWAMessageMedia = async (message, options) => {
111
111
  const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true;
112
112
  const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
113
113
  const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
114
- const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath } = await (0, messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
114
+ const { mediaKey, encFilePath, originalFilePath, fileEncSha256, fileSha256, fileLength } = await (0, messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
115
115
  logger,
116
116
  saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
117
117
  opts: options.options
@@ -120,14 +120,14 @@ const prepareWAMessageMedia = async (message, options) => {
120
120
  const fileEncSha256B64 = fileEncSha256.toString('base64');
121
121
  const [{ mediaUrl, directPath }] = await Promise.all([
122
122
  (async () => {
123
- const result = await options.upload(encWriteStream, { fileEncSha256B64, mediaType, timeoutMs: options.mediaUploadTimeoutMs });
123
+ const result = await options.upload(encFilePath, { fileEncSha256B64, mediaType, timeoutMs: options.mediaUploadTimeoutMs });
124
124
  logger === null || logger === void 0 ? void 0 : logger.debug({ mediaType, cacheableKey }, 'uploaded media');
125
125
  return result;
126
126
  })(),
127
127
  (async () => {
128
128
  try {
129
129
  if (requiresThumbnailComputation) {
130
- const { thumbnail, originalImageDimensions } = await (0, messages_media_1.generateThumbnail)(bodyPath, mediaType, options);
130
+ const { thumbnail, originalImageDimensions } = await (0, messages_media_1.generateThumbnail)(originalFilePath, mediaType, options);
131
131
  uploadData.jpegThumbnail = thumbnail;
132
132
  if (!uploadData.width && originalImageDimensions) {
133
133
  uploadData.width = originalImageDimensions.width;
@@ -137,11 +137,11 @@ const prepareWAMessageMedia = async (message, options) => {
137
137
  logger === null || logger === void 0 ? void 0 : logger.debug('generated thumbnail');
138
138
  }
139
139
  if (requiresDurationComputation) {
140
- uploadData.seconds = await (0, messages_media_1.getAudioDuration)(bodyPath);
140
+ uploadData.seconds = await (0, messages_media_1.getAudioDuration)(originalFilePath);
141
141
  logger === null || logger === void 0 ? void 0 : logger.debug('computed audio duration');
142
142
  }
143
143
  if (requiresWaveformProcessing) {
144
- uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(bodyPath, logger);
144
+ uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(originalFilePath, logger);
145
145
  logger === null || logger === void 0 ? void 0 : logger.debug('processed waveform');
146
146
  }
147
147
  if (requiresAudioBackground) {
@@ -155,17 +155,15 @@ const prepareWAMessageMedia = async (message, options) => {
155
155
  })(),
156
156
  ])
157
157
  .finally(async () => {
158
- encWriteStream.destroy();
159
- // remove tmp files
160
- if (didSaveToTmpPath && bodyPath) {
161
- try {
162
- await fs_1.promises.access(bodyPath);
163
- await fs_1.promises.unlink(bodyPath);
164
- logger === null || logger === void 0 ? void 0 : logger.debug('removed tmp file');
165
- }
166
- catch (error) {
167
- logger === null || logger === void 0 ? void 0 : logger.warn('failed to remove tmp file');
158
+ try {
159
+ await fs_1.promises.unlink(encFilePath);
160
+ if (originalFilePath) {
161
+ await fs_1.promises.unlink(originalFilePath);
168
162
  }
163
+ logger === null || logger === void 0 ? void 0 : logger.debug('removed tmp files');
164
+ }
165
+ catch (error) {
166
+ logger === null || logger === void 0 ? void 0 : logger.warn('failed to remove tmp file');
169
167
  }
170
168
  });
171
169
  const obj = Types_1.WAProto.Message.fromObject({
@@ -497,7 +495,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
497
495
  key: {
498
496
  remoteJid: jid,
499
497
  fromMe: true,
500
- id: (options === null || options === void 0 ? void 0 : options.messageId) || (0, generics_1.generateMessageID)(),
498
+ id: (options === null || options === void 0 ? void 0 : options.messageId) || (0, generics_1.generateMessageIDV2)(),
501
499
  },
502
500
  message: message,
503
501
  messageTimestamp: timestamp,
@@ -156,10 +156,11 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
156
156
  throw new Error('invalid jid pair: ' + i + ', ' + j);
157
157
  };
158
158
  const readAdJid = () => {
159
- const agent = readByte();
159
+ const rawDomainType = readByte();
160
+ const domainType = Number(rawDomainType);
160
161
  const device = readByte();
161
162
  const user = readString(readByte());
162
- return (0, jid_utils_1.jidEncode)(user, agent === 0 ? 's.whatsapp.net' : 'lid', device);
163
+ return (0, jid_utils_1.jidEncode)(user, domainType === 0 || domainType === 128 ? 's.whatsapp.net' : 'lid', device);
163
164
  };
164
165
  const readString = (tag) => {
165
166
  if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
@@ -17,6 +17,8 @@ export declare const jidEncode: (user: string | number | null, server: JidServer
17
17
  export declare const jidDecode: (jid: string | undefined) => FullJid | undefined;
18
18
  /** is the jid a user */
19
19
  export declare const areJidsSameUser: (jid1: string | undefined, jid2: string | undefined) => boolean;
20
+ /** is the jid Meta IA */
21
+ export declare const isJidMetaIa: (jid: string | undefined) => boolean | undefined;
20
22
  /** is the jid a user */
21
23
  export declare const isJidUser: (jid: string | undefined) => boolean | undefined;
22
24
  /** is the jid a group */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jidNormalizedUser = exports.isJidBot = exports.isJidNewsletter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.META_AI_JID = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
3
+ exports.jidNormalizedUser = exports.isJidBot = exports.isJidNewsletter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.isJidMetaIa = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.META_AI_JID = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
4
4
  exports.S_WHATSAPP_NET = '@s.whatsapp.net';
5
5
  exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
6
6
  exports.SERVER_JID = 'server@c.us';
@@ -34,6 +34,9 @@ const areJidsSameUser = (jid1, jid2) => {
34
34
  return (((_a = (0, exports.jidDecode)(jid1)) === null || _a === void 0 ? void 0 : _a.user) === ((_b = (0, exports.jidDecode)(jid2)) === null || _b === void 0 ? void 0 : _b.user));
35
35
  };
36
36
  exports.areJidsSameUser = areJidsSameUser;
37
+ /** is the jid Meta IA */
38
+ const isJidMetaIa = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@bot'));
39
+ exports.isJidMetaIa = isJidMetaIa;
37
40
  /** is the jid a user */
38
41
  const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));
39
42
  exports.isJidUser = isJidUser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d0v3riz/baileys",
3
- "version": "6.7.17",
3
+ "version": "6.7.19",
4
4
  "description": "A WebSockets library for interacting with WhatsApp Web",
5
5
  "keywords": [
6
6
  "whatsapp",