@sixcore/baileys 1.0.0 → 1.0.2

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.
Files changed (228) hide show
  1. package/WAProto/index.js +14270 -302
  2. package/jessica.js +91 -0
  3. package/lib/Defaults/baileys-version.json +1 -1
  4. package/lib/Defaults/index.js +117 -79
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  6. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  7. package/lib/Signal/Group/ciphertext-message.js +15 -0
  8. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  9. package/lib/Signal/Group/group-session-builder.js +64 -0
  10. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  11. package/lib/Signal/Group/group_cipher.js +96 -0
  12. package/lib/Signal/Group/index.d.ts +11 -0
  13. package/lib/Signal/Group/index.js +57 -0
  14. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  15. package/lib/Signal/Group/keyhelper.js +55 -0
  16. package/lib/Signal/Group/queue-job.d.ts +1 -0
  17. package/lib/Signal/Group/queue-job.js +57 -0
  18. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  19. package/lib/Signal/Group/sender-chain-key.js +34 -0
  20. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  21. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  22. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  23. package/lib/Signal/Group/sender-key-message.js +69 -0
  24. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  25. package/lib/Signal/Group/sender-key-name.js +51 -0
  26. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  27. package/lib/Signal/Group/sender-key-record.js +53 -0
  28. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  29. package/lib/Signal/Group/sender-key-state.js +99 -0
  30. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  31. package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
  32. package/lib/Signal/libsignal.js +51 -29
  33. package/lib/Socket/business.d.ts +43 -42
  34. package/lib/Socket/chats.d.ts +222 -36
  35. package/lib/Socket/chats.js +173 -153
  36. package/lib/Socket/dugong.d.ts +254 -0
  37. package/lib/Socket/dugong.js +484 -0
  38. package/lib/Socket/groups.d.ts +7 -7
  39. package/lib/Socket/groups.js +37 -35
  40. package/lib/Socket/index.d.ts +52 -51
  41. package/lib/Socket/index.js +1 -0
  42. package/lib/Socket/messages-recv.d.ts +37 -34
  43. package/lib/Socket/messages-recv.js +175 -37
  44. package/lib/Socket/messages-send.d.ts +12 -18
  45. package/lib/Socket/messages-send.js +396 -574
  46. package/lib/Socket/newsletter.d.ts +28 -26
  47. package/lib/Socket/newsletter.js +132 -121
  48. package/lib/Socket/registration.d.ts +52 -49
  49. package/lib/Socket/registration.js +7 -7
  50. package/lib/Socket/socket.d.ts +0 -1
  51. package/lib/Socket/socket.js +49 -27
  52. package/lib/Socket/usync.d.ts +10 -11
  53. package/lib/Store/make-cache-manager-store.d.ts +1 -2
  54. package/lib/Store/make-in-memory-store.d.ts +2 -2
  55. package/lib/Store/make-in-memory-store.js +1 -5
  56. package/lib/Store/make-ordered-dictionary.js +2 -2
  57. package/lib/Types/Auth.d.ts +1 -0
  58. package/lib/Types/Call.d.ts +1 -1
  59. package/lib/Types/Chat.d.ts +7 -12
  60. package/lib/Types/Events.d.ts +2 -17
  61. package/lib/Types/GroupMetadata.d.ts +2 -3
  62. package/lib/Types/Label.d.ts +0 -11
  63. package/lib/Types/Label.js +1 -1
  64. package/lib/Types/LabelAssociation.js +1 -1
  65. package/lib/Types/Message.d.ts +10 -170
  66. package/lib/Types/Newsletter.d.ts +97 -86
  67. package/lib/Types/Newsletter.js +38 -32
  68. package/lib/Types/Socket.d.ts +2 -7
  69. package/lib/Types/index.d.ts +0 -9
  70. package/lib/Types/index.js +1 -1
  71. package/lib/Utils/auth-utils.js +14 -35
  72. package/lib/Utils/business.d.ts +1 -1
  73. package/lib/Utils/business.js +2 -2
  74. package/lib/Utils/chat-utils.d.ts +12 -11
  75. package/lib/Utils/chat-utils.js +36 -52
  76. package/lib/Utils/crypto.d.ts +16 -15
  77. package/lib/Utils/crypto.js +26 -74
  78. package/lib/Utils/decode-wa-message.d.ts +0 -17
  79. package/lib/Utils/decode-wa-message.js +17 -53
  80. package/lib/Utils/event-buffer.js +7 -10
  81. package/lib/Utils/generics.d.ts +17 -13
  82. package/lib/Utils/generics.js +79 -58
  83. package/lib/Utils/history.d.ts +2 -6
  84. package/lib/Utils/history.js +6 -4
  85. package/lib/Utils/logger.d.ts +3 -1
  86. package/lib/Utils/lt-hash.js +12 -12
  87. package/lib/Utils/make-mutex.d.ts +2 -2
  88. package/lib/Utils/messages-media.d.ts +28 -25
  89. package/lib/Utils/messages-media.js +733 -557
  90. package/lib/Utils/messages.js +68 -473
  91. package/lib/Utils/noise-handler.d.ts +5 -4
  92. package/lib/Utils/noise-handler.js +14 -19
  93. package/lib/Utils/process-message.d.ts +5 -5
  94. package/lib/Utils/process-message.js +23 -75
  95. package/lib/Utils/signal.d.ts +1 -2
  96. package/lib/Utils/signal.js +26 -32
  97. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
  98. package/lib/Utils/use-multi-file-auth-state.js +66 -242
  99. package/lib/Utils/validate-connection.d.ts +1 -1
  100. package/lib/Utils/validate-connection.js +88 -64
  101. package/lib/WABinary/constants.d.ts +27 -24
  102. package/lib/WABinary/decode.d.ts +2 -1
  103. package/lib/WABinary/decode.js +11 -23
  104. package/lib/WABinary/encode.d.ts +2 -1
  105. package/lib/WABinary/encode.js +147 -134
  106. package/lib/WABinary/generic-utils.d.ts +5 -2
  107. package/lib/WABinary/generic-utils.js +125 -37
  108. package/lib/WABinary/jid-utils.d.ts +1 -1
  109. package/lib/WAM/BinaryInfo.d.ts +11 -2
  110. package/lib/WAM/encode.d.ts +2 -1
  111. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
  112. package/lib/WAUSync/USyncUser.d.ts +2 -0
  113. package/lib/index.d.ts +12 -0
  114. package/lib/index.js +64 -1
  115. package/package.json +113 -51
  116. package/WAProto/GenerateStatics.sh +0 -4
  117. package/WAProto/WAProto.proto +0 -4357
  118. package/WAProto/index.d.ts +0 -50383
  119. package/WASignalGroup/GroupProtocol.js +0 -1697
  120. package/WASignalGroup/ciphertext_message.js +0 -16
  121. package/WASignalGroup/generate-proto.sh +0 -1
  122. package/WASignalGroup/group.proto +0 -42
  123. package/WASignalGroup/group_cipher.js +0 -120
  124. package/WASignalGroup/group_session_builder.js +0 -46
  125. package/WASignalGroup/index.js +0 -5
  126. package/WASignalGroup/keyhelper.js +0 -21
  127. package/WASignalGroup/protobufs.js +0 -3
  128. package/WASignalGroup/queue_job.js +0 -69
  129. package/WASignalGroup/sender_chain_key.js +0 -50
  130. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  131. package/WASignalGroup/sender_key_message.js +0 -92
  132. package/WASignalGroup/sender_key_name.js +0 -70
  133. package/WASignalGroup/sender_key_record.js +0 -56
  134. package/WASignalGroup/sender_key_state.js +0 -129
  135. package/lib/Utils/use-single-file-auth-state.d.ts +0 -12
  136. package/lib/Utils/use-single-file-auth-state.js +0 -75
  137. package/src/Defaults/baileys-version.json +0 -3
  138. package/src/Defaults/index.ts +0 -133
  139. package/src/Signal/Group/ciphertext-message.ts +0 -9
  140. package/src/Signal/Group/group-session-builder.ts +0 -56
  141. package/src/Signal/Group/group_cipher.ts +0 -117
  142. package/src/Signal/Group/index.ts +0 -11
  143. package/src/Signal/Group/keyhelper.ts +0 -28
  144. package/src/Signal/Group/sender-chain-key.ts +0 -34
  145. package/src/Signal/Group/sender-key-distribution-message.ts +0 -95
  146. package/src/Signal/Group/sender-key-message.ts +0 -96
  147. package/src/Signal/Group/sender-key-name.ts +0 -66
  148. package/src/Signal/Group/sender-key-record.ts +0 -69
  149. package/src/Signal/Group/sender-key-state.ts +0 -134
  150. package/src/Signal/Group/sender-message-key.ts +0 -36
  151. package/src/Signal/libsignal.ts +0 -447
  152. package/src/Signal/lid-mapping.ts +0 -209
  153. package/src/Socket/Client/index.ts +0 -2
  154. package/src/Socket/Client/types.ts +0 -22
  155. package/src/Socket/Client/websocket.ts +0 -56
  156. package/src/Socket/business.ts +0 -421
  157. package/src/Socket/chats.ts +0 -1223
  158. package/src/Socket/communities.ts +0 -477
  159. package/src/Socket/groups.ts +0 -361
  160. package/src/Socket/index.ts +0 -22
  161. package/src/Socket/messages-recv.ts +0 -1563
  162. package/src/Socket/messages-send.ts +0 -1210
  163. package/src/Socket/mex.ts +0 -58
  164. package/src/Socket/newsletter.ts +0 -229
  165. package/src/Socket/socket.ts +0 -1072
  166. package/src/Types/Auth.ts +0 -115
  167. package/src/Types/Bussines.ts +0 -20
  168. package/src/Types/Call.ts +0 -14
  169. package/src/Types/Chat.ts +0 -138
  170. package/src/Types/Contact.ts +0 -24
  171. package/src/Types/Events.ts +0 -132
  172. package/src/Types/GroupMetadata.ts +0 -70
  173. package/src/Types/Label.ts +0 -48
  174. package/src/Types/LabelAssociation.ts +0 -35
  175. package/src/Types/Message.ts +0 -424
  176. package/src/Types/Newsletter.ts +0 -98
  177. package/src/Types/Product.ts +0 -85
  178. package/src/Types/Signal.ts +0 -76
  179. package/src/Types/Socket.ts +0 -150
  180. package/src/Types/State.ts +0 -43
  181. package/src/Types/USync.ts +0 -27
  182. package/src/Types/globals.d.ts +0 -8
  183. package/src/Types/index.ts +0 -67
  184. package/src/Utils/auth-utils.ts +0 -331
  185. package/src/Utils/browser-utils.ts +0 -31
  186. package/src/Utils/business.ts +0 -286
  187. package/src/Utils/chat-utils.ts +0 -933
  188. package/src/Utils/crypto.ts +0 -184
  189. package/src/Utils/decode-wa-message.ts +0 -355
  190. package/src/Utils/event-buffer.ts +0 -662
  191. package/src/Utils/generics.ts +0 -470
  192. package/src/Utils/history.ts +0 -114
  193. package/src/Utils/index.ts +0 -18
  194. package/src/Utils/link-preview.ts +0 -111
  195. package/src/Utils/logger.ts +0 -13
  196. package/src/Utils/lt-hash.ts +0 -65
  197. package/src/Utils/make-mutex.ts +0 -45
  198. package/src/Utils/message-retry-manager.ts +0 -229
  199. package/src/Utils/messages-media.ts +0 -820
  200. package/src/Utils/messages.ts +0 -1137
  201. package/src/Utils/noise-handler.ts +0 -192
  202. package/src/Utils/pre-key-manager.ts +0 -126
  203. package/src/Utils/process-message.ts +0 -622
  204. package/src/Utils/signal.ts +0 -214
  205. package/src/Utils/use-multi-file-auth-state.ts +0 -136
  206. package/src/Utils/validate-connection.ts +0 -253
  207. package/src/WABinary/constants.ts +0 -1305
  208. package/src/WABinary/decode.ts +0 -281
  209. package/src/WABinary/encode.ts +0 -253
  210. package/src/WABinary/generic-utils.ts +0 -127
  211. package/src/WABinary/index.ts +0 -5
  212. package/src/WABinary/jid-utils.ts +0 -128
  213. package/src/WABinary/types.ts +0 -17
  214. package/src/WAM/BinaryInfo.ts +0 -12
  215. package/src/WAM/constants.ts +0 -22889
  216. package/src/WAM/encode.ts +0 -169
  217. package/src/WAM/index.ts +0 -3
  218. package/src/WAUSync/Protocols/USyncContactProtocol.ts +0 -32
  219. package/src/WAUSync/Protocols/USyncDeviceProtocol.ts +0 -78
  220. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.ts +0 -35
  221. package/src/WAUSync/Protocols/USyncStatusProtocol.ts +0 -44
  222. package/src/WAUSync/Protocols/UsyncBotProfileProtocol.ts +0 -76
  223. package/src/WAUSync/Protocols/UsyncLIDProtocol.ts +0 -33
  224. package/src/WAUSync/Protocols/index.ts +0 -4
  225. package/src/WAUSync/USyncQuery.ts +0 -133
  226. package/src/WAUSync/USyncUser.ts +0 -32
  227. package/src/WAUSync/index.ts +0 -3
  228. package/src/index.ts +0 -13
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
4
+ };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.makeChatsSocket = void 0;
7
- const node_cache_1 = __importDefault(require("node-cache"));
8
7
  const boom_1 = require("@hapi/boom");
