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,
|
message: proto.IMessage,
|
||||||
extraAttrs?: BinaryNode['attrs']
|
extraAttrs?: BinaryNode['attrs']
|
||||||
) => {
|
) => {
|
||||||
const patched = await patchMessageBeforeSending(message, jids)
|
let patched = await patchMessageBeforeSending(message, jids)
|
||||||
const bytes = encodeWAMessage(patched)
|
if(!Array.isArray(patched)) {
|
||||||
|
patched = [{ recipientJid: jids[0], ...patched }]
|
||||||
|
}
|
||||||
|
|
||||||
let shouldIncludeDeviceIdentity = false
|
let shouldIncludeDeviceIdentity = false
|
||||||
const nodes = await Promise.all(
|
const nodes = await Promise.all(
|
||||||
jids.map(
|
patched.map(
|
||||||
async jid => {
|
async patchedMessageWithJid => {
|
||||||
|
const { recipientJid: jid, ...patchedMessage } = patchedMessageWithJid
|
||||||
|
const bytes = encodeWAMessage(patchedMessage)
|
||||||
const { type, ciphertext } = await signalRepository
|
const { type, ciphertext } = await signalRepository
|
||||||
.encryptMessage({ jid, data: bytes })
|
.encryptMessage({ jid: jid!, data: bytes })
|
||||||
if(type === 'pkmsg') {
|
if(type === 'pkmsg') {
|
||||||
shouldIncludeDeviceIdentity = true
|
shouldIncludeDeviceIdentity = true
|
||||||
}
|
}
|
||||||
|
|
||||||
const node: BinaryNode = {
|
const node: BinaryNode = {
|
||||||
tag: 'to',
|
tag: 'to',
|
||||||
attrs: { jid },
|
attrs: { jid: jid! },
|
||||||
content: [{
|
content: [{
|
||||||
tag: 'enc',
|
tag: 'enc',
|
||||||
attrs: {
|
attrs: {
|
||||||
@@ -401,7 +405,12 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
devices.push(...additionalDevices)
|
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 bytes = encodeWAMessage(patched)
|
||||||
|
|
||||||
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage(
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage(
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ export type CacheStore = {
|
|||||||
flushAll(): void
|
flushAll(): void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type PatchedMessageWithRecipientJID = proto.IMessage & {recipientJid?: string}
|
||||||
|
|
||||||
export type SocketConfig = {
|
export type SocketConfig = {
|
||||||
/** the WS url to connect to WA */
|
/** the WS url to connect to WA */
|
||||||
waWebSocketUrl: string | URL
|
waWebSocketUrl: string | URL
|
||||||
@@ -104,8 +106,8 @@ export type SocketConfig = {
|
|||||||
* */
|
* */
|
||||||
patchMessageBeforeSending: (
|
patchMessageBeforeSending: (
|
||||||
msg: proto.IMessage,
|
msg: proto.IMessage,
|
||||||
recipientJids: string[],
|
recipientJids?: string[],
|
||||||
) => Promise<proto.IMessage> | proto.IMessage
|
) => Promise<PatchedMessageWithRecipientJID[] | PatchedMessageWithRecipientJID> | PatchedMessageWithRecipientJID[] | PatchedMessageWithRecipientJID
|
||||||
|
|
||||||
/** verify app state MACs */
|
/** verify app state MACs */
|
||||||
appStateMacVerification: {
|
appStateMacVerification: {
|
||||||
|
|||||||
Reference in New Issue
Block a user