zaileys 1.1.38 → 1.1.39

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.
package/dist/index.d.mts CHANGED
@@ -586,6 +586,7 @@ declare const RelayButtonType: z.ZodDiscriminatedUnion<[z.ZodObject<{
586
586
  text: z.ZodString;
587
587
  }, z.core.$strip>>;
588
588
  roomId: z.ZodOptional<z.ZodString>;
589
+ externalAdReply: z.ZodOptional<z.ZodCustom<baileys.proto.ContextInfo.IExternalAdReplyInfo, baileys.proto.ContextInfo.IExternalAdReplyInfo>>;
589
590
  }, z.core.$strip>, z.ZodObject<{
590
591
  type: z.ZodLiteral<"interactive">;
591
592
  text: z.ZodString;
@@ -611,6 +612,7 @@ declare const RelayButtonType: z.ZodDiscriminatedUnion<[z.ZodObject<{
611
612
  text: z.ZodString;
612
613
  }, z.core.$strip>], "type">>;
613
614
  roomId: z.ZodOptional<z.ZodString>;
615
+ externalAdReply: z.ZodOptional<z.ZodCustom<baileys.proto.ContextInfo.IExternalAdReplyInfo, baileys.proto.ContextInfo.IExternalAdReplyInfo>>;
614
616
  }, z.core.$strip>], "type">;
615
617
 
616
618
  declare const RelayGroupCreateType: z.ZodObject<{
@@ -1261,7 +1263,87 @@ declare class Relay {
1261
1263
  };
1262
1264
  }>;
1263
1265
  document(type: ExtractZod<typeof RelayDocumentEnumType>, props: ExtractZod<typeof RelayDocumentType>): Promise<void>;
1264
- image(type: ExtractZod<typeof RelayImageEnumType>, props: ExtractZod<typeof RelayImageType>): Promise<void>;
1266
+ image(type: ExtractZod<typeof RelayImageEnumType>, props: ExtractZod<typeof RelayImageType>): Promise<{
1267
+ chatId: string;
1268
+ channelId: string;
1269
+ uniqueId: string;
1270
+ receiverId: string;
1271
+ receiverName: string;
1272
+ roomId: string;
1273
+ roomName: string;
1274
+ senderLid: string;
1275
+ senderId: string;
1276
+ senderName: string;
1277
+ senderDevice: "unknown" | "android" | "ios" | "desktop" | "web";
1278
+ chatType: "contacts" | "event" | "text" | "image" | "contact" | "location" | "document" | "audio" | "video" | "protocol" | "highlyStructured" | "sendPayment" | "requestPayment" | "declinePaymentRequest" | "cancelPaymentRequest" | "template" | "sticker" | "groupInvite" | "buttons" | "product" | "deviceSent" | "list" | "viewOnce" | "order" | "ephemeral" | "invoice" | "paymentInvite" | "interactive" | "reaction" | "interactiveResponse" | "pollCreation" | "pollUpdate" | "keepInChat" | "requestPhoneNumber" | "scheduledCallCreation" | "groupMentioned" | "pinInChat" | "scheduledCallEdit" | "ptv" | "botInvoke" | "callLog" | "encComment" | "bcall" | "lottieSticker" | "comment" | "placeholder" | "encEventUpdate";
1279
+ timestamp: number;
1280
+ mentions: string[];
1281
+ links: string[];
1282
+ isPrefix: boolean;
1283
+ isSpam: boolean;
1284
+ isFromMe: boolean;
1285
+ isTagMe: boolean;
1286
+ isGroup: boolean;
1287
+ isStory: boolean;
1288
+ isViewOnce: boolean;
1289
+ isEdited: boolean;
1290
+ isDeleted: boolean;
1291
+ isPinned: boolean;
1292
+ isUnPinned: boolean;
1293
+ isChannel: boolean;
1294
+ isBroadcast: boolean;
1295
+ isEphemeral: boolean;
1296
+ isForwarded: boolean;
1297
+ message: z.core.$InferOuterFunctionType<z.ZodTuple<readonly [], null>, z.ZodRecord<z.ZodString, z.ZodAny>>;
1298
+ text?: string;
1299
+ citation?: Record<string, boolean>;
1300
+ media?: {
1301
+ [x: string]: unknown;
1302
+ buffer: z.core.$InferOuterFunctionType<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>;
1303
+ stream: z.core.$InferOuterFunctionType<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>;
1304
+ };
1305
+ replied?: {
1306
+ chatId: string;
1307
+ channelId: string;
1308
+ uniqueId: string;
1309
+ receiverId: string;
1310
+ receiverName: string;
1311
+ roomId: string;
1312
+ roomName: string;
1313
+ senderLid: string;
1314
+ senderId: string;
1315
+ senderName: string;
1316
+ senderDevice: "unknown" | "android" | "ios" | "desktop" | "web";
1317
+ chatType: "contacts" | "event" | "text" | "image" | "contact" | "location" | "document" | "audio" | "video" | "protocol" | "highlyStructured" | "sendPayment" | "requestPayment" | "declinePaymentRequest" | "cancelPaymentRequest" | "template" | "sticker" | "groupInvite" | "buttons" | "product" | "deviceSent" | "list" | "viewOnce" | "order" | "ephemeral" | "invoice" | "paymentInvite" | "interactive" | "reaction" | "interactiveResponse" | "pollCreation" | "pollUpdate" | "keepInChat" | "requestPhoneNumber" | "scheduledCallCreation" | "groupMentioned" | "pinInChat" | "scheduledCallEdit" | "ptv" | "botInvoke" | "callLog" | "encComment" | "bcall" | "lottieSticker" | "comment" | "placeholder" | "encEventUpdate";
1318
+ timestamp: number;
1319
+ mentions: string[];
1320
+ links: string[];
1321
+ isPrefix: boolean;
1322
+ isSpam: boolean;
1323
+ isFromMe: boolean;
1324
+ isTagMe: boolean;
1325
+ isGroup: boolean;
1326
+ isStory: boolean;
1327
+ isViewOnce: boolean;
1328
+ isEdited: boolean;
1329
+ isDeleted: boolean;
1330
+ isPinned: boolean;
1331
+ isUnPinned: boolean;
1332
+ isChannel: boolean;
1333
+ isBroadcast: boolean;
1334
+ isEphemeral: boolean;
1335
+ isForwarded: boolean;
1336
+ message: z.core.$InferOuterFunctionType<z.ZodTuple<readonly [], null>, z.ZodRecord<z.ZodString, z.ZodAny>>;
1337
+ text?: string;
1338
+ citation?: Record<string, boolean>;
1339
+ media?: {
1340
+ [x: string]: unknown;
1341
+ buffer: z.core.$InferOuterFunctionType<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>;
1342
+ stream: z.core.$InferOuterFunctionType<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>;
1343
+ };
1344
+ replied?: /*elided*/ any;
1345
+ };
1346
+ }>;
1265
1347
  sticker(type: ExtractZod<typeof RelayStickerEnumType>, props: ExtractZod<typeof RelayStickerType>): Promise<void>;
