@jiancodes/baileys 1.7.3 → 2.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.
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": [2, 3000, 1026924051]
2
+ "version": [2, 3000, 1029030078]
3
3
  }
@@ -27,7 +27,7 @@ exports.DEFAULT_CACHE_TTLS =
27
27
  void 0;
28
28
 
29
29
  const crypto_1 = require("crypto");
30
- const { proto } = require("../../WAProto"),
30
+ 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")),
@@ -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
- "INITIAL_BOOTSTRAP",
68
- "PUSH_NAME",
69
- "RECENT",
70
- "FULL",
71
- "ON_DEMAND"
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
72
72
  ];
73
73
 
74
74
  exports.DEFAULT_CONNECTION_CONFIG = {
@@ -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) {
@@ -962,7 +975,7 @@ const makeChatsSocket = (config) => {
962
975
  addChatLabel,
963
976
  removeChatLabel,
964
977
  addMessageLabel,
965
- checkStatusWA,
978
+ checkWhatsApp,
966
979
  removeMessageLabel,
967
980
  star
968
981
  };
@@ -1,6 +1,7 @@
1
+ // dugong.d.ts
1
2
  import { proto } from '../../WAProto';
2
3
 
3
- declare namespace imup {
4
+ declare namespace kikyy {
4
5
  interface MediaUploadOptions {
5
6
  fileEncSha256?: Buffer;
6
7
  mediaType?: string;
@@ -69,20 +70,20 @@ declare namespace imup {
69
70
  }
70
71
 
71
72
  interface InteractiveMessage {
73
+ header?: string;
72
74
  title: string;
73
75
  footer?: string;
74
76
  thumbnail?: string;
75
77
  image?: string | Buffer | { url: string };
76
78
  video?: string | Buffer | { url: string };
77
- document?: Buffer;
79
+ document?: string | Buffer | { url: string };
78
80
  mimetype?: string;
79
81
  fileName?: string;
80
- jpegThumbnail?: Buffer;
82
+ jpegThumbnail?: string | Buffer | { url: string };
81
83
  contextInfo?: {
82
84
  mentionedJid?: string[];
83
85
  forwardingScore?: number;
84
86
  isForwarded?: boolean;
85
- forwardedNewsletterMessageInfo?: proto.Message.ContextInfo.ForwardedNewsletterMessageInfo;
86
87
  externalAdReply?: {
87
88
  title?: string;
88
89
  body?: string;
@@ -116,8 +117,8 @@ declare namespace imup {
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 {
@@ -145,28 +146,9 @@ declare namespace imup {
145
146
  interface PollResultMessage {
146
147
  name: string;
147
148
  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[];
158
149
  }
159
150
 
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 {
151
+ interface GroupStatusMessage {
170
152
  message?: any;
171
153
  image?: string | Buffer | { url: string };
172
154
  video?: string | Buffer | { url: string };
@@ -175,10 +157,6 @@ declare namespace imup {
175
157
  document?: string | Buffer | { url: string };
176
158
  [key: string]: any;
177
159
  }
178
-
179
- interface GroupLabel {
180
- labelText: string;
181
- }
182
160
 
183
161
  interface MessageContent {
184
162
  requestPaymentMessage?: PaymentMessage;
@@ -187,9 +165,7 @@ declare namespace imup {
187
165
  albumMessage?: AlbumItem[];
188
166
  eventMessage?: EventMessage;
189
167
  pollResultMessage?: PollResultMessage;
190
- groupStatus?: GroupStatus;
191
- orderMessage?: OrderMessage;
192
- groupLabel?: GroupLabel;
168
+ groupStatusMessage?: GroupStatusMessage;
193
169
  sender?: string;
194
170
  }
195
171
 
@@ -204,75 +180,75 @@ declare namespace imup {
204
180
  generateWAMessageFromContent: (jid: string, content: any, options?: any) => Promise<any>;
205
181
  generateWAMessage: (jid: string, content: any, options?: any) => Promise<any>;
206
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;
207
190
  }
208
191
  }
209
192
 
210
- declare class imup {
193
+ declare class kikyy {
211
194
  constructor(
212
- utils: imup.Utils,
213
- waUploadToServer: imup.WAMediaUploadFunction,
195
+ utils: kikyy.Utils,
196
+ waUploadToServer: kikyy.WAMediaUploadFunction,
214
197
  relayMessageFn?: (jid: string, content: any, options?: any) => Promise<any>
215
198
  );
216
199
 
217
- detectType(content: imup.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | 'GROUP_STATUS' | 'ORDER' | 'GROUP_LABEL' |null;
200
+ detectType(content: kikyy.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | 'GROUP_STORY' | null;
218
201
 
219
202
  handlePayment(
220
- content: { requestPaymentMessage: imup.PaymentMessage },
203
+ content: { requestPaymentMessage: kikyy.PaymentMessage },
221
204
  quoted?: proto.IWebMessageInfo
222
205
  ): Promise<{ requestPaymentMessage: proto.Message.RequestPaymentMessage }>;
223
206
 
224
207
  handleProduct(
225
- content: { productMessage: imup.ProductMessage },
208
+ content: { productMessage: kikyy.ProductMessage },
226
209
  jid: string,
227
210
  quoted?: proto.IWebMessageInfo
228
211
  ): Promise<{ viewOnceMessage: proto.Message.ViewOnceMessage }>;
229
212
 
230
213
  handleInteractive(
231
- content: { interactiveMessage: imup.InteractiveMessage },
214
+ content: { interactiveMessage: kikyy.InteractiveMessage },
232
215
  jid: string,
233
216
  quoted?: proto.IWebMessageInfo
234
217
  ): Promise<{ interactiveMessage: proto.Message.InteractiveMessage }>;
235
218
 
236
219
  handleAlbum(
237
- content: { albumMessage: imup.AlbumItem[] },
220
+ content: { albumMessage: kikyy.AlbumItem[] },
238
221
  jid: string,
239
222
  quoted?: proto.IWebMessageInfo
240
223
  ): Promise<any>;
241
224
 
242
225
  handleEvent(
243
- content: { eventMessage: imup.EventMessage },
226
+ content: { eventMessage: kikyy.EventMessage },
244
227
  jid: string,
245
228
  quoted?: proto.IWebMessageInfo
246
229
  ): Promise<any>;
247
230
 
248
231
  handlePollResult(
249
- content: { pollResultMessage: imup.PollResultMessage },
232
+ content: { pollResultMessage: kikyy.PollResultMessage },
250
233
  jid: string,
251
234
  quoted?: proto.IWebMessageInfo
252
235
  ): Promise<any>;
253
236
 
254
- handleStMention(
255
- content: { statusMentionMessage: imup.StatusMentionMessage },
256
- jid: string,
257
- quoted?: proto.IWebMessageInfo
258
- ): Promise<any>;
259
-
260
- handleOrderMessage(
261
- content: { orderMessage: imup.OrderMessage },
262
- jid: string,
263
- quoted?: proto.IWebMessageInfo
264
- ): Promise<any>;
265
-
266
237
  handleGroupStory(
267
- content: { groupStatus: imup.GroupStatus },
238
+ content: { groupStatusMessage: kikyy.GroupStatusMessage },
268
239
  jid: string,
269
240
  quoted?: proto.IWebMessageInfo
270
241
  ): Promise<any>;
271
-
272
- handleGbLabel(
273
- content: { groupLabel: imup.GroupLabel },
274
- jid: string,
242
+
243
+ buildMessageContent(
244
+ content: any,
245
+ opts?: kikyy.WAMessageContentGenerationOptions
275
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;
276
252
  }
277
253
 
278
- export = imup;
254
+ export = kikyy;