@mrlegendbot/baileys 1.1.0 → 1.1.1

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.
@@ -410,6 +410,34 @@ export const makeMessagesSocket = (config) => {
410
410
  };
411
411
 
412
412
  const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
413
+ const normalizedForStatus = normalizeMessageContent(message);
414
+ const hasGroupStatusWrapper = Boolean(normalizedForStatus?.groupStatusMessageV2 || normalizedForStatus?.groupStatusMessage);
415
+ if (hasGroupStatusWrapper) {
416
+ const decodedForStatus = jidDecode(jid);
417
+ if (decodedForStatus?.server === 'g.us') {
418
+ try {
419
+ if (!statusJidList?.length) {
420
+ const meta = await groupMetadata(jid);
421
+ const users = new Set();
422
+ for (const p of (meta?.participants || [])) {
423
+ const pj = jidNormalizedUser(p.id);
424
+ if (pj) users.add(pj);
425
+ }
426
+ const ownJid = jidNormalizedUser(authState.creds.me.id);
427
+ if (ownJid) users.add(ownJid);
428
+ statusJidList = [...users];
429
+ }
430
+ if (statusJidList?.length) {
431
+ logger.debug({ jid, audience: statusJidList.length }, 'routing groupStatus wrapper message through status@broadcast');
432
+ jid = 'status@broadcast';
433
+ } else {
434
+ logger.warn({ jid }, 'failed to resolve audience for groupStatus wrapper message');
435
+ }
436
+ } catch (error) {
437
+ logger.warn({ jid, trace: error?.stack || String(error) }, 'failed to resolve audience for groupStatus wrapper message');
438
+ }
439
+ }
440
+ }
413
441
  const meId = assertMeId(authState.creds);
414
442
  const meLid = authState.creds.me?.lid;
415
443
  const isRetryResend = Boolean(participant?.jid);
@@ -862,6 +890,9 @@ export const makeMessagesSocket = (config) => {
862
890
  if (normalizedMessage.eventMessage) {
863
891
  return 'event';
864
892
  }
893
+ if (normalizedMessage.groupStatusMessage) {
894
+ return 'group_status';
895
+ }
865
896
  if (getMediaType(normalizedMessage) !== '') {
866
897
  return 'media';
867
898
  }
@@ -914,6 +945,13 @@ export const makeMessagesSocket = (config) => {
914
945
  else if (message.groupInviteMessage) {
915
946
  return 'url';
916
947
  }
948
+ else if (message.groupStatusMessage) {
949
+ if (message.groupStatusMessage.image) return 'image';
950
+ if (message.groupStatusMessage.video) return 'video';
951
+ if (message.groupStatusMessage.audio) return 'audio';
952
+ if (message.groupStatusMessage.sticker) return 'sticker';
953
+ return 'text';
954
+ }
917
955
  return '';
918
956
  };
919
957
 
@@ -1155,6 +1193,117 @@ export const makeMessagesSocket = (config) => {
1155
1193
  }
1156
1194
  });
1157
1195
 
