@nexustechpro/baileys 1.1.4 → 1.1.5

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.
@@ -17,13 +17,13 @@ const {
17
17
  extractDeviceJids, generateMessageIDV2, generateParticipantHashV2, generateWAMessage,
18
18
  getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager,
19
19
  normalizeMessageContent, parseAndInjectE2ESessions, unixTimestampSeconds,
20
- generateWAMessageFromContent, delay, generateMessageID
20
+ generateWAMessageFromContent, delay
21
21
  } = Utils
22
22
 
23
23
  const {
24
24
  areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser,
25
25
  isJidGroup, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET,
26
- getBinaryFilteredButtons, STORIES_JID, isJidUser, isJidNewsletter, getButtonArgs, getButtonType
26
+ getBinaryFilteredButtons, STORIES_JID, isJidUser, getButtonArgs, getButtonType
27
27
  } = WABinary
28
28
 
29
29
  export const makeMessagesSocket = (config) => {
@@ -282,183 +282,195 @@ export const makeMessagesSocket = (config) => {
282
282
  }
283
283
 
284
284
  // ===== RELAY MESSAGE =====
285
- const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList } = {}) => {
286
- const meId = authState.creds.me.id
287
- const meLid = authState.creds.me?.lid
288
- const isRetryResend = Boolean(participant?.jid)
289
- let shouldIncludeDeviceIdentity = isRetryResend
290
-
291
- const { user, server } = jidDecode(jid)
292
- const isGroup = server === 'g.us'
293
- const isStatus = jid === 'status@broadcast'
294
- const isLid = server === 'lid'
295
- const isNewsletter = server === 'newsletter'
296
-
297
- msgId = msgId || generateMessageIDV2(meId)
298
- useUserDevicesCache = useUserDevicesCache !== false
299
- useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus
285
+ const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList, quoted } = {}) => {
286
+ const meId = authState.creds.me.id
287
+ const meLid = authState.creds.me?.lid
288
+ const isRetryResend = Boolean(participant?.jid)
289
+ let shouldIncludeDeviceIdentity = isRetryResend
290
+ let finalMsgId = msgId
291
+
292
+ // Check if message is already in proper WAMessage format
293
+ const hasProtoMessageType = Object.keys(message).some(key => key.endsWith('Message') || key === 'conversation')
294
+
295
+ if (!hasProtoMessageType) {
296
+ logger.debug({ jid }, 'relayMessage: auto-generating message from raw content')
297
+ const generatedMsg = await generateWAMessage(jid, message, { logger, userJid: meId, getUrlInfo: text => getUrlInfo(text, { thumbnailWidth: linkPreviewImageThumbnailWidth, fetchOpts: { timeout: 3000, ...(httpRequestOptions || {}) }, logger, uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined }), getProfilePicUrl: sock.profilePictureUrl, getCallLink: sock.createCallLink, upload: waUploadToServer, mediaCache: config.mediaCache, options: config.options, messageId: finalMsgId || generateMessageIDV2(meId), quoted: quoted })
298
+ message = generatedMsg.message
299
+ if (!finalMsgId) finalMsgId = generatedMsg.key.id
300
+ logger.debug({ msgId: finalMsgId, jid }, 'message auto-generated successfully')
301
+ }
300
302
 
301
- const participants = []
302
- const destinationJid = !isStatus ? jid : 'status@broadcast'
303
- const binaryNodeContent = []
304
- const devices = []
303
+ const { user, server } = jidDecode(jid)
304
+ const isGroup = server === 'g.us'
305
+ const isStatus = jid === 'status@broadcast'
306
+ const isLid = server === 'lid'
307
+ const isNewsletter = server === 'newsletter'
308
+
309
+ finalMsgId = finalMsgId || generateMessageIDV2(meId)
310
+ useUserDevicesCache = useUserDevicesCache !== false
311
+ useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus
312
+
313
+ const participants = []
314
+ const destinationJid = !isStatus ? jid : 'status@broadcast'
315
+ const binaryNodeContent = []
316
+ const devices = []
317
+
318
+ const meMsg = { deviceSentMessage: { destinationJid, message }, messageContextInfo: message.messageContextInfo }
319
+ const extraAttrs = {}
320
+ const messages = normalizeMessageContent(message)
321
+ const buttonType = getButtonType(messages)
322
+
323
+ if (participant) {
324
+ if (!isGroup && !isStatus) additionalAttributes = { ...additionalAttributes, device_fanout: 'false' }
325
+ const { user, device } = jidDecode(participant.jid)
326
+ devices.push({ user, device, jid: participant.jid })
327
+ }
305
328
 
306
- const meMsg = { deviceSentMessage: { destinationJid, message }, messageContextInfo: message.messageContextInfo }
307
- const extraAttrs = {}
308
- const messages = normalizeMessageContent(message)
309
- const buttonType = getButtonType(messages)
329
+ await authState.keys.transaction(async () => {
330
+ const mediaType = getMediaType(message)
331
+ if (mediaType) extraAttrs.mediatype = mediaType
310
332
 
311
- if (participant) {
312
- if (!isGroup && !isStatus) additionalAttributes = { ...additionalAttributes, device_fanout: 'false' }
313
- const { user, device } = jidDecode(participant.jid)
314
- devices.push({ user, device, jid: participant.jid })
333
+ if (isNewsletter) {
334
+ const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message
335
+ const bytes = encodeNewsletterMessage(patched)
336
+ binaryNodeContent.push({ tag: 'plaintext', attrs: {}, content: bytes })
337
+ const stanza = { tag: 'message', attrs: { to: jid, id: finalMsgId, type: getMessageType(message), ...(additionalAttributes || {}) }, content: binaryNodeContent }
338
+ logger.debug({ msgId: finalMsgId }, `sending newsletter message to ${jid}`)
339
+ await sendNode(stanza)
340
+ return
315
341
  }
316
342
 
317
- await authState.keys.transaction(async () => {
318
- const mediaType = getMediaType(message)
319
- if (mediaType) extraAttrs.mediatype = mediaType
320
-
321
- if (isNewsletter) {
322
- const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message
323
- const bytes = encodeNewsletterMessage(patched)
324
- binaryNodeContent.push({ tag: 'plaintext', attrs: {}, content: bytes })
325
- const stanza = { tag: 'message', attrs: { to: jid, id: msgId, type: getMessageType(message), ...(additionalAttributes || {}) }, content: binaryNodeContent }
326
- logger.debug({ msgId }, `sending newsletter message to ${jid}`)
327
- await sendNode(stanza)
328
- return
329
- }
330
-
331
- if (messages.pinInChatMessage || messages.keepInChatMessage || message.reactionMessage || message.protocolMessage?.editedMessage) extraAttrs['decrypt-fail'] = 'hide'
332
-
333
- if (isGroup || isStatus) {
334
- const [groupData, senderKeyMap] = await Promise.all([
335
- (async () => {
336
- let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined
337
- if (groupData?.participants) logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata')
338
- else if (!isStatus) groupData = await groupMetadata(jid)
339
- return groupData
340
- })(),
341
- (async () => !participant && !isStatus ? (await authState.keys.get('sender-key-memory', [jid]))[jid] || {} : {})()
342
- ])
343
-
344
- if (!participant) {
345
- const participantsList = []
346
- if (isStatus) { if (statusJidList?.length) participantsList.push(...statusJidList) }
347
- else {
348
- let groupAddressingMode = 'lid'
349
- if (groupData) { participantsList.push(...groupData.participants.map(p => p.id)); groupAddressingMode = groupData?.addressingMode || groupAddressingMode }
350
- additionalAttributes = { ...additionalAttributes, addressing_mode: groupAddressingMode }
351
- }
352
- const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false)
353
- devices.push(...additionalDevices)
343
+ if (messages.pinInChatMessage || messages.keepInChatMessage || message.reactionMessage || message.protocolMessage?.editedMessage) extraAttrs['decrypt-fail'] = 'hide'
344
+
345
+ if (isGroup || isStatus) {
346
+ const [groupData, senderKeyMap] = await Promise.all([
347
+ (async () => {
348
+ let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined
349
+ if (groupData?.participants) logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata')
350
+ else if (!isStatus) groupData = await groupMetadata(jid)
351
+ return groupData
352
+ })(),
353
+ (async () => !participant && !isStatus ? (await authState.keys.get('sender-key-memory', [jid]))[jid] || {} : {})()
354
+ ])
355
+
356
+ if (!participant) {
357
+ const participantsList = []
358
+ if (isStatus) { if (statusJidList?.length) participantsList.push(...statusJidList) }
359
+ else {
360
+ let groupAddressingMode = 'lid'
361
+ if (groupData) { participantsList.push(...groupData.participants.map(p => p.id)); groupAddressingMode = groupData?.addressingMode || groupAddressingMode }
362
+ additionalAttributes = { ...additionalAttributes, addressing_mode: groupAddressingMode }
354
363
  }
364
+ const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false)
365
+ devices.push(...additionalDevices)
366
+ }
355
367
 
356
- if (groupData?.ephemeralDuration > 0) additionalAttributes = { ...additionalAttributes, expiration: groupData.ephemeralDuration.toString() }
368
+ if (groupData?.ephemeralDuration > 0) additionalAttributes = { ...additionalAttributes, expiration: groupData.ephemeralDuration.toString() }
357
369
 
358
- const patched = await patchMessageBeforeSending(message)
359
- if (Array.isArray(patched)) throw new Boom('Per-jid patching not supported in groups')
370
+ const patched = await patchMessageBeforeSending(message)
371
+ if (Array.isArray(patched)) throw new Boom('Per-jid patching not supported in groups')
360
372
 
361
- const bytes = encodeWAMessage(patched)
362
- const groupAddressingMode = additionalAttributes?.addressing_mode || groupData?.addressingMode || 'lid'
363
- const groupSenderIdentity = groupAddressingMode === 'lid' && meLid ? meLid : meId
373
+ const bytes = encodeWAMessage(patched)
374
+ const groupAddressingMode = additionalAttributes?.addressing_mode || groupData?.addressingMode || 'lid'
375
+ const groupSenderIdentity = groupAddressingMode === 'lid' && meLid ? meLid : meId
364
376
 
365
- const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({ group: destinationJid, data: bytes, meId: groupSenderIdentity })
377
+ const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({ group: destinationJid, data: bytes, meId: groupSenderIdentity })
366
378
 
367
- const senderKeyRecipients = []
368
- for (const device of devices) {
369
- const deviceJid = device.jid
370
- const hasKey = !!senderKeyMap[deviceJid]
371
- if ((!hasKey || !!participant) && !isHostedLidUser(deviceJid) && !isHostedPnUser(deviceJid) && device.device !== 99) { senderKeyRecipients.push(deviceJid); senderKeyMap[deviceJid] = true }
372
- }
379
+ const senderKeyRecipients = []
380
+ for (const device of devices) {
381
+ const deviceJid = device.jid
382
+ const hasKey = !!senderKeyMap[deviceJid]
383
+ if ((!hasKey || !!participant) && !isHostedLidUser(deviceJid) && !isHostedPnUser(deviceJid) && device.device !== 99) { senderKeyRecipients.push(deviceJid); senderKeyMap[deviceJid] = true }
384
+ }
373
385
 
374
- if (senderKeyRecipients.length) {
375
- logger.debug({ senderKeyJids: senderKeyRecipients }, 'sending sender key')
376
- const senderKeyMsg = { senderKeyDistributionMessage: { axolotlSenderKeyDistributionMessage: senderKeyDistributionMessage, groupId: destinationJid } }
377
- await assertSessions(senderKeyRecipients)
378
- const result = await createParticipantNodes(senderKeyRecipients, senderKeyMsg, extraAttrs)
379
- shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity
380
- participants.push(...result.nodes)
381
- }
386
+ if (senderKeyRecipients.length) {
387
+ logger.debug({ senderKeyJids: senderKeyRecipients }, 'sending sender key')
388
+ const senderKeyMsg = { senderKeyDistributionMessage: { axolotlSenderKeyDistributionMessage: senderKeyDistributionMessage, groupId: destinationJid } }
389
+ await assertSessions(senderKeyRecipients)
390
+ const result = await createParticipantNodes(senderKeyRecipients, senderKeyMsg, extraAttrs)
391
+ shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity
392
+ participants.push(...result.nodes)
393
+ }
382
394
 
383
- if (isRetryResend) {
384
- const { type, ciphertext: encryptedContent } = await signalRepository.encryptMessage({ data: bytes, jid: participant?.jid })
385
- binaryNodeContent.push({ tag: 'enc', attrs: { v: '2', type, count: participant.count.toString() }, content: encryptedContent })
386
- } else {
387
- binaryNodeContent.push({ tag: 'enc', attrs: { v: '2', type: 'skmsg', ...extraAttrs }, content: ciphertext })
388
- await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } })
389
- }
395
+ if (isRetryResend) {
396
+ const { type, ciphertext: encryptedContent } = await signalRepository.encryptMessage({ data: bytes, jid: participant?.jid })
397
+ binaryNodeContent.push({ tag: 'enc', attrs: { v: '2', type, count: participant.count.toString() }, content: encryptedContent })
390
398
  } else {
391
- let ownId = meId
392
- if (isLid && meLid) { ownId = meLid; logger.debug({ to: jid, ownId }, 'Using LID identity') }
393
-
394
- const { user: ownUser } = jidDecode(ownId)
399
+ binaryNodeContent.push({ tag: 'enc', attrs: { v: '2', type: 'skmsg', ...extraAttrs }, content: ciphertext })
400
+ await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } })
401
+ }
402
+ } else {
403
+ let ownId = meId
404
+ if (isLid && meLid) { ownId = meLid; logger.debug({ to: jid, ownId }, 'Using LID identity') }
395
405
 
396
- if (!participant) {
397
- const targetUserServer = isLid ? 'lid' : 's.whatsapp.net'
398
- devices.push({ user, device: 0, jid: jidEncode(user, targetUserServer, 0) })
406
+ const { user: ownUser } = jidDecode(ownId)
399
407
 
400
- if (user !== ownUser) {
401
- const ownUserServer = isLid ? 'lid' : 's.whatsapp.net'
402
- const ownUserForAddressing = isLid && meLid ? jidDecode(meLid).user : jidDecode(meId).user
403
- devices.push({ user: ownUserForAddressing, device: 0, jid: jidEncode(ownUserForAddressing, ownUserServer, 0) })
404
- }
408
+ if (!participant) {
409
+ const targetUserServer = isLid ? 'lid' : 's.whatsapp.net'
410
+ devices.push({ user, device: 0, jid: jidEncode(user, targetUserServer, 0) })
405
411
 
406
- if (additionalAttributes?.category !== 'peer') {
407
- devices.length = 0
408
- const senderIdentity = isLid && meLid ? jidEncode(jidDecode(meLid)?.user, 'lid', undefined) : jidEncode(jidDecode(meId)?.user, 's.whatsapp.net', undefined)
409
- const sessionDevices = await getUSyncDevices([senderIdentity, jid], true, false)
410
- devices.push(...sessionDevices)
411
- }
412
+ if (user !== ownUser) {
413
+ const ownUserServer = isLid ? 'lid' : 's.whatsapp.net'
414
+ const ownUserForAddressing = isLid && meLid ? jidDecode(meLid).user : jidDecode(meId).user
415
+ devices.push({ user: ownUserForAddressing, device: 0, jid: jidEncode(ownUserForAddressing, ownUserServer, 0) })
412
416
  }
413
417
 
414
- const allRecipients = [], meRecipients = [], otherRecipients = []
415
- const { user: mePnUser } = jidDecode(meId)
416
- const { user: meLidUser } = meLid ? jidDecode(meLid) : { user: null }
417
-
418
- for (const { user, jid } of devices) {
419
- const isExactSenderDevice = jid === meId || (meLid && jid === meLid)
420
- if (isExactSenderDevice) continue
421
- const isMe = user === mePnUser || user === meLidUser
422
- if (isMe) meRecipients.push(jid)
423
- else otherRecipients.push(jid)
424
- allRecipients.push(jid)
418
+ if (additionalAttributes?.category !== 'peer') {
419
+ devices.length = 0
420
+ const senderIdentity = isLid && meLid ? jidEncode(jidDecode(meLid)?.user, 'lid', undefined) : jidEncode(jidDecode(meId)?.user, 's.whatsapp.net', undefined)
421
+ const sessionDevices = await getUSyncDevices([senderIdentity, jid], true, false)
422
+ devices.push(...sessionDevices)
425
423
  }
424
+ }
426
425
 
427
- await assertSessions(allRecipients)
428
-
429
- const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
430
- createParticipantNodes(meRecipients, meMsg || message, extraAttrs),
431
- createParticipantNodes(otherRecipients, message, extraAttrs, meMsg)
432
- ])
426
+ const allRecipients = [], meRecipients = [], otherRecipients = []
427
+ const { user: mePnUser } = jidDecode(meId)
428
+ const { user: meLidUser } = meLid ? jidDecode(meLid) : { user: null }
433
429
 
434
- participants.push(...meNodes, ...otherNodes)
435
- if (meRecipients.length > 0 || otherRecipients.length > 0) extraAttrs.phash = generateParticipantHashV2([...meRecipients, ...otherRecipients])
436
- shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2
430
+ for (const { user, jid } of devices) {
431
+ const isExactSenderDevice = jid === meId || (meLid && jid === meLid)
432
+ if (isExactSenderDevice) continue
433
+ const isMe = user === mePnUser || user === meLidUser
434
+ if (isMe) meRecipients.push(jid)
435
+ else otherRecipients.push(jid)
436
+ allRecipients.push(jid)
437
437
  }
438
438
 
439
- if (participants.length) {
440
- if (additionalAttributes?.category === 'peer') { const peerNode = participants[0]?.content?.[0]; if (peerNode) binaryNodeContent.push(peerNode) }
441
- else binaryNodeContent.push({ tag: 'participants', attrs: {}, content: participants })
442
- }
439
+ await assertSessions(allRecipients)
443
440
 
444
- const stanza = { tag: 'message', attrs: { id: msgId, to: destinationJid, type: getMessageType(message), ...(additionalAttributes || {}) }, content: binaryNodeContent }
441
+ const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
442
+ createParticipantNodes(meRecipients, meMsg || message, extraAttrs),
443
+ createParticipantNodes(otherRecipients, message, extraAttrs, meMsg)
444
+ ])
445
445
 
