@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.
- package/lib/Socket/messages-send.js +165 -153
- package/lib/Utils/messages.js +5 -21
- package/lib/index.js +1 -1
- package/package.json +2 -2
|
@@ -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
|
|
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,
|
|
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
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
-
|
|
307
|
-
const
|
|
308
|
-
|
|
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 (
|
|
312
|
-
|
|
313
|
-
const
|
|
314
|
-
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
await
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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
|
-
|
|
368
|
+
if (groupData?.ephemeralDuration > 0) additionalAttributes = { ...additionalAttributes, expiration: groupData.ephemeralDuration.toString() }
|
|
357
369
|
|
|
358
|
-
|
|
359
|
-
|
|
370
|
+
const patched = await patchMessageBeforeSending(message)
|
|
371
|
+
if (Array.isArray(patched)) throw new Boom('Per-jid patching not supported in groups')
|
|
360
372
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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
|
-
|
|
377
|
+
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({ group: destinationJid, data: bytes, meId: groupSenderIdentity })
|
|
366
378
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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
|
-
|
|
384
|
-
|
|
385
|
-
|
|
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
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
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
|
-
|
|
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
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
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
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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
|
-
|
|
453
|
-
if (
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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
|
-
|
|
461
|
-
|
|
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
|
|
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
|
|
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' } })
|
package/lib/Utils/messages.js
CHANGED
|
@@ -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 &&
|
|
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
|
-
|
|
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
|
|
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.
|
|
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
|
+
"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
|
+
}
|