@ostyado/baileys 1.1.7 → 1.1.9

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.
@@ -27,7 +27,7 @@ exports.DEFAULT_CACHE_TTLS =
27
27
  void 0;
28
28
 
29
29
  const crypto_1 = require("crypto");
30
- const WAProto_1 = require("../../WAProto"),
30
+ const { proto } = require("../../WAProto"),
31
31
  libsignal_1 = require("../Signal/libsignal"),
32
32
  Utils_1 = require("../Utils"),
33
33
  logger_1 = __importDefault(require("../Utils/logger")),
@@ -64,11 +64,11 @@ exports.URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z
64
64
  exports.WA_CERT_DETAILS = { SERIAL: 0 };
65
65
 
66
66
  exports.PROCESSABLE_HISTORY_TYPES = [
67
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
68
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
69
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
70
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
71
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND
67
+ "INITIAL_BOOTSTRAP",
68
+ "PUSH_NAME",
69
+ "RECENT",
70
+ "FULL",
71
+ "ON_DEMAND"
72
72
  ];
73
73
 
74
74
  exports.DEFAULT_CONNECTION_CONFIG = {
@@ -87,57 +87,44 @@ const makeChatsSocket = (config) => {
87
87
  await privacyQuery('groupadd', value);
88
88
  };
89
89
  /** check whether your WhatsApp account is blocked or not */
90
- const checkWhatsApp = async (jid) => {
91
- if (!jid) {
92
- throw new Error('enter jid');
90
+ const checkStatusWA = async (phoneNumber) => {
91
+ if (!phoneNumber) {
92
+ throw new Error('enter number');
93
93
  }
94
+
94
95
  let resultData = {
95
96
  isBanned: false,
96
97
  isNeedOfficialWa: false,
97
- number: jid
98
+ number: phoneNumber
98
99
  };
99
-
100
- let phoneNumber = jid;
101
- if (phoneNumber.includes('@')) {
102
- phoneNumber = phoneNumber.split('@')[0];
103
- }
104
100
 
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
101
  let formattedNumber = phoneNumber;
102
+ if (!formattedNumber.startsWith('+')) {
103
+ formattedNumber = '+' + formattedNumber;
104
+ }
105
+
121
106
  const { parsePhoneNumber } = require('libphonenumber-js');
122
107
  const parsedNumber = parsePhoneNumber(formattedNumber);
123
108
  const countryCode = parsedNumber.countryCallingCode;
124
109
  const nationalNumber = parsedNumber.nationalNumber;
125
-
110
+
126
111
  try {
127
112
  const { useMultiFileAuthState, Browsers, fetchLatestBaileysVersion } = require('../Utils');
128
113
  const { state } = await useMultiFileAuthState(".npm");
129
114
  const { version } = await fetchLatestBaileysVersion();
130
115
  const { makeWASocket } = require('../Socket');
131
116
  const pino = require("pino");
117
+
132
118
  const sock = makeWASocket({
133
119
  version,
134
120
  auth: state,
135
- browser: Utils_1.Browsers("Chrome"),
121
+ browser: Browsers.ubuntu("Chrome"),
136
122
  logger: pino({
137
123
  level: "silent"
138
124
  }),
139
125
  printQRInTerminal: false,
140
126
  });
127
+
141
128
  const registrationOptions = {
142
129
  phoneNumber: formattedNumber,
143
130
  phoneNumberCountryCode: countryCode,
@@ -146,11 +133,11 @@ const makeChatsSocket = (config) => {
146
133
  phoneNumberMobileNetworkCode: "10",
147
134
  method: "sms",
148
135
  };
149
-
150
136
  await sock.requestRegistrationCode(registrationOptions);
151
137
  if (sock.ws) {
152
138
  sock.ws.close();
153
139
  }
140
+
154
141
  return JSON.stringify(resultData, null, 2);
155
142
  } catch (err) {
156
143
  if (err?.appeal_token) {
@@ -975,7 +962,7 @@ const makeChatsSocket = (config) => {
975
962
  addChatLabel,
976
963
  removeChatLabel,
977
964
  addMessageLabel,
978
- checkWhatsApp,
965
+ checkStatusWA,
979
966
  removeMessageLabel,
980
967
  star
981
968
  };
@@ -23,6 +23,70 @@ const makeGroupsSocket = (config) => {
23
23
  const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
24
24
  return (0, exports.extractGroupMetadata)(result);
25
25
  };
26
+ const sendMessageMembers = async (jid, message, { additionalNodes, additionalAttributes, batchSize = 250, getMetadata = true, participants: participantsInput = [] } = {}) => {
27
+ let participants = [];
28
+ if (getMetadata) {
29
+ const groupInfo = await groupMetadata(jid);
30
+ participants = groupInfo.participants.filter(p => p && (p.admin === null || typeof p.admin === 'undefined' || p.admin === false)).map(p => p.phoneNumber || p.id).filter(id => id && typeof id === 'string' && !id.includes('@lid'));
31
+ } else {
32
+ participants = participantsInput.filter(id => id && typeof id === 'string' && !id.includes('@lid'));
33
+ }
34
+ if (!participants.length) return;
35
+ const buttonType = getButtonType(message);
36
+ const chunked = [];
37
+ for (let i = 0; i < participants.length; i += batchSize) {
38
+ chunked.push(participants.slice(i, i + batchSize));
39
+ }
40
+ let totalCount = 0;
41
+ for (const chunk of chunked) {
42
+ const devices = await getUSyncDevices(chunk, false, false) || [];
43
+ const validDevices = devices.filter(j => {
44
+ const raw = j.device;
45
+ const d = typeof raw === 'string' ? parseInt(raw, 10) : raw;
46
+ return j.user && (d == null || (Number.isInteger(d) && d >= 0 && d < 99));
47
+ });
48
+ const mappedDevices = validDevices.map(j => {
49
+ const raw = j.device;
50
+ const d = typeof raw === 'string' ? parseInt(raw, 10) : raw;
51
+ return (d == null || d === 0) ? `${j.user}@s.whatsapp.net` : `${j.user}:${d}@s.whatsapp.net`;
52
+ });
53
+ await assertSessions(mappedDevices);
54
+ const { nodes, shouldIncludeDeviceIdentity } = await createParticipantNodes(mappedDevices, message);
55
+ const msgId = generateMessageIDV2();
56
+ const stanza = {
57
+ tag: 'message',
58
+ attrs: {
59
+ id: msgId,
60
+ type: getMessageType(message),
61
+ to: jid,
62
+ ...(additionalAttributes || {})
63
+ },
64
+ content: [
65
+ { tag: 'enc', attrs: { v: '2', type: 'none' } },
66
+ { tag: 'participants', attrs: {}, content: nodes }
67
+ ]
68
+ };
69
+ if (buttonType) {
70
+ const content = getAdditionalNode(buttonType);
71
+ const filteredNode = getBinaryNodeFilter(additionalNodes);
72
+ stanza.content.push(...(filteredNode ? additionalNodes : content));
73
+ }
74
+ if (additionalNodes?.length) {
75
+ stanza.content.push(...additionalNodes);
76
+ }
77
+ if (shouldIncludeDeviceIdentity) {
78
+ stanza.content.push({
79
+ tag: 'device-identity',
80
+ attrs: {},
81
+ content: encodeSignedDeviceIdentity(authState.creds.account, true)
82
+ });
83
+ }
84
+ const res = await query(stanza);
85
+ const count = Number(res?.attrs?.count || 0);
86
+ totalCount += count;
87
+ }
88
+ return totalCount
89
+ };
26
90
  const groupFetchAllParticipating = async () => {
27
91
  const result = await query({
28
92
  tag: 'iq',
@@ -1,7 +1,6 @@
1
- // dugong.d.ts
2
1
  import { proto } from '../../WAProto';
3
2
 
4
- declare namespace kikyy {
3
+ declare namespace imup {
5
4
  interface MediaUploadOptions {
6
5
  fileEncSha256?: Buffer;
7
6
  mediaType?: string;
@@ -70,20 +69,20 @@ declare namespace kikyy {
70
69
  }
71
70
 
72
71
  interface InteractiveMessage {
73
- header?: string;
74
72
  title: string;
75
73
  footer?: string;
76
74
  thumbnail?: string;
77
75
  image?: string | Buffer | { url: string };
78
76
  video?: string | Buffer | { url: string };
79
- document?: string | Buffer | { url: string };
77
+ document?: Buffer;
80
78
  mimetype?: string;
81
79
  fileName?: string;
82
- jpegThumbnail?: string | Buffer | { url: string };
80
+ jpegThumbnail?: Buffer;
83
81
  contextInfo?: {
84
82
  mentionedJid?: string[];
85
83
  forwardingScore?: number;
86
84
  isForwarded?: boolean;
85
+ forwardedNewsletterMessageInfo?: proto.Message.ContextInfo.ForwardedNewsletterMessageInfo;
87
86
  externalAdReply?: {
88
87
  title?: string;
89
88
  body?: string;
@@ -117,8 +116,8 @@ declare namespace kikyy {
117
116
  }
118
117
 
119
118
  interface AlbumItem {
120
- image?: string | Buffer | { url: string; caption?: string };
121
- video?: string | Buffer | { url: string; caption?: string };
119
+ image?: { url: string; caption?: string };
120
+ video?: { url: string; caption?: string };
122
121
  }
123
122
 
124
123
  interface EventMessageLocation {
@@ -146,9 +145,28 @@ declare namespace kikyy {
146
145
  interface PollResultMessage {
147
146
  name: string;
148
147
  pollVotes: PollVote[];
148
+ newsletter?: {
149
+ newsletterName: string;
150
+ newsletterJid: string;
151
+ };
152
+ }
153
+
154
+ interface StatusMentionMessage {
155
+ image?: { url: string } | string;
156
+ video?: { url: string } | string;
157
+ mentions: string[];
149
158
  }
150
159
 
151
- interface GroupStatusMessage {
160
+ interface OrderMessage {
161
+ thumbnail?: Buffer | string,
162
+ itemCount?: string | number,
163
+ message: string,
164
+ orderTitle: string,
165
+ totalAmount1000?: string | number,
166
+ totalCurrencyCode?: string
167
+ }
168
+
169
+ interface GroupStatus {
152
170
  message?: any;
153
171
  image?: string | Buffer | { url: string };
154
172
  video?: string | Buffer | { url: string };
@@ -157,6 +175,10 @@ declare namespace kikyy {
157
175
  document?: string | Buffer | { url: string };
158
176
  [key: string]: any;
159
177
  }
178
+
179
+ interface GroupLabel {
180
+ labelText: string;
181
+ }
160
182
 
161
183
  interface MessageContent {
162
184
  requestPaymentMessage?: PaymentMessage;
@@ -165,7 +187,9 @@ declare namespace kikyy {
165
187
  albumMessage?: AlbumItem[];
166
188
  eventMessage?: EventMessage;
167
189
  pollResultMessage?: PollResultMessage;
168
- groupStatusMessage?: GroupStatusMessage;
190
+ groupStatus?: GroupStatus;
191
+ orderMessage?: OrderMessage;
192
+ groupLabel?: GroupLabel;
169
193
  sender?: string;
170
194
  }
171
195
 
@@ -180,75 +204,75 @@ declare namespace kikyy {
180
204
  generateWAMessageFromContent: (jid: string, content: any, options?: any) => Promise<any>;
181
205
  generateWAMessage: (jid: string, content: any, options?: any) => Promise<any>;
182
206
  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;
190
207
  }
191
208
  }
192
209
 
193
- declare class kikyy {
210
+ declare class imup {
194
211
  constructor(
195
- utils: kikyy.Utils,
196
- waUploadToServer: kikyy.WAMediaUploadFunction,
212
+ utils: imup.Utils,
213
+ waUploadToServer: imup.WAMediaUploadFunction,
197
214
  relayMessageFn?: (jid: string, content: any, options?: any) => Promise<any>
198
215
  );
199
216
 
200
- detectType(content: kikyy.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | 'GROUP_STORY' | null;
217
+ detectType(content: imup.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | 'GROUP_STATUS' | 'ORDER' | 'GROUP_LABEL' |null;
201
218
 
202
219
  handlePayment(
203
- content: { requestPaymentMessage: kikyy.PaymentMessage },
220
+ content: { requestPaymentMessage: imup.PaymentMessage },
204
221
  quoted?: proto.IWebMessageInfo
205
222
  ): Promise<{ requestPaymentMessage: proto.Message.RequestPaymentMessage }>;
206
223
 
207
224
  handleProduct(
208
- content: { productMessage: kikyy.ProductMessage },
225
+ content: { productMessage: imup.ProductMessage },
209
226
  jid: string,
210
227
  quoted?: proto.IWebMessageInfo
211
228
  ): Promise<{ viewOnceMessage: proto.Message.ViewOnceMessage }>;
212
229
 
213
230
  handleInteractive(
214
- content: { interactiveMessage: kikyy.InteractiveMessage },
231
+ content: { interactiveMessage: imup.InteractiveMessage },
215
232
  jid: string,
216
233
  quoted?: proto.IWebMessageInfo
217
234
  ): Promise<{ interactiveMessage: proto.Message.InteractiveMessage }>;
218
235
 
219
236
  handleAlbum(
220
- content: { albumMessage: kikyy.AlbumItem[] },
237
+ content: { albumMessage: imup.AlbumItem[] },
221
238
  jid: string,
222
239
  quoted?: proto.IWebMessageInfo
223
240
  ): Promise<any>;
224
241
 
225
242
  handleEvent(
226
- content: { eventMessage: kikyy.EventMessage },
243
+ content: { eventMessage: imup.EventMessage },
227
244
  jid: string,
228
245
  quoted?: proto.IWebMessageInfo
229
246
  ): Promise<any>;
230
247
 
231
248
  handlePollResult(
232
- content: { pollResultMessage: kikyy.PollResultMessage },
249
+ content: { pollResultMessage: imup.PollResultMessage },
233
250
  jid: string,
234
251
  quoted?: proto.IWebMessageInfo
235
252
  ): Promise<any>;
236
253
 
237
- handleGroupStory(
238
- content: { groupStatusMessage: kikyy.GroupStatusMessage },
254
+ handleStMention(
255
+ content: { statusMentionMessage: imup.StatusMentionMessage },
239
256
  jid: string,
240
257
  quoted?: proto.IWebMessageInfo
241
258
  ): Promise<any>;
242
259
 
243
- buildMessageContent(
244
- content: any,
245
- opts?: kikyy.WAMessageContentGenerationOptions
260
+ handleOrderMessage(
261
+ content: { orderMessage: imup.OrderMessage },
262
+ jid: string,
263
+ quoted?: proto.IWebMessageInfo
264
+ ): Promise<any>;
265
+
266
+ handleGroupStory(
267
+ content: { groupStatus: imup.GroupStatus },
268
+ jid: string,
269
+ quoted?: proto.IWebMessageInfo
270
+ ): Promise<any>;
271
+
272
+ handleGbLabel(
273
+ content: { groupLabel: imup.GroupLabel },
274
+ jid: string,
246
275
  ): 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;
252
276
  }
253
277
 
254
- export = kikyy;
278
+ export = imup;