446
- if (participant) {
447
- if (isJidGroup(destinationJid)) { stanza.attrs.to = destinationJid; stanza.attrs.participant = participant.jid }
448
- else if (areJidsSameUser(participant.jid, meId)) { stanza.attrs.to = participant.jid; stanza.attrs.recipient = destinationJid }
449
- else stanza.attrs.to = participant.jid
450
- } else stanza.attrs.to = destinationJid
446
+ participants.push(...meNodes, ...otherNodes)
447
+ if (meRecipients.length > 0 || otherRecipients.length > 0) extraAttrs.phash = generateParticipantHashV2([...meRecipients, ...otherRecipients])
448
+ shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2
449
+ }
451
450
 
452
- let additionalAlready = false
453
- if (!isNewsletter && buttonType) {
454
- const buttonsNode = getButtonArgs(messages)
455
- const filteredButtons = getBinaryFilteredButtons(additionalNodes || [])
456
- if (filteredButtons) { stanza.content.push(...additionalNodes); additionalAlready = true }
457
- else stanza.content.push(buttonsNode)
458
- }
451
+ if (participants.length) {
452
+ if (additionalAttributes?.category === 'peer') { const peerNode = participants[0]?.content?.[0]; if (peerNode) binaryNodeContent.push(peerNode) }
453
+ else binaryNodeContent.push({ tag: 'participants', attrs: {}, content: participants })
454
+ }
455
+
456
+ const stanza = { tag: 'message', attrs: { id: finalMsgId, to: destinationJid, type: getMessageType(message), ...(additionalAttributes || {}) }, content: binaryNodeContent }
457
+
458
+ if (participant) {
459
+ if (isJidGroup(destinationJid)) { stanza.attrs.to = destinationJid; stanza.attrs.participant = participant.jid }
460
+ else if (areJidsSameUser(participant.jid, meId)) { stanza.attrs.to = participant.jid; stanza.attrs.recipient = destinationJid }
461
+ else stanza.attrs.to = participant.jid
462
+ } else stanza.attrs.to = destinationJid
463
+
464
+ let additionalAlready = false
465
+ if (!isNewsletter && buttonType) {
466
+ const buttonsNode = getButtonArgs(messages)
467
+ const filteredButtons = getBinaryFilteredButtons(additionalNodes || [])
468
+ if (filteredButtons) { stanza.content.push(...additionalNodes); additionalAlready = true }
469
+ else stanza.content.push(buttonsNode)
470
+ }
459
471
 
