mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: temp patch for button/list messages
This commit is contained in:
@@ -4,7 +4,7 @@ import NodeCache from 'node-cache'
|
||||
import { proto } from '../../WAProto'
|
||||
import { WA_DEFAULT_EPHEMERAL } from '../Defaults'
|
||||
import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types'
|
||||
import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeWAMessage, encryptMediaRetryRequest, encryptSenderKeyMsgSignalProto, encryptSignalProto, extractDeviceJids, generateMessageID, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, jidToSignalProtocolAddress, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils'
|
||||
import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeWAMessage, encryptMediaRetryRequest, encryptSenderKeyMsgSignalProto, encryptSignalProto, extractDeviceJids, generateMessageID, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, jidToSignalProtocolAddress, parseAndInjectE2ESessions, patchMessageForMdIfRequired, unixTimestampSeconds } from '../Utils'
|
||||
import { getUrlInfo } from '../Utils/link-preview'
|
||||
import { areJidsSameUser, BinaryNode, BinaryNodeAttributes, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidDecode, jidEncode, jidNormalizedUser, JidWithDevice, S_WHATSAPP_NET } from '../WABinary'
|
||||
import { makeGroupsSocket } from './groups'
|
||||
@@ -628,6 +628,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
}
|
||||
}
|
||||
|
||||
fullMsg.message = patchMessageForMdIfRequired(fullMsg.message!)
|
||||
await relayMessage(jid, fullMsg.message!, { messageId: fullMsg.key.id!, cachedGroupMetadata: options.cachedGroupMetadata, additionalAttributes })
|
||||
if(config.emitOwnEvents) {
|
||||
process.nextTick(() => {
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
WAProto,
|
||||
WATextMessage,
|
||||
} from '../Types'
|
||||
import { jidNormalizedUser } from '../WABinary'
|
||||
import { isJidGroup, jidNormalizedUser } from '../WABinary'
|
||||
import { generateMessageID, unixTimestampSeconds } from './generics'
|
||||
import { downloadContentFromMessage, encryptedStream, generateThumbnail, getAudioDuration, MediaDownloadOptions } from './messages-media'
|
||||
|
||||
@@ -392,6 +392,7 @@ export const generateWAMessageContent = async(
|
||||
|
||||
m = {
|
||||
templateMessage: {
|
||||
fourRowTemplate: msg,
|
||||
hydratedTemplate: msg
|
||||
}
|
||||
}
|
||||
@@ -494,7 +495,7 @@ export const generateWAMessageFromContent = (
|
||||
message: message,
|
||||
messageTimestamp: timestamp,
|
||||
messageStubParameters: [],
|
||||
participant: jid.includes('@g.us') ? userJid : undefined,
|
||||
participant: isJidGroup(jid) ? userJid : undefined,
|
||||
status: WAMessageStatus.PENDING
|
||||
}
|
||||
return WAProto.WebMessageInfo.fromObject(messageJSON)
|
||||
@@ -717,4 +718,37 @@ export const assertMediaContent = (content: proto.IMessage | null | undefined) =
|
||||
}
|
||||
|
||||
return mediaContent
|
||||
}
|
||||
|
||||
|
||||
const generateContextInfo = () => {
|
||||
const info: proto.IMessageContextInfo = {
|
||||
deviceListMetadataVersion: 2,
|
||||
deviceListMetadata: { }
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
/**
|
||||
* this is an experimental patch to make buttons work
|
||||
* Don't know how it works, but it does for now
|
||||
*/
|
||||
export const patchMessageForMdIfRequired = (message: proto.IMessage) => {
|
||||
const requiresPatch = !!(
|
||||
message.buttonsMessage
|
||||
// || message.templateMessage
|
||||
|| message.listMessage
|
||||
)
|
||||
if(requiresPatch) {
|
||||
message = {
|
||||
viewOnceMessage: {
|
||||
message: {
|
||||
messageContextInfo: generateContextInfo(),
|
||||
...message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return message
|
||||
}
|
||||
Reference in New Issue
Block a user