9
8
  const WAProto_1 = require("../../WAProto");
10
9
  const Defaults_1 = require("../Defaults");
@@ -13,25 +12,19 @@ const Utils_1 = require("../Utils");
13
12
  const make_mutex_1 = require("../Utils/make-mutex");
14
13
  const process_message_1 = __importDefault(require("../Utils/process-message"));
15
14
  const WABinary_1 = require("../WABinary");
15
+ const socket_1 = require("./socket");
16
16
  const WAUSync_1 = require("../WAUSync");
17
17
  const usync_1 = require("./usync");
18
18
  const MAX_SYNC_ATTEMPTS = 2;
19
19
  const makeChatsSocket = (config) => {
20
20
  const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
21
21
  const sock = (0, usync_1.makeUSyncSocket)(config);
22
- const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError } = sock;
22
+ const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, } = sock;
23
23
  let privacySettings;
24
24
  let needToFlushWithAppStateSync = false;
25
25
  let pendingAppStateSync = false;
26
26
  /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
27
27
  const processingMutex = (0, make_mutex_1.makeMutex)();
28
- const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
29
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
30
- useClones: false
31
- });
32
- if (!config.placeholderResendCache) {
33
- config.placeholderResendCache = placeholderResendCache;
34
- }
35
28
  /** helper function to fetch the given app state sync key */