460
- if (shouldIncludeDeviceIdentity) { stanza.content.push({ tag: 'device-identity', attrs: {}, content: encodeSignedDeviceIdentity(authState.creds.account, true) }); logger.debug({ jid }, 'adding device identity') }
461
- if (additionalNodes?.length > 0 && !additionalAlready) stanza.content.push(...additionalNodes)
472
+ if (shouldIncludeDeviceIdentity) { stanza.content.push({ tag: 'device-identity', attrs: {}, content: encodeSignedDeviceIdentity(authState.creds.account, true) }); logger.debug({ jid }, 'adding device identity') }
473
+ if (additionalNodes?.length > 0 && !additionalAlready) stanza.content.push(...additionalNodes)
462
474
  // Add TCToken support
463
475
  const contactTcTokenData = !isGroup && !isRetryResend && !isStatus ? await authState.keys.get('tctoken', [destinationJid]) : {}
464
476
  const tcTokenBuffer = contactTcTokenData[destinationJid]?.token
@@ -469,7 +481,7 @@ export const makeMessagesSocket = (config) => {
469
481
  if (messageRetryManager && !participant) messageRetryManager.addRecentMessage(destinationJid, msgId, message)
470
482
  }, meId)
471
483
 
472
- return msgId
484
+ return {key: {remoteJid: jid, fromMe: true, id: finalMsgId, participant: isGroup ? authState.creds.me.id : undefined}, messageId: finalMsgId}
473
485
  }
