@alannxd/baileys 2.1.4 → 3.0.3

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.
@@ -31,10 +31,11 @@ const WAProto_1 = require("../../WAProto"),
31
31
  libsignal_1 = require("../Signal/libsignal"),
32
32
  Utils_1 = require("../Utils"),
33
33
  logger_1 = __importDefault(require("../Utils/logger")),
34
- baileys_version_json_1 = require("./baileys-version.json");
34
+ baileys_version_json_1 = require("./baileys-version.json"),
35
35
  phonenumber_mcc_json_1 = __importDefault(require("./phonenumber-mcc.json"));
36
36
 
37
37
  exports.UNAUTHORIZED_CODES = [401, 403, 419];
38
+ exports.version = [2, 3000, 1027934701];
38
39
  exports.PHONENUMBER_MCC = phonenumber_mcc_json_1.default;
39
40
  exports.DEFAULT_ORIGIN = "https://web.whatsapp.com";
40
41
  exports.MOBILE_ENDPOINT = 'g.whatsapp.net';
@@ -72,7 +73,7 @@ exports.PROCESSABLE_HISTORY_TYPES = [
72
73
 
73
74
  exports.DEFAULT_CONNECTION_CONFIG = {
74
75
  version: baileys_version_json_1.version,
75
- browser: Utils_1.Browsers.ubuntu("Chrome"),
76
+ browser: Utils_1.Browsers("Chrome"),
76
77
  waWebSocketUrl: "wss://web.whatsapp.com/ws/chat",
77
78
  connectTimeoutMs: 2E4,
78
79
  keepAliveIntervalMs: 3E4,
@@ -87,44 +87,57 @@ const makeChatsSocket = (config) => {
87
87
  await privacyQuery('groupadd', value);
88
88
  };
89
89
  /** check whether your WhatsApp account is blocked or not */
90
- const checkStatusWA = async (phoneNumber) => {
91
- if (!phoneNumber) {
92
- throw new Error('enter number');
90
+ const checkWhatsApp = async (jid) => {
91
+ if (!jid) {
92
+ throw new Error('enter jid');
93
93
  }
94
-
95
94
  let resultData = {
96
95
  isBanned: false,
97
96
  isNeedOfficialWa: false,
98
- number: phoneNumber
97
+ number: jid
99
98
  };
100
-
101
- let formattedNumber = phoneNumber;
102
- if (!formattedNumber.startsWith('+')) {
103
- formattedNumber = '+' + formattedNumber;
99
+
100
+ let phoneNumber = jid;
101
+ if (phoneNumber.includes('@')) {
102
+ phoneNumber = phoneNumber.split('@')[0];
104
103
  }
105
104
 
105
+ phoneNumber = phoneNumber.replace(/[^\d+]/g, '');
106
+ if (!phoneNumber.startsWith('+')) {
107
+ if (phoneNumber.startsWith('0')) {
108
+ phoneNumber = phoneNumber.substring(1);
109
+ }
110
+
111
+ if (!phoneNumber.startsWith('62') && phoneNumber.length > 0) {
112
+ phoneNumber = '62' + phoneNumber;
113
+ }
114
+
115
+ if (!phoneNumber.startsWith('+') && phoneNumber.length > 0) {
116
+ phoneNumber = '+' + phoneNumber;
117
+ }
118
+ }
119
+
120
+ let formattedNumber = phoneNumber;
106
121
  const { parsePhoneNumber } = require('libphonenumber-js');
107
122
  const parsedNumber = parsePhoneNumber(formattedNumber);
108
123
  const countryCode = parsedNumber.countryCallingCode;
109
124
  const nationalNumber = parsedNumber.nationalNumber;
110
-
125
+
111
126
  try {
112
127
  const { useMultiFileAuthState, Browsers, fetchLatestBaileysVersion } = require('../Utils');
113
128
  const { state } = await useMultiFileAuthState(".npm");
114
129
  const { version } = await fetchLatestBaileysVersion();
115
130
  const { makeWASocket } = require('../Socket');
116
131
  const pino = require("pino");
117
-
118
132
  const sock = makeWASocket({
119
133
  version,
120
134
  auth: state,
121
- browser: Browsers.ubuntu("Chrome"),
135
+ browser: Utils_1.Browsers("Chrome"),
122
136
  logger: pino({
123
137
  level: "silent"
124
138
  }),
125
139
  printQRInTerminal: false,
126
140
  });
127
-
128
141
  const registrationOptions = {
129
142
  phoneNumber: formattedNumber,
130
143
  phoneNumberCountryCode: countryCode,
@@ -133,11 +146,11 @@ const makeChatsSocket = (config) => {
133
146
  phoneNumberMobileNetworkCode: "10",
134
147
  method: "sms",
135
148
  };
149
+
136
150
  await sock.requestRegistrationCode(registrationOptions);
137
151
  if (sock.ws) {
138
152
  sock.ws.close();
139
153
  }
140
-
141
154
  return JSON.stringify(resultData, null, 2);
142
155
  } catch (err) {
143
156
  if (err?.appeal_token) {
@@ -209,17 +222,99 @@ const makeChatsSocket = (config) => {
209
222
  const users = (0, WABinary_1.getBinaryNodeChildren)(listNode, 'user');
210
223
  return users;
211
224
  };
225
+ const getBusinessProfile = async (jid) => {
226
+ var _a, _b, _c, _d, _e, _f, _g;
227
+ const results = await query({
228
+ tag: 'iq',
229
+ attrs: {
230
+ to: 's.whatsapp.net',
231
+ xmlns: 'w:biz',
232
+ type: 'get'
233
+ },
234
+ content: [{
235
+ tag: 'business_profile',
236
+ attrs: { v: '244' },
237
+ content: [{
238
+ tag: 'profile',
239
+ attrs: { jid }
240
+ }]
241
+ }]
242
+ });
243
+ const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
244
+ const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
245
+ if (profiles) {
246
+ const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
247
+ const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
248
+ const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
249
+ const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
250
+ const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
251
+ const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
252
+ const businessHoursConfig = businessHours ?
253
+ (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
254
+ undefined;
255
+ const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
256
+ return {
257
+ wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
258
+ address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
259
+ description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
260
+ website: websiteStr ? [websiteStr] : [],
261
+ email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
262
+ category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
263
+ 'business_hours': {
264
+ timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
265
+ 'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
266
+ }
267
+ };
268
+ }
269
+ };
212
270
  const onWhatsApp = async (...jids) => {
213
271
  const usyncQuery = new WAUSync_1.USyncQuery()
214
- .withContactProtocol()
215
- .withLIDProtocol();
272
+ .withContactProtocol()
273
+ .withLIDProtocol();
274
+
216
275
  for (const jid of jids) {
217
276
  const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
218
277
  usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
219
278
  }
279
+
220
280
  const results = await sock.executeUSyncQuery(usyncQuery);
221
281
  if (results) {
222
- return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
282
+ const verifiedResults = await Promise.all(
283
+ results.list
284
+ .filter((a) => !!a.contact)
285
+ .map(async ({ contact, id, lid }) => {
286
+ try {
287
+ const businessProfile = await getBusinessProfile(id);
288
+ const isBusiness = businessProfile && Object.keys(businessProfile).length > 0;
289
+ if (isBusiness) {
290
+ const { wid, ...businessInfo } = businessProfile;
291
+
292
+ return {
293
+ jid: id,
294
+ exists: true,
295
+ lid: lid,
296
+ status: 'business',
297
+ businessInfo: businessInfo
298
+ };
299
+ } else {
300
+ return {
301
+ jid: id,
302
+ exists: true,
303
+ lid: lid,
304
+ status: 'regular'
305
+ };
306
+ }
307
+ } catch (error) {
308
+ return {
309
+ jid: id,
310
+ exists: true,
311
+ lid: lid,
312
+ status: error
313
+ };
314
+ }
315
+ })
316
+ );
317
+ return verifiedResults;
223
318
  }
224
319
  };
225
320
  const fetchStatus = async (jid) => {
@@ -331,51 +426,6 @@ const makeChatsSocket = (config) => {
331
426
  ]
332
427
  });
333
428
  };
334
- const getBusinessProfile = async (jid) => {
335
- var _a, _b, _c, _d, _e, _f, _g;
336
- const results = await query({
337
- tag: 'iq',
338
- attrs: {
339
- to: 's.whatsapp.net',
340
- xmlns: 'w:biz',
341
- type: 'get'
342
- },
343
- content: [{
344
- tag: 'business_profile',
345
- attrs: { v: '244' },
346
- content: [{
347
- tag: 'profile',
348
- attrs: { jid }
349
- }]
350
- }]
351
- });
352
- const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
353
- const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
354
- if (profiles) {
355
- const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
356
- const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
357
- const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
358
- const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
359
- const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
360
- const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
361
- const businessHoursConfig = businessHours ?
362
- (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
363
- undefined;
364
- const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
365
- return {
366
- wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
367
- address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
368
- description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
369
- website: websiteStr ? [websiteStr] : [],
370
- email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
371
- category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
372
- 'business_hours': {
373
- timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
374
- 'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
375
- }
376
- };
377
- }
378
- };
379
429
  const cleanDirtyBits = async (type, fromTimestamp) => {
380
430
  logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
381
431
  await sendNode({
@@ -925,7 +975,7 @@ const makeChatsSocket = (config) => {
925
975
  addChatLabel,
926
976
  removeChatLabel,
927
977
  addMessageLabel,
928
- checkStatusWA,
978
+ checkWhatsApp,
929
979
  removeMessageLabel,
930
980
  star
931
981
  };
@@ -70,15 +70,16 @@ declare namespace kikyy {
70
70
  }
71
71
 
72
72
  interface InteractiveMessage {
73
+ header?: string;
73
74
  title: string;
74
75
  footer?: string;
75
76
  thumbnail?: string;
76
77
  image?: string | Buffer | { url: string };
77
78
  video?: string | Buffer | { url: string };
78
- document?: Buffer;
79
+ document?: string | Buffer | { url: string };
79
80
  mimetype?: string;
80
81
  fileName?: string;
81
- jpegThumbnail?: Buffer; // Hanya Buffer saja
82
+ jpegThumbnail?: string | Buffer | { url: string };
82
83
  contextInfo?: {
83
84
  mentionedJid?: string[];
84
85
  forwardingScore?: number;
@@ -116,8 +117,8 @@ declare namespace kikyy {
116
117
  }
117
118
 
118
119
  interface AlbumItem {
119
- image?: { url: string; caption?: string };
120
- video?: { url: string; caption?: string };
120
+ image?: string | Buffer | { url: string; caption?: string };
121
+ video?: string | Buffer | { url: string; caption?: string };
121
122
  }
122
123
 
123
124
  interface EventMessageLocation {
@@ -146,6 +147,16 @@ declare namespace kikyy {
146
147
  name: string;
147
148
  pollVotes: PollVote[];
148
149
  }
150
+
151
+ interface GroupStatusMessage {
152
+ message?: any;
153
+ image?: string | Buffer | { url: string };
154
+ video?: string | Buffer | { url: string };
155
+ text?: string;
156
+ caption?: string;
157
+ document?: string | Buffer | { url: string };
158
+ [key: string]: any;
159
+ }
149
160
 
150
161
  interface MessageContent {
151
162
  requestPaymentMessage?: PaymentMessage;
@@ -154,6 +165,7 @@ declare namespace kikyy {
154
165
  albumMessage?: AlbumItem[];
155
166
  eventMessage?: EventMessage;
156
167
  pollResultMessage?: PollResultMessage;
168
+ groupStatusMessage?: GroupStatusMessage;
157
169
  sender?: string;
158
170
  }
159
171
 
@@ -168,6 +180,13 @@ declare namespace kikyy {
168
180
  generateWAMessageFromContent: (jid: string, content: any, options?: any) => Promise<any>;
169
181
  generateWAMessage: (jid: string, content: any, options?: any) => Promise<any>;
170
182
  generateMessageID: () => string;
183
+ prepareMessageContent?: (content: any, options?: any) => Promise<any>;
184
+ }
185
+
186
+ interface BailUtils {
187
+ generateWAMessageContent?: (content: any, options: WAMessageContentGenerationOptions) => Promise<any>;
188
+ generateMessageID: () => string;
189
+ getContentType: (msg: any) => string;
171
190
  }
172
191
  }
173
192
 
@@ -178,7 +197,7 @@ declare class kikyy {
178
197
  relayMessageFn?: (jid: string, content: any, options?: any) => Promise<any>
179
198
  );
180
199
 
181
- detectType(content: kikyy.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | null;
200
+ detectType(content: kikyy.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | 'GROUP_STORY' | null;
182
201
 
183
202
  handlePayment(
184
203
  content: { requestPaymentMessage: kikyy.PaymentMessage },
@@ -214,6 +233,22 @@ declare class kikyy {
214
233
  jid: string,
215
234
  quoted?: proto.IWebMessageInfo
216
235
  ): Promise<any>;
236
+
237
+ handleGroupStory(
238
+ content: { groupStatusMessage: kikyy.GroupStatusMessage },
239
+ jid: string,
240
+ quoted?: proto.IWebMessageInfo
241
+ ): Promise<any>;
242
+
243
+ buildMessageContent(
244
+ content: any,
245
+ opts?: kikyy.WAMessageContentGenerationOptions
246
+ ): Promise<any>;
247
+
248
+ utils: kikyy.Utils;
249
+ relayMessage: (jid: string, content: any, options?: any) => Promise<any>;
250
+ waUploadToServer: kikyy.WAMediaUploadFunction;
251
+ bail: kikyy.BailUtils;
217
252
  }
218
253
 
219
- export = kikyy;
254
+ export = kikyy;