1266
1348
  video(type: ExtractZod<typeof RelayVideoEnumType>, props: ExtractZod<typeof RelayVideoType>): Promise<void>;
1267
1349
  audio(type: ExtractZod<typeof RelayAudioEnumType>, props: ExtractZod<typeof RelayAudioType>): Promise<void>;
@@ -1350,7 +1432,7 @@ declare class Client {
1350
1432
  interface Client extends Relay {
1351
1433
  }
1352
1434
 
1353
- declare const toJson: <T = unknown>(object: unknown) => T;
1435
+ declare const toJson: (object: unknown) => any;
1354
1436
  declare const toString: (object: unknown) => string;
1355
1437
  declare const shuffleString: (str: string) => string;
1356
1438
  declare const tryAgain: <T>(fn: () => Promise<T>) => Promise<T>;
@@ -1360,5 +1442,6 @@ declare const extractJids: (text?: string) => string[];
1360
1442
  declare const extractUrls: (text?: string) => string[];
1361
1443
  declare const getMentions: (text?: string) => string[];
1362
1444
  declare const randomize: (arr: string[]) => string;
1445
+ declare const delay: (ms: number) => Promise<unknown>;
1363
1446
 
1364
- export { AdsReplyType, CitationType, Client, ClientAuthPairingType, ClientAuthQRType, ClientBaseType, ClientOptionsType, type EventCallbackType, EventEnumType, type ExtractZod, ExtractorCallsType, ExtractorConnectionType, ExtractorMessagesType, FakeReplyType, JsonDB, type JsonDBInterface, LimiterType, MessagesDeviceEnumType, MessagesEnumType, MessagesMediaType, MessagesVerifiedPlatformType, PluginsType, defaultBoolean, defaultString, extractJids, extractUrls, findWord, getMentions, normalizeText, randomize, shuffleString, toJson, toString, tryAgain };
1447
+ export { AdsReplyType, CitationType, Client, ClientAuthPairingType, ClientAuthQRType, ClientBaseType, ClientOptionsType, type EventCallbackType, EventEnumType, type ExtractZod, ExtractorCallsType, ExtractorConnectionType, ExtractorMessagesType, FakeReplyType, JsonDB, type JsonDBInterface, LimiterType, MessagesDeviceEnumType, MessagesEnumType, MessagesMediaType, MessagesVerifiedPlatformType, PluginsType, defaultBoolean, defaultString, delay, extractJids, extractUrls, findWord, getMentions, normalizeText, randomize, shuffleString, toJson, toString, tryAgain };
package/dist/index.d.ts CHANGED
@@ -586,6 +586,7 @@ declare const RelayButtonType: z.ZodDiscriminatedUnion<[z.ZodObject<{
586
586
  text: z.ZodString;
587
587
  }, z.core.$strip>>;
588
588
  roomId: z.ZodOptional<z.ZodString>;
589
+ externalAdReply: z.ZodOptional<z.ZodCustom<baileys.proto.ContextInfo.IExternalAdReplyInfo, baileys.proto.ContextInfo.IExternalAdReplyInfo>>;
589
590
  }, z.core.$strip>, z.ZodObject<{
590
591
  type: z.ZodLiteral<"interactive">;
591
592
  text: z.ZodString;
@@ -611,6 +612,7 @@ declare const RelayButtonType: z.ZodDiscriminatedUnion<[z.ZodObject<{
611
612
  text: z.ZodString;
612
613
  }, z.core.$strip>], "type">>;
613
614
  roomId: z.ZodOptional<z.ZodString>;
615
+ externalAdReply: z.ZodOptional<z.ZodCustom<baileys.proto.ContextInfo.IExternalAdReplyInfo, baileys.proto.ContextInfo.IExternalAdReplyInfo>>;
614
616
  }, z.core.$strip>], "type">;
