mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: add per-jid patching
This does not work in groups
This commit is contained in:
@@ -280,22 +280,26 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
message: proto.IMessage,
|
||||
extraAttrs?: BinaryNode['attrs']
|
||||
) => {
|
||||
const patched = await patchMessageBeforeSending(message, jids)
|
||||
const bytes = encodeWAMessage(patched)
|
||||
let patched = await patchMessageBeforeSending(message, jids)
|
||||
if(!Array.isArray(patched)) {
|
||||
patched = [{ recipientJid: jids[0], ...patched }]
|
||||
}
|
||||
|
||||
let shouldIncludeDeviceIdentity = false
|
||||
const nodes = await Promise.all(
|
||||
jids.map(
|
||||
async jid => {
|
||||
patched.map(
|
||||
async patchedMessageWithJid => {
|
||||
const { recipientJid: jid, ...patchedMessage } = patchedMessageWithJid
|
||||
const bytes = encodeWAMessage(patchedMessage)
|
||||
const { type, ciphertext } = await signalRepository
|
||||
.encryptMessage({ jid, data: bytes })
|
||||
.encryptMessage({ jid: jid!, data: bytes })
|
||||
if(type === 'pkmsg') {
|
||||
shouldIncludeDeviceIdentity = true
|
||||
}
|
||||
|
||||
const node: BinaryNode = {
|
||||
tag: 'to',
|
||||
attrs: { jid },
|
||||
attrs: { jid: jid! },
|
||||
content: [{
|
||||
tag: 'enc',
|
||||
attrs: {
|
||||
@@ -401,7 +405,12 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
devices.push(...additionalDevices)
|
||||
}
|
||||
|
||||
const patched = await patchMessageBeforeSending(message, devices.map(d => jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)))
|
||||
const patched = await patchMessageBeforeSending(message)
|
||||
|
||||
if(Array.isArray(patched)) {
|
||||
throw new Boom('Per-jid patching is not supported in groups')
|
||||
}
|
||||
|
||||
const bytes = encodeWAMessage(patched)
|
||||
|
||||
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage(
|
||||
|
||||
@@ -23,6 +23,8 @@ export type CacheStore = {
|
||||
flushAll(): void
|
||||
}
|
||||
|
||||
export type PatchedMessageWithRecipientJID = proto.IMessage & {recipientJid?: string}
|
||||
|
||||
export type SocketConfig = {
|
||||
/** the WS url to connect to WA */
|
||||
waWebSocketUrl: string | URL
|
||||
@@ -104,8 +106,8 @@ export type SocketConfig = {
|
||||
* */
|
||||
patchMessageBeforeSending: (
|
||||
msg: proto.IMessage,
|
||||
recipientJids: string[],
|
||||
) => Promise<proto.IMessage> | proto.IMessage
|
||||
recipientJids?: string[],
|
||||
) => Promise<PatchedMessageWithRecipientJID[] | PatchedMessageWithRecipientJID> | PatchedMessageWithRecipientJID[] | PatchedMessageWithRecipientJID
|
||||
|
||||
/** verify app state MACs */
|
||||
appStateMacVerification: {
|
||||
|
||||
Reference in New Issue
Block a user