1196
+ const sendMessage = async (jid, content, options = {}) => {
1197
+ if (content.groupStatusMessage || content.groupStatus) {
1198
+ const statusContent = content.groupStatusMessage || content.groupStatus;
1199
+ const fullMsg = await generateWAMessage(jid, {
1200
+ groupStatusMessage: statusContent
1201
+ }, {
1202
+ logger,
1203
+ userJid: authState.creds.me.id,
1204
+ upload: waUploadToServer,
1205
+ mediaCache: config.mediaCache,
1206
+ messageId: generateMessageIDV2(sock.user?.id)
1207
+ });
1208
+ await relayMessage(jid, fullMsg.message, {
1209
+ messageId: fullMsg.key.id,
1210
+ additionalAttributes: { type: 'group_status' },
1211
+ additionalNodes: [{ tag: 'meta', attrs: { type: 'group_status' } }]
1212
+ });
1213
+ if (config.emitOwnEvents) {
1214
+ process.nextTick(async () => {
1215
+ await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
1216
+ });
1217
+ }
1218
+ return fullMsg;
1219
+ }
1220
+ const userJid = authState.creds.me.id;
1221
+ if (typeof content === 'object' &&
1222
+ 'disappearingMessagesInChat' in content &&
1223
+ typeof content['disappearingMessagesInChat'] !== 'undefined' &&
1224
+ isJidGroup(jid)) {
1225
+ const { disappearingMessagesInChat } = content;
1226
+ const value = typeof disappearingMessagesInChat === 'boolean'
1227
+ ? disappearingMessagesInChat
1228
+ ? WA_DEFAULT_EPHEMERAL
1229
+ : 0
1230
+ : disappearingMessagesInChat;
1231
+ await groupToggleEphemeral(jid, value);
1232
+ }
1233
+ else {
1234
+ const fullMsg = await generateWAMessage(jid, content, {
1235
+ logger,
1236
+ userJid,
1237
+ getUrlInfo: text => getUrlInfo(text, {
1238
+ thumbnailWidth: linkPreviewImageThumbnailWidth,
1239
+ fetchOpts: {
1240
+ timeout: 3000,
1241
+ ...(httpRequestOptions || {})
1242
+ },
1243
+ logger,
1244
+ uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
1245
+ }),
1246
+ getProfilePicUrl: sock.profilePictureUrl,
1247
+ getCallLink: sock.createCallLink,
1248
+ upload: waUploadToServer,
1249
+ mediaCache: config.mediaCache,
1250
+ options: config.options,
1251
+ messageId: generateMessageIDV2(sock.user?.id),
1252
+ ...options
1253
+ });
1254
+ const isEventMsg = 'event' in content && !!content.event;
1255
+ const isDeleteMsg = 'delete' in content && !!content.delete;
1256
+ const isEditMsg = 'edit' in content && !!content.edit;
1257
+ const isPinMsg = 'pin' in content && !!content.pin;
1258
+ const isPollMessage = 'poll' in content && !!content.poll;
1259
+ const additionalAttributes = {};
1260
+ const additionalNodes = [];
1261
+ if (isDeleteMsg) {
1262
+ if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
1263
+ additionalAttributes.edit = '8';
1264
+ }
1265
+ else {
1266
+ additionalAttributes.edit = '7';
1267
+ }
1268
+ }
1269
+ else if (isEditMsg) {
1270
+ additionalAttributes.edit = '1';
1271
+ }
1272
+ else if (isPinMsg) {
1273
+ additionalAttributes.edit = '2';
1274
+ }
1275
+ else if (isPollMessage) {
1276
+ additionalNodes.push({
1277
+ tag: 'meta',
1278
+ attrs: {
1279
+ polltype: 'creation'
1280
+ }
1281
+ });
1282
+ }
1283
+ else if (isEventMsg) {
1284
+ additionalNodes.push({
1285
+ tag: 'meta',
1286
+ attrs: {
1287
+ event_type: 'creation'
1288
+ }
1289
+ });
1290
+ }
1291
+ await relayMessage(jid, fullMsg.message, {
1292
+ messageId: fullMsg.key.id,
1293
+ useCachedGroupMetadata: options.useCachedGroupMetadata,
1294
+ additionalAttributes,
1295
+ statusJidList: options.statusJidList,
1296
+ additionalNodes
1297
+ });
1298
+ if (config.emitOwnEvents) {
1299
+ process.nextTick(async () => {
1300
+ await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
1301
+ });
1302
+ }
1303
+ return fullMsg;
1304
+ }
1305
+ };
1306
+
1158
1307
  const sendQuickReplyButtons = async (jid, text, buttons, footer = '') => {
1159
1308
  const message = createButtonsMessage(text, footer, buttons);
1160
1309
  return await sendMessage(jid, message);
@@ -1374,92 +1523,6 @@ export const makeMessagesSocket = (config) => {
1374
1523
  sendCatalogMessage,
1375
1524
  sendProductMessage,
1376
1525
  sendCollectionMessage,
1377
- sendMessage: async (jid, content, options = {}) => {
1378
- const userJid = authState.creds.me.id;
1379
- if (typeof content === 'object' &&
1380
- 'disappearingMessagesInChat' in content &&
1381
- typeof content['disappearingMessagesInChat'] !== 'undefined' &&
1382
- isJidGroup(jid)) {
1383
- const { disappearingMessagesInChat } = content;
1384
- const value = typeof disappearingMessagesInChat === 'boolean'
1385
- ? disappearingMessagesInChat
1386
- ? WA_DEFAULT_EPHEMERAL
1387
- : 0
1388
- : disappearingMessagesInChat;
1389
- await groupToggleEphemeral(jid, value);
1390
- }
1391
- else {
1392
- const fullMsg = await generateWAMessage(jid, content, {
1393
- logger,
1394
- userJid,
1395
- getUrlInfo: text => getUrlInfo(text, {
1396
- thumbnailWidth: linkPreviewImageThumbnailWidth,
1397
- fetchOpts: {
1398
- timeout: 3000,
1399
- ...(httpRequestOptions || {})
1400
- },
1401
- logger,
1402
- uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
1403
- }),
1404
- getProfilePicUrl: sock.profilePictureUrl,
1405
- getCallLink: sock.createCallLink,
1406
- upload: waUploadToServer,
1407
- mediaCache: config.mediaCache,
1408
- options: config.options,
1409
- messageId: generateMessageIDV2(sock.user?.id),
1410
- ...options
1411
- });
1412
- const isEventMsg = 'event' in content && !!content.event;
1413
- const isDeleteMsg = 'delete' in content && !!content.delete;
1414
- const isEditMsg = 'edit' in content && !!content.edit;
1415
- const isPinMsg = 'pin' in content && !!content.pin;
1416
- const isPollMessage = 'poll' in content && !!content.poll;
1417
- const additionalAttributes = {};
1418
- const additionalNodes = [];
1419
- if (isDeleteMsg) {
1420
- if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
1421
- additionalAttributes.edit = '8';
1422
- }
1423
- else {
1424
- additionalAttributes.edit = '7';
1425
- }
1426
- }
1427
- else if (isEditMsg) {
1428
- additionalAttributes.edit = '1';
1429
- }
1430
- else if (isPinMsg) {
1431
- additionalAttributes.edit = '2';
1432
- }
1433
- else if (isPollMessage) {
1434
- additionalNodes.push({
1435
- tag: 'meta',
1436
- attrs: {
1437
- polltype: 'creation'
1438
- }
1439
- });
1440
- }
1441
- else if (isEventMsg) {
1442
- additionalNodes.push({
1443
- tag: 'meta',
1444
- attrs: {
1445
- event_type: 'creation'
1446
- }
1447
- });
1448
- }
1449
- await relayMessage(jid, fullMsg.message, {
1450
- messageId: fullMsg.key.id,
1451
- useCachedGroupMetadata: options.useCachedGroupMetadata,
1452
- additionalAttributes,
1453
- statusJidList: options.statusJidList,
1454
- additionalNodes
1455
- });
1456
- if (config.emitOwnEvents) {
1457
- process.nextTick(async () => {
1458
- await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
1459
- });
1460
- }
1461
- return fullMsg;
1462
- }
1463
- }
1526
+ sendMessage
1464
1527
  };
1465
1528
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mrlegendbot/baileys",
3
3
  "type": "module",
4
- "version": "1.1.0",
4
+ "version": "1.1.1",
5
5
  "description": "A WebSockets library for interacting with WhatsApp Web",
6
6
  "keywords": [
7
7
  "whatsapp",