615
617
 
616
618
  declare const RelayGroupCreateType: z.ZodObject<{
@@ -1261,7 +1263,87 @@ declare class Relay {
1261
1263
  };
1262
1264
  }>;
1263
1265
  document(type: ExtractZod<typeof RelayDocumentEnumType>, props: ExtractZod<typeof RelayDocumentType>): Promise<void>;
1264
- image(type: ExtractZod<typeof RelayImageEnumType>, props: ExtractZod<typeof RelayImageType>): Promise<void>;
1266
+ image(type: ExtractZod<typeof RelayImageEnumType>, props: ExtractZod<typeof RelayImageType>): Promise<{
1267
+ chatId: string;
1268
+ channelId: string;
1269
+ uniqueId: string;
1270
+ receiverId: string;
1271
+ receiverName: string;
1272
+ roomId: string;
1273
+ roomName: string;
1274
+ senderLid: string;
1275
+ senderId: string;
1276
+ senderName: string;
1277
+ senderDevice: "unknown" | "android" | "ios" | "desktop" | "web";
1278
+ chatType: "contacts" | "event" | "text" | "image" | "contact" | "location" | "document" | "audio" | "video" | "protocol" | "highlyStructured" | "sendPayment" | "requestPayment" | "declinePaymentRequest" | "cancelPaymentRequest" | "template" | "sticker" | "groupInvite" | "buttons" | "product" | "deviceSent" | "list" | "viewOnce" | "order" | "ephemeral" | "invoice" | "paymentInvite" | "interactive" | "reaction" | "interactiveResponse" | "pollCreation" | "pollUpdate" | "keepInChat" | "requestPhoneNumber" | "scheduledCallCreation" | "groupMentioned" | "pinInChat" | "scheduledCallEdit" | "ptv" | "botInvoke" | "callLog" | "encComment" | "bcall" | "lottieSticker" | "comment" | "placeholder" | "encEventUpdate";
1279
+ timestamp: number;
1280
+ mentions: string[];
1281
+ links: string[];
1282
+ isPrefix: boolean;
1283
+ isSpam: boolean;
1284
+ isFromMe: boolean;
1285
+ isTagMe: boolean;
1286
+ isGroup: boolean;
1287
+ isStory: boolean;
1288
+ isViewOnce: boolean;
1289
+ isEdited: boolean;
1290
+ isDeleted: boolean;
1291
+ isPinned: boolean;
1292
+ isUnPinned: boolean;
1293
+ isChannel: boolean;
1294
+ isBroadcast: boolean;
1295
+ isEphemeral: boolean;
1296
+ isForwarded: boolean;
1297
+ message: z.core.$InferOuterFunctionType<z.ZodTuple<readonly [], null>, z.ZodRecord<z.ZodString, z.ZodAny>>;
1298
+ text?: string;
1299
+ citation?: Record<string, boolean>;
1300
+ media?: {
1301
+ [x: string]: unknown;
1302
+ buffer: z.core.$InferOuterFunctionType<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>;
1303
+ stream: z.core.$InferOuterFunctionType<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>;
1304
+ };
1305
+ replied?: {
1306
+ chatId: string;
1307
+ channelId: string;
1308
+ uniqueId: string;
1309
+ receiverId: string;
1310
+ receiverName: string;
1311
+ roomId: string;
1312
+ roomName: string;
1313
+ senderLid: string;
1314
+ senderId: string;
1315
+ senderName: string;
1316
+ senderDevice: "unknown" | "android" | "ios" | "desktop" | "web";
1317
+ chatType: "contacts" | "event" | "text" | "image" | "contact" | "location" | "document" | "audio" | "video" | "protocol" | "highlyStructured" | "sendPayment" | "requestPayment" | "declinePaymentRequest" | "cancelPaymentRequest" | "template" | "sticker" | "groupInvite" | "buttons" | "product" | "deviceSent" | "list" | "viewOnce" | "order" | "ephemeral" | "invoice" | "paymentInvite" | "interactive" | "reaction" | "interactiveResponse" | "pollCreation" | "pollUpdate" | "keepInChat" | "requestPhoneNumber" | "scheduledCallCreation" | "groupMentioned" | "pinInChat" | "scheduledCallEdit" | "ptv" | "botInvoke" | "callLog" | "encComment" | "bcall" | "lottieSticker" | "comment" | "placeholder" | "encEventUpdate";
1318
+ timestamp: number;
1319
+ mentions: string[];
1320
+ links: string[];
1321
+ isPrefix: boolean;
1322
+ isSpam: boolean;
1323
+ isFromMe: boolean;
1324
+ isTagMe: boolean;
1325
+ isGroup: boolean;
1326
+ isStory: boolean;
1327
+ isViewOnce: boolean;
1328
+ isEdited: boolean;
1329
+ isDeleted: boolean;
1330
+ isPinned: boolean;
1331
+ isUnPinned: boolean;
1332
+ isChannel: boolean;
1333
+ isBroadcast: boolean;
1334
+ isEphemeral: boolean;
1335
+ isForwarded: boolean;
1336
+ message: z.core.$InferOuterFunctionType<z.ZodTuple<readonly [], null>, z.ZodRecord<z.ZodString, z.ZodAny>>;
1337
+ text?: string;
1338
+ citation?: Record<string, boolean>;
1339
+ media?: {
1340
+ [x: string]: unknown;
1341
+ buffer: z.core.$InferOuterFunctionType<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>;
1342
+ stream: z.core.$InferOuterFunctionType<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>;
1343
+ };
1344
+ replied?: /*elided*/ any;
1345
+ };
1346
+ }>;
1265
1347
  sticker(type: ExtractZod<typeof RelayStickerEnumType>, props: ExtractZod<typeof RelayStickerType>): Promise<void>;