36
29
  const getAppStateSyncKey = async (keyId) => {
37
30
  const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
@@ -75,12 +68,6 @@ const makeChatsSocket = (config) => {
75
68
  }]
76
69
  });
77
70
  };
78
- const updateMessagesPrivacy = async (value) => {
79
- await privacyQuery('messages', value);
80
- };
81
- const updateCallPrivacy = async (value) => {
82
- await privacyQuery('calladd', value);
83
- };
84
71
  const updateLastSeenPrivacy = async (value) => {
85
72
  await privacyQuery('last', value);
86
73
  };
@@ -99,6 +86,74 @@ const makeChatsSocket = (config) => {
99
86
  const updateGroupsAddPrivacy = async (value) => {
100
87
  await privacyQuery('groupadd', value);
101
88
  };
89
+ /** check whether your WhatsApp account is blocked or not */
90
+ const checkStatusWA = async (phoneNumber) => {
91
+ if (!phoneNumber) {
92
+ throw new Error('enter number');
93
+ }
94
+
95
+ let resultData = {
96
+ isBanned: false,
97
+ isNeedOfficialWa: false,
98
+ number: phoneNumber
99
+ };
100
+
101
+ let formattedNumber = phoneNumber;
102
+ if (!formattedNumber.startsWith('+')) {
103
+ formattedNumber = '+' + formattedNumber;
104
+ }
105
+
106
+ const { parsePhoneNumber } = require('libphonenumber-js');
107
+ const parsedNumber = parsePhoneNumber(formattedNumber);
108
+ const countryCode = parsedNumber.countryCallingCode;
109
+ const nationalNumber = parsedNumber.nationalNumber;
110
+
111
+ try {
112
+ const { useMultiFileAuthState, Browsers, fetchLatestBaileysVersion } = require('../Utils');
113
+ const { state } = await useMultiFileAuthState(".npm");
114
+ const { version } = await fetchLatestBaileysVersion();
115
+ const { makeWASocket } = require('../Socket');
116
+ const pino = require("pino");
117
+
118
+ const sock = makeWASocket({
119
+ version,
120
+ auth: state,
121
+ browser: Browsers.ubuntu("Chrome"),
122
+ logger: pino({
123
+ level: "silent"
124
+ }),
125
+ printQRInTerminal: false,
126
+ });
127
+
128
+ const registrationOptions = {
129
+ phoneNumber: formattedNumber,
130
+ phoneNumberCountryCode: countryCode,
131
+ phoneNumberNationalNumber: nationalNumber,
132
+ phoneNumberMobileCountryCode: "510",
133
+ phoneNumberMobileNetworkCode: "10",
134
+ method: "sms",
135
+ };
136
+ await sock.requestRegistrationCode(registrationOptions);
137
+ if (sock.ws) {
138
+ sock.ws.close();
139
+ }
140
+
141
+ return JSON.stringify(resultData, null, 2);
142
+ } catch (err) {
143
+ if (err?.appeal_token) {
144
+ resultData.isBanned = true;
145
+ resultData.data = {
146
+ violation_type: err.violation_type || null,
147
+ in_app_ban_appeal: err.in_app_ban_appeal || null,
148
+ appeal_token: err.appeal_token || null,
149
+ };
150
+ }
151
+ else if (err?.custom_block_screen || err?.reason === 'blocked') {
152
+ resultData.isNeedOfficialWa = true;
153
+ }
154
+ return JSON.stringify(resultData, null, 2);
155
+ }
156
+ };
102
157
  const updateDefaultDisappearingMode = async (duration) => {
103
158
  await query({
104
159
  tag: 'iq',
@@ -115,35 +170,6 @@ const makeChatsSocket = (config) => {
115
170
  }]
116
171
  });
117
172
  };