474
486
 
475
487
  const getPrivacyTokens = async (jids) => {
@@ -597,7 +609,7 @@ export const makeMessagesSocket = (config) => {
597
609
 
598
610
  const additionalAttributes = {}, additionalNodes = []
599
611
  if (content.delete) additionalAttributes.edit = isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe ? '8' : '7'
600
- else if (content.edit && typeof content.edit === 'object') additionalAttributes.edit = '1'
612
+ else if (content.edit) additionalAttributes.edit = '1'
601
613
  else if (content.pin) additionalAttributes.edit = '2'
602
614
  if (content.poll) additionalNodes.push({ tag: 'meta', attrs: { polltype: 'creation' } })
603
615
  if (content.event) additionalNodes.push({ tag: 'meta', attrs: { event_type: 'creation' } })
@@ -486,18 +486,17 @@ export const generateWAMessageContent = async (message, options = {}) => {
486
486
  };
487
487
 
488
488
 
489
- export const generateWAMessageFromContent = (jid, message, options = {}) => {
489
+ export const generateWAMessageFromContent = (jid, message, options) => {
490
490
  if (!options.timestamp) options.timestamp = new Date();
491
491
  const innerMessage = normalizeMessageContent(message);
492
492
  const key = getContentType(innerMessage);
493
493
  const timestamp = unixTimestampSeconds(options.timestamp);
494
494
  const { quoted, userJid } = options;
495
495
 
496
- if (quoted && key && !isJidNewsletter(jid)) {
496
+ if (quoted && !isJidNewsletter(jid)) {
497
497
  const participant = quoted.key.fromMe ? userJid : quoted.participant || quoted.key.participant || quoted.key.remoteJid;
498
498
  const quotedMsg = proto.Message.create({ [getContentType(normalizeMessageContent(quoted.message))]: normalizeMessageContent(quoted.message)[getContentType(normalizeMessageContent(quoted.message))] });
499
- if (!innerMessage[key]) innerMessage[key] = {};
500
- const contextInfo = innerMessage[key].contextInfo || {};
499
+ const contextInfo = (innerMessage[key]?.contextInfo) || {};
501
500
  contextInfo.participant = jidNormalizedUser(participant);
502
501
  contextInfo.stanzaId = quoted.key.id;
503
502
  contextInfo.quotedMessage = quotedMsg;
@@ -505,27 +504,12 @@ export const generateWAMessageFromContent = (jid, message, options = {}) => {
505
504
  innerMessage[key].contextInfo = contextInfo;
506
505
  }
507
506
 
508
- if (options?.ephemeralExpiration && key && key !== 'protocolMessage' && key !== 'ephemeralMessage' && !isJidNewsletter(jid)) {
509
- if (!innerMessage[key]) innerMessage[key] = {};
507
+ if (options?.ephemeralExpiration && key !== 'protocolMessage' && key !== 'ephemeralMessage' && !isJidNewsletter(jid)) {
510
508
  innerMessage[key].contextInfo = { ...(innerMessage[key].contextInfo || {}), expiration: options.ephemeralExpiration || WA_DEFAULT_EPHEMERAL };
511
509
  }
512
510
 
513
- const findMessageKey = (obj) => {
514
- if (!obj || typeof obj !== 'object') return null;
515
- if (obj.key?.id) return obj.key.id;
516
- for (const value of Object.values(obj)) {
517
- if (value && typeof value === 'object') {
518
- const found = findMessageKey(value);
519
- if (found) return found;
520
- }
521
- }
522
- return null;
523
- };
524
-
525
- const messageId = findMessageKey(innerMessage) || options?.messageId || generateMessageIDV2();
526
-
527
511
  return WAProto.WebMessageInfo.fromObject({
528
- key: { remoteJid: jid, fromMe: true, id: messageId },
512
+ key: { remoteJid: jid, fromMe: true, id: options?.messageId || generateMessageIDV2() },
529
513
  message: WAProto.Message.create(message),
530
514
  messageTimestamp: timestamp,
531
515
  messageStubParameters: [],
package/lib/index.js CHANGED
@@ -31,7 +31,7 @@ const banner = `
31
31
  const info = `
32
32
  ┌───────────────────────────────────────────────────────────────────────┐
33
33
  │ 📦 Package: @nexustechpro/baileys │
34
- │ 🔖 Version: 1.1.4
34
+ │ 🔖 Version: 1.1.5
35
35
  │ ⚡ Status: Production Ready │
36
36
  ├───────────────────────────────────────────────────────────────────────┤
37
37
  │ 🚀 Advanced WhatsApp Web API Client │
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nexustechpro/baileys",
3
3
  "type": "module",
4
- "version": "1.1.4",
4
+ "version": "1.1.5",
5
5
  "description": "Advanced WhatsApp Web API client with interactive messages, product catalogs, carousels, events, payments, and polls.",
6
6
  "keywords": [
7
7
  "whatsapp",
@@ -134,4 +134,4 @@
134
134
  "engines": {
135
135
  "node": ">=20.0.0"
136
136
  }
137
- }
137
+ }