1266
1348
  video(type: ExtractZod<typeof RelayVideoEnumType>, props: ExtractZod<typeof RelayVideoType>): Promise<void>;
1267
1349
  audio(type: ExtractZod<typeof RelayAudioEnumType>, props: ExtractZod<typeof RelayAudioType>): Promise<void>;
@@ -1350,7 +1432,7 @@ declare class Client {
1350
1432
  interface Client extends Relay {
1351
1433
  }
1352
1434
 
1353
- declare const toJson: <T = unknown>(object: unknown) => T;
1435
+ declare const toJson: (object: unknown) => any;
1354
1436
  declare const toString: (object: unknown) => string;
1355
1437
  declare const shuffleString: (str: string) => string;
1356
1438
  declare const tryAgain: <T>(fn: () => Promise<T>) => Promise<T>;
@@ -1360,5 +1442,6 @@ declare const extractJids: (text?: string) => string[];
1360
1442
  declare const extractUrls: (text?: string) => string[];
1361
1443
  declare const getMentions: (text?: string) => string[];
1362
1444
  declare const randomize: (arr: string[]) => string;
1445
+ declare const delay: (ms: number) => Promise<unknown>;
1363
1446
 
1364
- export { AdsReplyType, CitationType, Client, ClientAuthPairingType, ClientAuthQRType, ClientBaseType, ClientOptionsType, type EventCallbackType, EventEnumType, type ExtractZod, ExtractorCallsType, ExtractorConnectionType, ExtractorMessagesType, FakeReplyType, JsonDB, type JsonDBInterface, LimiterType, MessagesDeviceEnumType, MessagesEnumType, MessagesMediaType, MessagesVerifiedPlatformType, PluginsType, defaultBoolean, defaultString, extractJids, extractUrls, findWord, getMentions, normalizeText, randomize, shuffleString, toJson, toString, tryAgain };
1447
+ export { AdsReplyType, CitationType, Client, ClientAuthPairingType, ClientAuthQRType, ClientBaseType, ClientOptionsType, type EventCallbackType, EventEnumType, type ExtractZod, ExtractorCallsType, ExtractorConnectionType, ExtractorMessagesType, FakeReplyType, JsonDB, type JsonDBInterface, LimiterType, MessagesDeviceEnumType, MessagesEnumType, MessagesMediaType, MessagesVerifiedPlatformType, PluginsType, defaultBoolean, defaultString, delay, extractJids, extractUrls, findWord, getMentions, normalizeText, randomize, shuffleString, toJson, toString, tryAgain };
package/dist/index.js CHANGED
@@ -98,6 +98,9 @@ var getMentions = (text = "") => {
98
98
  var randomize = (arr) => {
99
99
  return arr[Math.floor(Math.random() * arr.length)];
100
100
  };
101
+ var delay = (ms) => {
102
+ return new Promise((resolve) => setTimeout(resolve, ms));
103
+ };
101
104
  var CHUNK_SIZE = 1e3;
102
105
  var JsonDB = class {
103
106
  session = "zaileys-sessions";
@@ -696,10 +699,10 @@ var LimiterHandler = async (key, max, ms) => {
696
699
  };
697
700
 
698
701
  // src/extractor/messages.ts
699
- var MessagesExtractor = async (client, message) => {
702
+ var MessagesExtractor = async (client, message, isExtract) => {
700
703
  let MAX_REPLIES = 0;
701
704
  const CLONE = message;
702
- const extract = async (obj, isReplied, isExtract) => {
705
+ const extract = async (obj, isReplied) => {
703
706
  let msg = toJson(obj);
704
707
  if (!msg.message || !msg?.key?.id) {
705
708
  return null;
@@ -707,7 +710,7 @@ var MessagesExtractor = async (client, message) => {
707
710
  if (msg?.messageStubType || !!msg?.messageStubParameters || msg?.message?.botInvokeMessage || msg.message?.protocolMessage?.peerDataOperationRequestResponseMessage) {
708
711
  return null;
709
712
  }
710
- if (msg?.key?.fromMe && msg?.key?.remoteJid != "status@broadcast" && client.props?.ignoreMe && !MAX_REPLIES && true) {
713
+ if (msg?.key?.fromMe && msg?.key?.remoteJid != "status@broadcast" && client.props?.ignoreMe && !MAX_REPLIES && !isExtract) {
711
714
  return null;
712
715
  }
713
716
  const pinId = msg?.message?.pinInChatMessage?.key?.id;
@@ -786,7 +789,7 @@ var MessagesExtractor = async (client, message) => {
786
789
  payload.isBroadcast = !!message?.broadcast;
787
790
  payload.isEphemeral = false;
788
791
  payload.isForwarded = false;
789
- if (!isReplied && true) {
792
+ if (!isReplied && !isExtract) {
790
793
  const limiter = await LimiterHandler(payload.roomId, client.props.limiter?.maxMessages || 3, client.props.limiter?.durationMs || 5e3);
791
794
  payload.isSpam = limiter;
792
795
  }
@@ -1121,7 +1124,8 @@ var RelayButtonSimpleType = z2.z.object({
1121
1124
  id: z2.z.string(),
1122
1125
  text: z2.z.string()
1123
1126
  }).array(),
1124
- roomId: z2.z.string().optional()
1127
+ roomId: z2.z.string().optional(),
1128
+ externalAdReply: AdsReplyType.optional()
1125
1129
  });
1126
1130
  var RelayButtonInteractiveReplyType = z2.z.object({
1127
1131
  type: z2.z.literal("quick_reply"),
@@ -1151,13 +1155,15 @@ var RelayButtonInteractiveType = z2.z.object({
1151
1155
  text: z2.z.string(),
1152
1156
  footer: z2.z.string().optional(),
1153
1157
  buttons: z2.z.discriminatedUnion("type", [RelayButtonInteractiveReplyType, RelayButtonInteractiveUrlType, RelayButtonInteractiveCopyType, RelayButtonInteractiveCallType]).array(),
1154
- roomId: z2.z.string().optional()
1158
+ roomId: z2.z.string().optional(),
1159
+ externalAdReply: AdsReplyType.optional()
1155
1160
  });
1156
1161
  z2.z.object({
1157
1162
  type: z2.z.literal("list"),
1158
1163
  text: z2.z.string(),
1159
1164
  footer: z2.z.string(),
1160
- roomId: z2.z.string().optional()
1165
+ roomId: z2.z.string().optional(),
1166
+ externalAdReply: AdsReplyType.optional()
1161
1167
  });
1162
1168
  var RelayButtonType = z2.z.discriminatedUnion("type", [RelayButtonSimpleType, RelayButtonInteractiveType]);
1163
1169
  var RelayGroupCreateType = z2.z.object({
@@ -1300,7 +1306,7 @@ var Relay = class {
1300
1306
  text: params,
1301
1307
  ...extend
1302
1308
  });
1303
- return await MessagesExtractor(this.ctx, res);
1309
+ return await MessagesExtractor(this.ctx, res, true);
1304
1310
  }
1305
1311
  }
1306
1312
  if (typeof params == "object") {
@@ -1313,7 +1319,7 @@ var Relay = class {
1313
1319
  obj.text = params?.text;
1314
1320
  }
1315
1321
  const res = await this.client.socket.sendMessage(params?.roomId || this.message?.roomId, obj);
1316
- return await MessagesExtractor(this.ctx, res);
1322
+ return await MessagesExtractor(this.ctx, res, true);
1317
1323
  }
1318
1324
  }
1319
1325
  }
@@ -1335,7 +1341,7 @@ var Relay = class {
1335
1341
  if (typeof params == "string") {
1336
1342
  if (this.client.socket) {
1337
1343
  const res = await this.client.socket.sendMessage(this.message?.roomId, { text: params, ...extend }, options);
1338
- return await MessagesExtractor(this.ctx, res);
1344
+ return await MessagesExtractor(this.ctx, res, true);
1339
1345
  }
1340
1346
  }
1341
1347
  if (typeof params == "object") {
@@ -1348,7 +1354,7 @@ var Relay = class {
1348
1354
  obj.text = params?.text;
1349
1355
  }
1350
1356
  const res = await this.client.socket.sendMessage(params?.roomId || this.message?.roomId, obj, options);
1351
- return await MessagesExtractor(this.ctx, res);
1357
+ return await MessagesExtractor(this.ctx, res, true);
1352
1358
  }
1353
1359
  }
1354
1360
  }
@@ -1369,7 +1375,7 @@ var Relay = class {
1369
1375
  if (typeof params == "string") {
1370
1376
  if (this.client.socket) {
1371
1377
  const res = await this.client.socket.sendMessage(this.message?.roomId, { text: params, ...extend });
1372
- return await MessagesExtractor(this.ctx, res);
1378
+ return await MessagesExtractor(this.ctx, res, true);
1373
1379
  }
1374
1380
  }
1375
1381
  if (typeof params == "object") {
@@ -1385,7 +1391,7 @@ var Relay = class {
1385
1391
  obj.text = params?.text;
1386
1392
  }
1387
1393
  const res = await this.client.socket.sendMessage(params?.roomId || this.message?.roomId, obj);
1388
- return await MessagesExtractor(this.ctx, res);
1394
+ return await MessagesExtractor(this.ctx, res, true);
1389
1395
  }
1390
1396
  }
1391
1397
  }
@@ -1394,14 +1400,14 @@ var Relay = class {
1394
1400
  const params = RelayEditType.parse(props);
1395
1401
  const message = params.message();
1396
1402
  const res = await this.client.socket.sendMessage(message?.key?.remoteJid, { text: params.text, edit: message?.key });
1397
- return await MessagesExtractor(this.ctx, res);
1403
+ return await MessagesExtractor(this.ctx, res, true);
1398
1404
  }
1399
1405
  async delete(props) {
1400
1406
  await this.initial({ disabledPresence: true });
1401
1407
  const params = RelayDeleteType.parse(props);
1402
1408
  const message = params.message();
1403
1409
  const res = await this.client.socket.sendMessage(message?.key?.remoteJid, { delete: message?.key });
1404
- return await MessagesExtractor(this.ctx, res);
1410
+ return await MessagesExtractor(this.ctx, res, true);
1405
1411
  }
1406
1412
  async reject(props) {
1407
1413
  const params = RelayRejectType.parse(props);
@@ -1425,7 +1431,7 @@ var Relay = class {
1425
1431
  const message = typeof params == "string" ? this.message.message() : params.message();
1426
1432
  const text = typeof params == "string" ? params : params.emoticon;
1427
1433
  const res = await this.client.socket.sendMessage(message?.key?.remoteJid, { react: { text, key: message?.key } });
1428
- return await MessagesExtractor(this.ctx, res);
1434
+ return await MessagesExtractor(this.ctx, res, true);
1429
1435
  }
1430
1436
  // MEDIA RELAY
1431
1437
  async document(type, props) {
@@ -1447,11 +1453,12 @@ var Relay = class {
1447
1453
  const params = RelayImageType.parse(props);
1448
1454
  const options = {
1449
1455
  image: typeof params.image === "string" ? { url: params.image } : params.image,
1456
+ jpegThumbnail: params.image,
1450
1457
  caption: params.text,
1451
1458
  viewOnce: params.viewOnce,
1452
1459
  contextInfo: { externalAdReply: params.externalAdReply, isQuestion: true }
1453
1460
  };
1454
- this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
1461
+ return this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
1455
1462
  }
1456
1463
  async sticker(type, props) {
1457
1464
  await this.initial();
@@ -1567,7 +1574,8 @@ var Relay = class {
1567
1574
  const params = RelayButtonType.parse(props);
1568
1575
  const options = {
1569
1576
  text: params.text,
1570
- footer: params.footer
1577
+ footer: params.footer,
1578
+ contextInfo: { externalAdReply: params.externalAdReply }
1571
1579
  };
1572
1580
  if (params.type == "simple") {
1573
1581
  options.buttons = params.buttons.map((x) => ({ buttonId: x.id, buttonText: { displayText: x.text } }));
@@ -2012,6 +2020,7 @@ exports.MessagesVerifiedPlatformType = MessagesVerifiedPlatformType;
2012
2020
  exports.PluginsType = PluginsType;
2013
2021
  exports.defaultBoolean = defaultBoolean;
2014
2022
  exports.defaultString = defaultString;
2023
+ exports.delay = delay;
2015
2024
  exports.extractJids = extractJids;
2016
2025
  exports.extractUrls = extractUrls;
2017
2026
  exports.findWord = findWord;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import makeWASocket, { BufferJSON, delay, fetchLatestBaileysVersion, makeCacheableSignalKeyStore, DisconnectReason, jidNormalizedUser, initAuthCreds, getContentType, getDevice, downloadMediaMessage } from 'baileys';
1
+ import makeWASocket, { BufferJSON, delay as delay$1, fetchLatestBaileysVersion, makeCacheableSignalKeyStore, DisconnectReason, jidNormalizedUser, initAuthCreds, getContentType, getDevice, downloadMediaMessage } from 'baileys';
2
2
  import EventEmitter from 'events';
3
3
  import { createSpinner } from 'nanospinner';
4
4
  import NodeCache2 from 'node-cache';
@@ -82,6 +82,9 @@ var getMentions = (text = "") => {
82
82
  var randomize = (arr) => {
83
83
  return arr[Math.floor(Math.random() * arr.length)];
84
84
  };
85
+ var delay = (ms) => {
86
+ return new Promise((resolve) => setTimeout(resolve, ms));
87
+ };
85
88
  var CHUNK_SIZE = 1e3;
86
89
  var JsonDB = class {
87
90
  session = "zaileys-sessions";
@@ -680,10 +683,10 @@ var LimiterHandler = async (key, max, ms) => {
680
683
  };
681
684
 
682
685
  // src/extractor/messages.ts
683
- var MessagesExtractor = async (client, message) => {
686
+ var MessagesExtractor = async (client, message, isExtract) => {
684
687
  let MAX_REPLIES = 0;
685
688
  const CLONE = message;
686
- const extract = async (obj, isReplied, isExtract) => {
689
+ const extract = async (obj, isReplied) => {
687
690
  let msg = toJson(obj);
688
691
  if (!msg.message || !msg?.key?.id) {
689
692
  return null;
@@ -691,7 +694,7 @@ var MessagesExtractor = async (client, message) => {
691
694
  if (msg?.messageStubType || !!msg?.messageStubParameters || msg?.message?.botInvokeMessage || msg.message?.protocolMessage?.peerDataOperationRequestResponseMessage) {
692
695
  return null;
693
696
  }
694
- if (msg?.key?.fromMe && msg?.key?.remoteJid != "status@broadcast" && client.props?.ignoreMe && !MAX_REPLIES && true) {
697
+ if (msg?.key?.fromMe && msg?.key?.remoteJid != "status@broadcast" && client.props?.ignoreMe && !MAX_REPLIES && !isExtract) {
695
698
  return null;
696
699
  }
697
700
  const pinId = msg?.message?.pinInChatMessage?.key?.id;
@@ -770,7 +773,7 @@ var MessagesExtractor = async (client, message) => {
770
773
  payload.isBroadcast = !!message?.broadcast;
771
774
  payload.isEphemeral = false;
772
775
  payload.isForwarded = false;
773
- if (!isReplied && true) {
776
+ if (!isReplied && !isExtract) {
774
777
  const limiter = await LimiterHandler(payload.roomId, client.props.limiter?.maxMessages || 3, client.props.limiter?.durationMs || 5e3);
775
778
  payload.isSpam = limiter;
776
779
  }
@@ -895,7 +898,7 @@ var Listener = class {
895
898
  }
896
899
  async handleSessionClosing() {
897
900
  this.client.spinner.start("Processing session changes...");
898
- await delay(3e3);
901
+ await delay$1(3e3);
899
902
  this.client.spinner.success("Session processing completed");
900
903
  }
901
904
  async connection(update) {
@@ -1105,7 +1108,8 @@ var RelayButtonSimpleType = z.object({
1105
1108
  id: z.string(),
1106
1109
  text: z.string()
1107
1110
  }).array(),
1108
- roomId: z.string().optional()
1111
+ roomId: z.string().optional(),
1112
+ externalAdReply: AdsReplyType.optional()
1109
1113
  });
1110
1114
  var RelayButtonInteractiveReplyType = z.object({
1111
1115
  type: z.literal("quick_reply"),
@@ -1135,13 +1139,15 @@ var RelayButtonInteractiveType = z.object({
1135
1139
  text: z.string(),
1136
1140
  footer: z.string().optional(),
1137
1141
  buttons: z.discriminatedUnion("type", [RelayButtonInteractiveReplyType, RelayButtonInteractiveUrlType, RelayButtonInteractiveCopyType, RelayButtonInteractiveCallType]).array(),
1138
- roomId: z.string().optional()
1142
+ roomId: z.string().optional(),
1143
+ externalAdReply: AdsReplyType.optional()
1139
1144
  });
1140
1145
  z.object({
1141
1146
  type: z.literal("list"),
1142
1147
  text: z.string(),
1143
1148
  footer: z.string(),
1144
- roomId: z.string().optional()
1149
+ roomId: z.string().optional(),
1150
+ externalAdReply: AdsReplyType.optional()
1145
1151
  });
1146
1152
  var RelayButtonType = z.discriminatedUnion("type", [RelayButtonSimpleType, RelayButtonInteractiveType]);
1147
1153
  var RelayGroupCreateType = z.object({
@@ -1259,7 +1265,7 @@ var Relay = class {
1259
1265
  });
1260
1266
  }
1261
1267
  async initial(props) {
1262
- await delay(0);
1268
+ await delay$1(0);
1263
1269
  if (!props?.disabledPresence) {
1264
1270
  if (this.client.props?.autoPresence) {
1265
1271
  if (props?.isAudio) {
@@ -1284,7 +1290,7 @@ var Relay = class {
1284
1290
  text: params,
1285
1291
  ...extend
1286
1292
  });
1287
- return await MessagesExtractor(this.ctx, res);
1293
+ return await MessagesExtractor(this.ctx, res, true);
1288
1294
  }
1289
1295
  }
1290
1296
  if (typeof params == "object") {
@@ -1297,7 +1303,7 @@ var Relay = class {
1297
1303
  obj.text = params?.text;
1298
1304
  }
1299
1305
  const res = await this.client.socket.sendMessage(params?.roomId || this.message?.roomId, obj);
1300
- return await MessagesExtractor(this.ctx, res);
1306
+ return await MessagesExtractor(this.ctx, res, true);
1301
1307
  }
1302
1308
  }
1303
1309
  }
@@ -1319,7 +1325,7 @@ var Relay = class {
1319
1325
  if (typeof params == "string") {
1320
1326
  if (this.client.socket) {
1321
1327
  const res = await this.client.socket.sendMessage(this.message?.roomId, { text: params, ...extend }, options);
1322
- return await MessagesExtractor(this.ctx, res);
1328
+ return await MessagesExtractor(this.ctx, res, true);
1323
1329
  }
1324
1330
  }
1325
1331
  if (typeof params == "object") {
@@ -1332,7 +1338,7 @@ var Relay = class {
1332
1338
  obj.text = params?.text;
1333
1339
  }
1334
1340
  const res = await this.client.socket.sendMessage(params?.roomId || this.message?.roomId, obj, options);
1335
- return await MessagesExtractor(this.ctx, res);
1341
+ return await MessagesExtractor(this.ctx, res, true);
1336
1342
  }
1337
1343
  }
1338
1344
  }
@@ -1353,7 +1359,7 @@ var Relay = class {
1353
1359
  if (typeof params == "string") {
1354
1360
  if (this.client.socket) {
1355
1361
  const res = await this.client.socket.sendMessage(this.message?.roomId, { text: params, ...extend });
1356
- return await MessagesExtractor(this.ctx, res);
1362
+ return await MessagesExtractor(this.ctx, res, true);
1357
1363
  }
1358
1364
  }
1359
1365
  if (typeof params == "object") {
@@ -1369,7 +1375,7 @@ var Relay = class {
1369
1375
  obj.text = params?.text;
1370
1376
  }
1371
1377
  const res = await this.client.socket.sendMessage(params?.roomId || this.message?.roomId, obj);
1372
- return await MessagesExtractor(this.ctx, res);
1378
+ return await MessagesExtractor(this.ctx, res, true);
1373
1379
  }
1374
1380
  }
1375
1381
  }
@@ -1378,14 +1384,14 @@ var Relay = class {
1378
1384
  const params = RelayEditType.parse(props);
1379
1385
  const message = params.message();
1380
1386
  const res = await this.client.socket.sendMessage(message?.key?.remoteJid, { text: params.text, edit: message?.key });
1381
- return await MessagesExtractor(this.ctx, res);
1387
+ return await MessagesExtractor(this.ctx, res, true);
1382
1388
  }
1383
1389
  async delete(props) {
1384
1390
  await this.initial({ disabledPresence: true });
1385
1391
  const params = RelayDeleteType.parse(props);
1386
1392
  const message = params.message();
1387
1393
  const res = await this.client.socket.sendMessage(message?.key?.remoteJid, { delete: message?.key });
1388
- return await MessagesExtractor(this.ctx, res);
1394
+ return await MessagesExtractor(this.ctx, res, true);
1389
1395
  }
1390
1396
  async reject(props) {
1391
1397
  const params = RelayRejectType.parse(props);
@@ -1409,7 +1415,7 @@ var Relay = class {
1409
1415
  const message = typeof params == "string" ? this.message.message() : params.message();
1410
1416
  const text = typeof params == "string" ? params : params.emoticon;
1411
1417
  const res = await this.client.socket.sendMessage(message?.key?.remoteJid, { react: { text, key: message?.key } });
1412
- return await MessagesExtractor(this.ctx, res);
1418
+ return await MessagesExtractor(this.ctx, res, true);
1413
1419
  }
1414
1420
  // MEDIA RELAY
1415
1421
  async document(type, props) {
@@ -1431,11 +1437,12 @@ var Relay = class {
1431
1437
  const params = RelayImageType.parse(props);
1432
1438
  const options = {
1433
1439
  image: typeof params.image === "string" ? { url: params.image } : params.image,
1440
+ jpegThumbnail: params.image,
1434
1441
  caption: params.text,
1435
1442
  viewOnce: params.viewOnce,
1436
1443
  contextInfo: { externalAdReply: params.externalAdReply, isQuestion: true }
1437
1444
  };
1438
- this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
1445
+ return this[enumType]({ text: "$$media$$", roomId: params.roomId, options });
1439
1446
  }
1440
1447
  async sticker(type, props) {
1441
1448
  await this.initial();
@@ -1551,7 +1558,8 @@ var Relay = class {
1551
1558
  const params = RelayButtonType.parse(props);
1552
1559
  const options = {
1553
1560
  text: params.text,
1554
- footer: params.footer
1561
+ footer: params.footer,
1562
+ contextInfo: { externalAdReply: params.externalAdReply }
1555
1563
  };
1556
1564
  if (params.type == "simple") {
1557
1565
  options.buttons = params.buttons.map((x) => ({ buttonId: x.id, buttonText: { displayText: x.text } }));
@@ -1874,7 +1882,7 @@ var Client = class {
1874
1882
  async initialize() {
1875
1883
  console.clear();
1876
1884
  await displayBanner();
1877
- await delay(1e3);
1885
+ await delay$1(1e3);
1878
1886
  await this.spinner.start("Initializing database...");
1879
1887
  const { db, state, store, saveCreds } = await CredsHandler(this.props);
1880
1888
  await this.spinner.start("Fetching newest version...");
@@ -1951,7 +1959,7 @@ var Client = class {
1951
1959
  this.socket.end?.(void 0);
1952
1960
  this.socket = void 0;
1953
1961
  }
1954
- await delay(2e3);
1962
+ await delay$1(2e3);
1955
1963
  await this.initialize();
1956
1964
  } catch (error) {
1957
1965
  this.spinner.error(`Auto-reload failed: ${error.message}`);
@@ -1975,4 +1983,4 @@ var ExtractorConnectionType = z.object({
1975
1983
  status: z.enum(["connecting", "open", "close"])
1976
1984
  });
1977
1985
 
1978
- export { AdsReplyType, CitationType, Client, ClientAuthPairingType, ClientAuthQRType, ClientBaseType, ClientOptionsType, EventEnumType, ExtractorCallsType, ExtractorConnectionType, ExtractorMessagesType, FakeReplyType, JsonDB, LimiterType, MessagesDeviceEnumType, MessagesEnumType, MessagesMediaType, MessagesVerifiedPlatformType, PluginsType, defaultBoolean, defaultString, extractJids, extractUrls, findWord, getMentions, normalizeText, randomize, shuffleString, toJson, toString, tryAgain };
1986
+ export { AdsReplyType, CitationType, Client, ClientAuthPairingType, ClientAuthQRType, ClientBaseType, ClientOptionsType, EventEnumType, ExtractorCallsType, ExtractorConnectionType, ExtractorMessagesType, FakeReplyType, JsonDB, LimiterType, MessagesDeviceEnumType, MessagesEnumType, MessagesMediaType, MessagesVerifiedPlatformType, PluginsType, defaultBoolean, defaultString, delay, extractJids, extractUrls, findWord, getMentions, normalizeText, randomize, shuffleString, toJson, toString, tryAgain };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zaileys",
3
- "version": "1.1.38",
3
+ "version": "1.1.39",
4
4
  "description": "Zaileys - Simplified WhatsApp Node.js API",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",