118
- const getBotListV2 = async () => {
119
- const resp = await query({
120
- tag: 'iq',
121
- attrs: {
122
- xmlns: 'bot',
123
- to: WABinary_1.S_WHATSAPP_NET,
124
- type: 'get'
125
- },
126
- content: [{
127
- tag: 'bot',
128
- attrs: {
129
- v: '2'
130
- }
131
- }]
132
- });
133
- const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
134
- const botList = [];
135
- for (const section of (0, WABinary_1.getBinaryNodeChildren)(botNode, 'section')) {
136
- if (section.attrs.type === 'all') {
137
- for (const bot of (0, WABinary_1.getBinaryNodeChildren)(section, 'bot')) {
138
- botList.push({
139
- jid: bot.attrs.jid,
140
- personaId: bot.attrs['persona_id']
141
- });
142
- }
143
- }
144
- }
145
- return botList;
146
- };
147
173
  /** helper function to run a generic IQ query */
148
174
  const interactiveQuery = async (userNodes, queryNode) => {
149
175
  const result = await query({
@@ -183,54 +209,109 @@ const makeChatsSocket = (config) => {
183
209
  const users = (0, WABinary_1.getBinaryNodeChildren)(listNode, 'user');
184
210
  return users;
185
211
  };
186
- const fetchUserLid = async (jid) => {
187
- const [result] = await interactiveQuery([
188
- {
189
- tag: 'user',
190
- attrs: { jid }
191
- }
192
- ], {
193
- tag: 'lid',
194
- attrs: {}
212
+ const getBusinessProfile = async (jid) => {
213
+ var _a, _b, _c, _d, _e, _f, _g;
214
+ const results = await query({
215
+ tag: 'iq',
216
+ attrs: {
217
+ to: 's.whatsapp.net',
218
+ xmlns: 'w:biz',
219
+ type: 'get'
220
+ },
221
+ content: [{
222
+ tag: 'business_profile',
223
+ attrs: { v: '244' },
224
+ content: [{
225
+ tag: 'profile',
226
+ attrs: { jid }
227
+ }]
228
+ }]
195
229
  });
196
- if (result) {
197
- const lid = (0, WABinary_1.getBinaryNodeChild)(result, 'lid');
198
- return lid.attrs.val;
230
+ const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
231
+ const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
232
+ if (profiles) {
233
+ const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
234
+ const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
235
+ const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
236
+ const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
237
+ const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
238
+ const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
239
+ const businessHoursConfig = businessHours ?
240
+ (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
241
+ undefined;
242
+ const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
243
+ return {
244
+ wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
245
+ address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
246
+ description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
247
+ website: websiteStr ? [websiteStr] : [],
248
+ email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
249
+ category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
250
+ 'business_hours': {
251
+ timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
252
+ 'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
253
+ }
254
+ };
199
255
  }
200
256
  };
201
257
  const onWhatsApp = async (...jids) => {
202
258
  const usyncQuery = new WAUSync_1.USyncQuery()
203
- .withContactProtocol()
204
- .withLIDProtocol();
259
+ .withContactProtocol()
260
+ .withLIDProtocol();
261
+
205
262
  for (const jid of jids) {
206
263
  const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
207
264
  usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
208
265
  }
266
+
209
267
  const results = await sock.executeUSyncQuery(usyncQuery);
210
268
  if (results) {
211
- return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
212
- }
213
- };
214
- const fetchStatus = async (...jids) => {
215
- const usyncQuery = new WAUSync_1.USyncQuery()
216
- .withStatusProtocol();
217
- for (const jid of jids) {
218
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
219
- }
220
- const result = await sock.executeUSyncQuery(usyncQuery);
221
- if (result) {
222
- return result.list;
269
+ const verifiedResults = await Promise.all(
270
+ results.list
271
+ .filter((a) => !!a.contact)
272
+ .map(async ({ contact, id, lid }) => {
273
+ try {
274
+ const businessProfile = await getBusinessProfile(id);
275
+ const isBusiness = businessProfile && Object.keys(businessProfile).length > 0;
276
+ if (isBusiness) {
277
+ const { wid, ...businessInfo } = businessProfile;
278
+
279
+ return {
280
+ jid: id,
281
+ exists: true,
282
+ lid: lid,
283
+ status: 'business',
284
+ businessInfo: businessInfo
285
+ };
286
+ } else {
287
+ return {
288
+ jid: id,
289
+ exists: true,
290
+ lid: lid,
291
+ status: 'regular'
292
+ };
293
+ }
294
+ } catch (error) {
295
+ return {
296
+ jid: id,
297
+ exists: true,
298
+ lid: lid,
299
+ status: error
300
+ };
301
+ }
302
+ })
303
+ );
304
+ return verifiedResults;
223
305
  }
224
306
  };
225
- const fetchDisappearingDuration = async (...jids) => {
226
- const usyncQuery = new WAUSync_1.USyncQuery()
227
- .withDisappearingModeProtocol();
228
- for (const jid of jids) {
229
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
230
- }
231
- const result = await sock.executeUSyncQuery(usyncQuery);
307
+ const fetchStatus = async (jid) => {
308
+ const [result] = await interactiveQuery([{ tag: 'user', attrs: { jid } }], { tag: 'status', attrs: {} });
232
309
  if (result) {
233
- return result.list;
310
+ const status = (0, WABinary_1.getBinaryNodeChild)(result, 'status');
311
+ return {
312
+ status: status === null || status === void 0 ? void 0 : status.content.toString(),
313
+ setAt: new Date(+((status === null || status === void 0 ? void 0 : status.attrs.t) || 0) * 1000)
314
+ };
234
315
  }
235
316
  };
236
317
  /** update the profile picture for yourself or a group */
@@ -332,51 +413,6 @@ const makeChatsSocket = (config) => {
332
413
  ]
333
414
  });
334
415
  };
335
- const getBusinessProfile = async (jid) => {
336
- var _a, _b, _c, _d, _e, _f, _g;
337
- const results = await query({
338
- tag: 'iq',
339
- attrs: {
340
- to: 's.whatsapp.net',
341
- xmlns: 'w:biz',
342
- type: 'get'
343
- },
344
- content: [{
345
- tag: 'business_profile',
346
- attrs: { v: '244' },
347
- content: [{
348
- tag: 'profile',
349
- attrs: { jid }
350
- }]
351
- }]
352
- });
353
- const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
354
- const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
355
- if (profiles) {
356
- const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
357
- const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
358
- const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
359
- const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
360
- const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
361
- const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
362
- const businessHoursConfig = businessHours ?
363
- (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
364
- undefined;
365
- const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
366
- return {
367
- wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
368
- address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
369
- description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
370
- website: websiteStr ? [websiteStr] : [],
371
- email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
372
- category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
373
- 'business_hours': {
374
- timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
375
- 'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
376
- }
377
- };
378
- }
379
- };
380
416
  const cleanDirtyBits = async (type, fromTimestamp) => {
381
417
  logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
382
418
  await sendNode({
@@ -520,7 +556,7 @@ const makeChatsSocket = (config) => {
520
556
  * fetch the profile picture of a user/group
521
557
  * type = "preview" for a low res picture
522
558
  * type = "image for the high res picture"
523
- */;
559
+ */
524
560
  const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
525
561
  var _a;
526
562
  jid = (0, WABinary_1.jidNormalizedUser)(jid);
@@ -556,10 +592,12 @@ const makeChatsSocket = (config) => {
556
592
  });
557
593
  }
558
594
  else {
595
+ const { server } = (0, WABinary_1.jidDecode)(toJid);
596
+ const isLid = server === 'lid';
559
597
  await sendNode({
560
598
  tag: 'chatstate',
561
599
  attrs: {
562
- from: me.id,
600
+ from: isLid ? me.lid : me.id,
563
601
  to: toJid,
564
602
  },
565
603
  content: [
@@ -710,10 +748,8 @@ const makeChatsSocket = (config) => {
710
748
  const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
711
749
  let props = {};
712
750
  if (propsNode) {
713
- if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) { // on some clients, the hash is returning as undefined
714
- authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
715
- ev.emit('creds.update', authState.creds);
716
- }
751
+ authState.creds.lastPropHash = (_b = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash;
752
+ ev.emit('creds.update', authState.creds);
717
753
  props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
718
754
  }
719
755
  logger.debug('fetched props');
@@ -739,16 +775,6 @@ const makeChatsSocket = (config) => {
739
775
  }
740
776
  }, jid);
741
777
  };
742
- /**
743
- * Adds label
744
- */
745
- const addLabel = (jid, labels) => {
746
- return chatModify({
747
- addLabel: {
748
- ...labels
749
- }
750
- }, jid);
751
- };
752
778
  /**
753
779
  * Adds label for the chats
754
780
  */
@@ -835,7 +861,6 @@ const makeChatsSocket = (config) => {
835
861
  })(),
836
862
  (0, process_message_1.default)(msg, {
837
863
  shouldProcessHistoryMsg,
838
- placeholderResendCache,
839
864
  ev,
840
865
  creds: authState.creds,
841
866
  keyStore: authState.keys,
@@ -896,38 +921,33 @@ const makeChatsSocket = (config) => {
896
921
  sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
897
922
  .catch(error => onUnexpectedError(error, 'presence update requests'));
898
923
  }
899
- if (receivedPendingNotifications && // if we don't have the app state key
924
+ if (receivedPendingNotifications) {
925
+ // if we don't have the app state key
900
926
  // we keep buffering events until we finally have
901
927
  // the key and can sync the messages
902
- // todo scrutinize
903
- !((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
904
- ev.buffer();
905
- needToFlushWithAppStateSync = true;
928
+ if (!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId) && !config.mobile) {
929
+ ev.buffer();
930
+ needToFlushWithAppStateSync = true;
931
+ }
906
932
  }
907
933
  });
908
934
  return {
909
935
  ...sock,
910
- interactiveQuery,
911
- getBotListV2,
912
936
  processingMutex,
913
937
  fetchPrivacySettings,
914
938
  upsertMessage,
915
939
  appPatch,
916
- fetchUserLid,
917
940
  sendPresenceUpdate,
918
941
  presenceSubscribe,
919
942
  profilePictureUrl,
920
943
  onWhatsApp,
921
944
  fetchBlocklist,
922
945
  fetchStatus,
923
- fetchDisappearingDuration,
924
946
  updateProfilePicture,
925
947
  removeProfilePicture,
926
948
  updateProfileStatus,
927
949
  updateProfileName,
928
950
  updateBlockStatus,
929
- updateCallPrivacy,
930
- updateMessagesPrivacy,
931
951
  updateLastSeenPrivacy,
932
952
  updateOnlinePrivacy,
933
953
  updateProfilePicturePrivacy,
@@ -939,10 +959,10 @@ const makeChatsSocket = (config) => {
939
959
  resyncAppState,
940
960
  chatModify,
941
961
  cleanDirtyBits,
942
- addLabel,
943
962
  addChatLabel,
944
963
  removeChatLabel,
945
964
  addMessageLabel,
965
+ checkStatusWA,
946
966
  removeMessageLabel,
947
967
  star
948
968
  };