From 4f941553ffb0c6dd566e67666a4073f6f5c22f11 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sat, 30 Sep 2023 21:12:17 +0300 Subject: [PATCH 01/46] Update jid-utils.ts --- src/WABinary/jid-utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WABinary/jid-utils.ts b/src/WABinary/jid-utils.ts index 840f770..45ceef6 100644 --- a/src/WABinary/jid-utils.ts +++ b/src/WABinary/jid-utils.ts @@ -4,7 +4,7 @@ export const SERVER_JID = 'server@c.us' export const PSA_WID = '0@c.us' export const STORIES_JID = 'status@broadcast' -export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' +export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid' export type JidWithDevice = { user: string @@ -61,4 +61,4 @@ export const jidNormalizedUser = (jid: string | undefined) => { const { user, server } = result return jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server as JidServer) -} \ No newline at end of file +} From 4b98392a3821c196b094b6743557d5c3f6249bfa Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sat, 30 Sep 2023 21:13:51 +0300 Subject: [PATCH 02/46] Update jid-utils.ts --- src/WABinary/jid-utils.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/WABinary/jid-utils.ts b/src/WABinary/jid-utils.ts index 45ceef6..d7cbbea 100644 --- a/src/WABinary/jid-utils.ts +++ b/src/WABinary/jid-utils.ts @@ -46,6 +46,8 @@ export const areJidsSameUser = (jid1: string | undefined, jid2: string | undefin ) /** is the jid a user */ export const isJidUser = (jid: string | undefined) => (jid?.endsWith('@s.whatsapp.net')) +/** is the jid a group */ +export const isLidUser = (jid: string | undefined) => (jid?.endsWith('@lid')) /** is the jid a broadcast */ export const isJidBroadcast = (jid: string | undefined) => (jid?.endsWith('@broadcast')) /** is the jid a group */ From d20830e43fb0cebdc015b5ce192123c426ae5d00 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sat, 30 Sep 2023 21:15:04 +0300 Subject: [PATCH 03/46] Update messages-send.ts --- src/Socket/messages-send.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 8e1df92..64120f9 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -312,12 +312,13 @@ export const makeMessagesSocket = (config: SocketConfig) => { const statusJid = 'status@broadcast' const isGroup = server === 'g.us' const isStatus = jid === statusJid + const isLid = server === "lid" msgId = msgId || generateMessageID() useUserDevicesCache = useUserDevicesCache !== false const participants: BinaryNode[] = [] - const destinationJid = (!isStatus) ? jidEncode(user, isGroup ? 'g.us' : 's.whatsapp.net') : statusJid + const destinationJid = (!isStatus) ? jidEncode(user, isLid ? 'lid' : isGroup ? 'g.us' : 's.whatsapp.net') : statusJid const binaryNodeContent: BinaryNode[] = [] const devices: JidWithDevice[] = [] From e15d2ffe3039670f9c8ea1ed01ab341e6b55e27e Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sat, 30 Sep 2023 21:29:40 +0300 Subject: [PATCH 04/46] Update decode-wa-message.ts --- src/Utils/decode-wa-message.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Utils/decode-wa-message.ts b/src/Utils/decode-wa-message.ts index ebec0de..e74f89b 100644 --- a/src/Utils/decode-wa-message.ts +++ b/src/Utils/decode-wa-message.ts @@ -2,7 +2,7 @@ import { Boom } from '@hapi/boom' import { Logger } from 'pino' import { proto } from '../../WAProto' import { SignalRepository, WAMessageKey } from '../Types' -import { areJidsSameUser, BinaryNode, isJidBroadcast, isJidGroup, isJidStatusBroadcast, isJidUser } from '../WABinary' +import { areJidsSameUser, BinaryNode, isJidBroadcast, isJidGroup, isJidStatusBroadcast, isJidUser, isLidUser } from '../WABinary' import { unpadRandomMax16 } from './generics' const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node' @@ -39,6 +39,19 @@ export function decodeMessageNode( chatId = from } + msgType = 'chat' + author = from + } else if (isLidUser(from)) { + if(recipient) { + if(!isMe(from)) { + throw new Boom('receipient present, but msg not from me', { data: stanza }) + } + + chatId = recipient + } else { + chatId = from + } + msgType = 'chat' author = from } else if(isJidGroup(from)) { @@ -183,4 +196,4 @@ export const decryptMessageNode = ( } } } -} \ No newline at end of file +} From 7106d3357834378e18e70f83e45455e9d242eb3c Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sat, 30 Sep 2023 21:31:44 +0300 Subject: [PATCH 05/46] Update messages-send.ts --- src/Socket/messages-send.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 64120f9..92b8916 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -312,7 +312,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { const statusJid = 'status@broadcast' const isGroup = server === 'g.us' const isStatus = jid === statusJid - const isLid = server === "lid" + const isLid = server === 'lid' msgId = msgId || generateMessageID() useUserDevicesCache = useUserDevicesCache !== false From 16bd6276859c7ad46795611deb4bacc3e159e9fe Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sat, 30 Sep 2023 21:32:30 +0300 Subject: [PATCH 06/46] help the tslint gods have come for my head, i commited the great taboo --- src/Utils/decode-wa-message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils/decode-wa-message.ts b/src/Utils/decode-wa-message.ts index e74f89b..132cb58 100644 --- a/src/Utils/decode-wa-message.ts +++ b/src/Utils/decode-wa-message.ts @@ -41,7 +41,7 @@ export function decodeMessageNode( msgType = 'chat' author = from - } else if (isLidUser(from)) { + } else if(isLidUser(from)) { if(recipient) { if(!isMe(from)) { throw new Boom('receipient present, but msg not from me', { data: stanza }) From 8c04171043191ececaa54b8ae0a3d04089cebdbf Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sat, 30 Sep 2023 23:59:08 +0300 Subject: [PATCH 07/46] Update decode.ts --- src/WABinary/decode.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WABinary/decode.ts b/src/WABinary/decode.ts index 6095c55..cd86f46 100644 --- a/src/WABinary/decode.ts +++ b/src/WABinary/decode.ts @@ -148,7 +148,7 @@ export const decodeDecompressedBinaryNode = ( const device = readByte() const user = readString(readByte()) - return jidEncode(user, 's.whatsapp.net', device, agent) + return jidEncode(user, agent == 0 ? 's.whatsapp.net' : 'lid', device) } const readString = (tag: number): string => { @@ -262,4 +262,4 @@ export const decodeDecompressedBinaryNode = ( export const decodeBinaryNode = (buff: Buffer): BinaryNode => { const decompBuff = decompressingIfRequired(buff) return decodeDecompressedBinaryNode(decompBuff, constants) -} \ No newline at end of file +} From ba43be9c982a9bf6ae9492c96fa08c5362d88588 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 00:04:47 +0300 Subject: [PATCH 08/46] Man TSLINT PLEASE PUT THE SHOTGUN DOWN I ADDED THAT EXTRA EQUALS SIGN PLEASE I HAVE A FAMIL- --- src/WABinary/decode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WABinary/decode.ts b/src/WABinary/decode.ts index cd86f46..b900bc4 100644 --- a/src/WABinary/decode.ts +++ b/src/WABinary/decode.ts @@ -148,7 +148,7 @@ export const decodeDecompressedBinaryNode = ( const device = readByte() const user = readString(readByte()) - return jidEncode(user, agent == 0 ? 's.whatsapp.net' : 'lid', device) + return jidEncode(user, agent === 0 ? 's.whatsapp.net' : 'lid', device) } const readString = (tag: number): string => { From 3bf4201ed309f2ebdb67e02abaceb44fdd10ad46 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 14:53:33 +0300 Subject: [PATCH 09/46] Update jid-utils.ts --- src/WABinary/jid-utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WABinary/jid-utils.ts b/src/WABinary/jid-utils.ts index d7cbbea..87554ca 100644 --- a/src/WABinary/jid-utils.ts +++ b/src/WABinary/jid-utils.ts @@ -30,12 +30,12 @@ export const jidDecode = (jid: string | undefined): FullJid | undefined => { const userCombined = jid!.slice(0, sepIdx) const [userAgent, device] = userCombined.split(':') - const [user, agent] = userAgent.split('_') + const user = userAgent.split('_')[0] return { server, user, - agent: agent ? +agent : undefined, + domainType: server == "lid" ? 1 : 0, device: device ? +device : undefined } } From a32c6265835827b783ce7fce728643d7b1a258fc Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 14:55:22 +0300 Subject: [PATCH 10/46] Update jid-utils.ts --- src/WABinary/jid-utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WABinary/jid-utils.ts b/src/WABinary/jid-utils.ts index 87554ca..b897f6a 100644 --- a/src/WABinary/jid-utils.ts +++ b/src/WABinary/jid-utils.ts @@ -13,7 +13,7 @@ export type JidWithDevice = { export type FullJid = JidWithDevice & { server: JidServer | string - agent?: number + domainType?: number } export const jidEncode = (user: string | number | null, server: JidServer, device?: number, agent?: number) => { From 6c1fd75789c6a98774436eb2c6605e2f944a17b2 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 14:57:13 +0300 Subject: [PATCH 11/46] Update encode.ts --- src/WABinary/encode.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/WABinary/encode.ts b/src/WABinary/encode.ts index 929c2a3..2823a44 100644 --- a/src/WABinary/encode.ts +++ b/src/WABinary/encode.ts @@ -52,10 +52,10 @@ export const encodeBinaryNode = ( pushBytes(bytes) } - const writeJid = ({ agent, device, user, server }: FullJid) => { + const writeJid = ({ domainType, device, user, server }: FullJid) => { if(typeof agent !== 'undefined' || typeof device !== 'undefined') { pushByte(TAGS.AD_JID) - pushByte(agent || 0) + pushByte(domainType || 0) pushByte(device || 0) writeString(user) } else { @@ -233,4 +233,4 @@ export const encodeBinaryNode = ( } return Buffer.from(buffer) -} \ No newline at end of file +} From 2da9f2deac2d37f9a6548709cb5eab693a5a0c0e Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 14:58:19 +0300 Subject: [PATCH 12/46] Update encode.ts --- src/WABinary/encode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WABinary/encode.ts b/src/WABinary/encode.ts index 2823a44..43eae95 100644 --- a/src/WABinary/encode.ts +++ b/src/WABinary/encode.ts @@ -53,7 +53,7 @@ export const encodeBinaryNode = ( } const writeJid = ({ domainType, device, user, server }: FullJid) => { - if(typeof agent !== 'undefined' || typeof device !== 'undefined') { + if(typeof domainType !== 'undefined' || typeof device !== 'undefined') { pushByte(TAGS.AD_JID) pushByte(domainType || 0) pushByte(device || 0) From 5b1171312eb33bbc84a0d2da30256cfbde64de3b Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 15:18:03 +0300 Subject: [PATCH 13/46] Update messages-send.ts --- src/Socket/messages-send.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 92b8916..cf7031f 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -378,7 +378,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { devices.push(...additionalDevices) } - const patched = await patchMessageBeforeSending(message, devices.map(d => jidEncode(d.user, 's.whatsapp.net', d.device))) + const patched = await patchMessageBeforeSending(message, devices.map(d => jidEncode(d.user, d.domainType == 0 ? 's.whatsapp.net' : 'lid', d.device))) const bytes = encodeWAMessage(patched) const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage( @@ -391,8 +391,8 @@ export const makeMessagesSocket = (config: SocketConfig) => { const senderKeyJids: string[] = [] // ensure a connection is established with every device - for(const { user, device } of devices) { - const jid = jidEncode(user, 's.whatsapp.net', device) + for(const { user, device,domainType } of devices) { + const jid = jidEncode(user, domainType == 0 ? 's.whatsapp.net' : 'lid', device) if(!senderKeyMap[jid] || !!participant) { senderKeyJids.push(jid) // store that this person has had the sender keys sent to them @@ -444,8 +444,8 @@ export const makeMessagesSocket = (config: SocketConfig) => { const allJids: string[] = [] const meJids: string[] = [] const otherJids: string[] = [] - for(const { user, device } of devices) { - const jid = jidEncode(user, 's.whatsapp.net', device) + for(const { user, device,domainType } of devices) { + const jid = jidEncode(user, domainType == 0 ?'s.whatsapp.net' : 'lid', device) const isMe = user === meUser if(isMe) { meJids.push(jid) From 73963c0ff85b069ca030433b7cc51591f3f19ced Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 15:21:18 +0300 Subject: [PATCH 14/46] Update messages-send.ts --- src/Socket/messages-send.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index cf7031f..8159d16 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -391,8 +391,8 @@ export const makeMessagesSocket = (config: SocketConfig) => { const senderKeyJids: string[] = [] // ensure a connection is established with every device - for(const { user, device,domainType } of devices) { - const jid = jidEncode(user, domainType == 0 ? 's.whatsapp.net' : 'lid', device) + for(const { user, device } of devices) { + const jid = jidEncode(user, isLid ? 'lid' : 's.whatsapp.net', device) if(!senderKeyMap[jid] || !!participant) { senderKeyJids.push(jid) // store that this person has had the sender keys sent to them @@ -445,7 +445,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { const meJids: string[] = [] const otherJids: string[] = [] for(const { user, device,domainType } of devices) { - const jid = jidEncode(user, domainType == 0 ?'s.whatsapp.net' : 'lid', device) + const jid = jidEncode(user, isLid ? 'lid' : 's.whatsapp.net', device) const isMe = user === meUser if(isMe) { meJids.push(jid) From e587ae0bf869242d14311f218e68a5c9466f79b4 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 16:06:23 +0300 Subject: [PATCH 15/46] Update messages-send.ts --- src/Socket/messages-send.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 8159d16..63dc4e2 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -444,9 +444,9 @@ export const makeMessagesSocket = (config: SocketConfig) => { const allJids: string[] = [] const meJids: string[] = [] const otherJids: string[] = [] - for(const { user, device,domainType } of devices) { - const jid = jidEncode(user, isLid ? 'lid' : 's.whatsapp.net', device) + for(const { user, device } of devices) { const isMe = user === meUser + const jid = jidEncode(user, !isMe && isLid ? 'lid' : 's.whatsapp.net', device) if(isMe) { meJids.push(jid) } else { From 0b2f4d0b429dae05975e8b9724fa07940f14f586 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 16:55:40 +0300 Subject: [PATCH 16/46] Update socket.ts --- src/Socket/socket.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index e08b045..5c8440d 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -623,7 +623,8 @@ export const makeSocket = (config: SocketConfig) => { } }) // login complete - ws.on('CB:success', async() => { + ws.on('CB:success', async (node) => { + console.log(node.attrs) // temporary log, don't merge before removing await uploadPreKeysToServerIfRequired() await sendPassiveIq('active') From 6546793ec63007b3313c0f402f2942c65c8aa6f7 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 14:16:29 +0000 Subject: [PATCH 17/46] fixes --- src/Socket/messages-send.ts | 4 ++-- src/Socket/socket.ts | 5 +++-- src/Types/Contact.ts | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 63dc4e2..5cb35b3 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -378,7 +378,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { devices.push(...additionalDevices) } - const patched = await patchMessageBeforeSending(message, devices.map(d => jidEncode(d.user, d.domainType == 0 ? 's.whatsapp.net' : 'lid', d.device))) + const patched = await patchMessageBeforeSending(message, devices.map(d => jidEncode(d.user, sock.user?.id?.includes?.(d.user) ? 'lid' : 's.whatsapp.net', d.device))) const bytes = encodeWAMessage(patched) const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage( @@ -446,7 +446,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { const otherJids: string[] = [] for(const { user, device } of devices) { const isMe = user === meUser - const jid = jidEncode(user, !isMe && isLid ? 'lid' : 's.whatsapp.net', device) + const jid = jidEncode(user, !isMe && isLid ? 'lid' : 's.whatsapp.net', device) if(isMe) { meJids.push(jid) } else { diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index 5c8440d..71f7d14 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -623,14 +623,15 @@ export const makeSocket = (config: SocketConfig) => { } }) // login complete - ws.on('CB:success', async (node) => { - console.log(node.attrs) // temporary log, don't merge before removing + ws.on('CB:success', async(node: BinaryNode) => { await uploadPreKeysToServerIfRequired() await sendPassiveIq('active') logger.info('opened connection to WA') clearTimeout(qrTimer) // will never happen in all likelyhood -- but just in case WA sends success on first try + ev.emit('creds.update', { me: { id: authState.creds.me!.id, lid: node.attrs.lid } }) + ev.emit('connection.update', { connection: 'open' }) }) diff --git a/src/Types/Contact.ts b/src/Types/Contact.ts index 5da78e8..0dd51f1 100644 --- a/src/Types/Contact.ts +++ b/src/Types/Contact.ts @@ -1,5 +1,6 @@ export interface Contact { id: string + lid?: string /** name of the contact, you have saved on your WA */ name?: string /** name of the contact, the contact has set on their own on WA */ From 6f08d55bb7da160bad82757ddef141a681134001 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 14:19:37 +0000 Subject: [PATCH 18/46] reflect my own lid in relayMessage --- src/Socket/messages-send.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 5cb35b3..f1f9fb4 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -304,8 +304,6 @@ export const makeMessagesSocket = (config: SocketConfig) => { message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: MessageRelayOptions ) => { - const meId = authState.creds.me!.id - let shouldIncludeDeviceIdentity = false const { user, server } = jidDecode(jid)! @@ -313,6 +311,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { const isGroup = server === 'g.us' const isStatus = jid === statusJid const isLid = server === 'lid' + const meId = authState.creds.me![isLid ? 'lid' : 'id']! msgId = msgId || generateMessageID() useUserDevicesCache = useUserDevicesCache !== false @@ -378,7 +377,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { devices.push(...additionalDevices) } - const patched = await patchMessageBeforeSending(message, devices.map(d => jidEncode(d.user, sock.user?.id?.includes?.(d.user) ? 'lid' : 's.whatsapp.net', d.device))) + const patched = await patchMessageBeforeSending(message, devices.map(d => jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device))) const bytes = encodeWAMessage(patched) const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage( From ef8d1a09fbf1fc6b0d0edcbaf2ea91c8c07102b2 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 14:40:40 +0000 Subject: [PATCH 19/46] support mesasge input from lid --- src/Socket/messages-recv.ts | 1 + src/Utils/decode-wa-message.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 1c4d93a..8d52009 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -655,6 +655,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { const { fullMessage: msg, category, author, decrypt } = decryptMessageNode( node, authState.creds.me!.id, + authState.creds.me!.lid || '', signalRepository, logger, ) diff --git a/src/Utils/decode-wa-message.ts b/src/Utils/decode-wa-message.ts index 132cb58..4b8537e 100644 --- a/src/Utils/decode-wa-message.ts +++ b/src/Utils/decode-wa-message.ts @@ -15,7 +15,8 @@ type MessageType = 'chat' | 'peer_broadcast' | 'other_broadcast' | 'group' | 'di */ export function decodeMessageNode( stanza: BinaryNode, - meId: string + meId: string, + meLid: string ) { let msgType: MessageType let chatId: string @@ -27,6 +28,7 @@ export function decodeMessageNode( const recipient: string | undefined = stanza.attrs.recipient const isMe = (jid: string) => areJidsSameUser(jid, meId) + const isMeLid = (jid: string) => areJidsSameUser(jid, meLid) if(isJidUser(from)) { if(recipient) { @@ -43,7 +45,7 @@ export function decodeMessageNode( author = from } else if(isLidUser(from)) { if(recipient) { - if(!isMe(from)) { + if(!isMeLid(from)) { throw new Boom('receipient present, but msg not from me', { data: stanza }) } @@ -111,10 +113,11 @@ export function decodeMessageNode( export const decryptMessageNode = ( stanza: BinaryNode, meId: string, + meLid: string, repository: SignalRepository, logger: Logger ) => { - const { fullMessage, author, sender } = decodeMessageNode(stanza, meId) + const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid) return { fullMessage, category: stanza.attrs.category, From c1fa5a13c33f47c279c9ed82c6ff63758793188f Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 14:56:09 +0000 Subject: [PATCH 20/46] fix fromMe on receipts and messages, missing notifications ! --- src/Socket/messages-recv.ts | 3 ++- src/Utils/decode-wa-message.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 8d52009..8032734 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -532,7 +532,8 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { const handleReceipt = async(node: BinaryNode) => { const { attrs, content } = node - const isNodeFromMe = areJidsSameUser(attrs.participant || attrs.from, authState.creds.me?.id) + const isLid = attrs.from.includes('lid') + const isNodeFromMe = areJidsSameUser(attrs.participant || attrs.from, isLid ? authState.creds.me?.lid : authState.creds.me?.id) const remoteJid = !isNodeFromMe || isJidGroup(attrs.from) ? attrs.from : attrs.recipient const fromMe = !attrs.recipient || (attrs.type === 'retry' && isNodeFromMe) diff --git a/src/Utils/decode-wa-message.ts b/src/Utils/decode-wa-message.ts index 4b8537e..3cbbff3 100644 --- a/src/Utils/decode-wa-message.ts +++ b/src/Utils/decode-wa-message.ts @@ -82,7 +82,7 @@ export function decodeMessageNode( throw new Boom('Unknown message type', { data: stanza }) } - const fromMe = isMe(stanza.attrs.participant || stanza.attrs.from) + const fromMe = (isLidUser(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from) const pushname = stanza.attrs.notify const key: WAMessageKey = { From a9d7bff2358a94cd6cb89be2ed01af773a9e7b66 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 15:18:40 +0000 Subject: [PATCH 21/46] Revert to fix --- src/Socket/messages-send.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index f1f9fb4..9b32b33 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -311,7 +311,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { const isGroup = server === 'g.us' const isStatus = jid === statusJid const isLid = server === 'lid' - const meId = authState.creds.me![isLid ? 'lid' : 'id']! + const meId = authState.creds.me!.id msgId = msgId || generateMessageID() useUserDevicesCache = useUserDevicesCache !== false From 261afd144f1876933668a217f1715700f996df34 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 16:40:40 +0000 Subject: [PATCH 22/46] fix group messaging --- src/WABinary/jid-utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WABinary/jid-utils.ts b/src/WABinary/jid-utils.ts index b897f6a..cb58eef 100644 --- a/src/WABinary/jid-utils.ts +++ b/src/WABinary/jid-utils.ts @@ -35,7 +35,7 @@ export const jidDecode = (jid: string | undefined): FullJid | undefined => { return { server, user, - domainType: server == "lid" ? 1 : 0, + domainType: server === 'lid' ? 1 : 0, device: device ? +device : undefined } } From a11d2deaa58d20ae8ef829c63dc8c175234b6d4d Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 16:41:49 +0000 Subject: [PATCH 23/46] fixing group messaging --- src/WABinary/encode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WABinary/encode.ts b/src/WABinary/encode.ts index 43eae95..5685f5f 100644 --- a/src/WABinary/encode.ts +++ b/src/WABinary/encode.ts @@ -53,7 +53,7 @@ export const encodeBinaryNode = ( } const writeJid = ({ domainType, device, user, server }: FullJid) => { - if(typeof domainType !== 'undefined' || typeof device !== 'undefined') { + if(typeof device !== 'undefined') { pushByte(TAGS.AD_JID) pushByte(domainType || 0) pushByte(device || 0) From 7cc604a9b5c5d56deabccde77a7c986a66a8faba Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 1 Oct 2023 21:43:00 +0000 Subject: [PATCH 24/46] share, receive, request, all you want --- src/Socket/messages-recv.ts | 7 +++++++ src/Socket/messages-send.ts | 3 ++- src/Types/Events.ts | 2 ++ src/Types/Message.ts | 10 +++++++++- src/Utils/messages.ts | 6 ++++++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 8032734..ded4eca 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -660,6 +660,13 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { signalRepository, logger, ) + + if(msg.message?.protocolMessage?.type === proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER) { + if(node.attrs.sender_pn) { + ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn }) + } + } + if(shouldIgnoreJid(msg.key.remoteJid!)) { logger.debug({ key: msg.key }, 'ignored message') await sendMessageAck(node) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 9b32b33..946db84 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -304,6 +304,8 @@ export const makeMessagesSocket = (config: SocketConfig) => { message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: MessageRelayOptions ) => { + const meId = authState.creds.me!.id + let shouldIncludeDeviceIdentity = false const { user, server } = jidDecode(jid)! @@ -311,7 +313,6 @@ export const makeMessagesSocket = (config: SocketConfig) => { const isGroup = server === 'g.us' const isStatus = jid === statusJid const isLid = server === 'lid' - const meId = authState.creds.me!.id msgId = msgId || generateMessageID() useUserDevicesCache = useUserDevicesCache !== false diff --git a/src/Types/Events.ts b/src/Types/Events.ts index f37a6d2..289f5be 100644 --- a/src/Types/Events.ts +++ b/src/Types/Events.ts @@ -26,6 +26,7 @@ export type BaileysEventMap = { 'chats.upsert': Chat[] /** update the given chats */ 'chats.update': ChatUpdate[] + 'chats.phoneNumberShare': {lid: string, jid: string} /** delete chats with given ID */ 'chats.delete': string[] /** presence of contact in a chat updated */ @@ -54,6 +55,7 @@ export type BaileysEventMap = { 'blocklist.set': { blocklist: string[] } 'blocklist.update': { blocklist: string[], type: 'add' | 'remove' } + /** Receive an update on a call, including when the call was received, rejected, accepted */ 'call': WACallEvent[] 'labels.edit': Label diff --git a/src/Types/Message.ts b/src/Types/Message.ts index 385ed7c..da8bd4d 100644 --- a/src/Types/Message.ts +++ b/src/Types/Message.ts @@ -96,6 +96,14 @@ export type PollMessageOptions = { messageSecret?: Uint8Array } +type SharePhoneNumber = { + sharePhoneNumber: boolean +} + +type RequestPhoneNumber = { + requestPhoneNumber: boolean +} + export type MediaType = keyof typeof MEDIA_HKDF_KEY_MAPPING export type AnyMediaMessageContent = ( ({ @@ -169,7 +177,7 @@ export type AnyRegularMessageContent = ( businessOwnerJid?: string body?: string footer?: string - } + } | SharePhoneNumber | RequestPhoneNumber ) & ViewOnce export type AnyMessageContent = AnyRegularMessageContent | { diff --git a/src/Utils/messages.ts b/src/Utils/messages.ts index 0ed8224..cfdcd6b 100644 --- a/src/Utils/messages.ts +++ b/src/Utils/messages.ts @@ -449,6 +449,12 @@ export const generateWAMessageContent = async( selectableOptionsCount: message.poll.selectableCount, options: message.poll.values.map(optionName => ({ optionName })), } + } else if('sharePhoneNumber' in message) { + m.protocolMessage = { + type: proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER + } + } else if('requestPhoneNumber' in message) { + m.requestPhoneNumberMessage = {} } else { m = await prepareWAMessageMedia( message, From 1447fb2eaba54d5411235c3c8567c9ae8a4bbb4f Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Mon, 2 Oct 2023 18:00:29 +0000 Subject: [PATCH 25/46] add me lid --- src/Socket/messages-send.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 946db84..3b002bf 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -446,7 +446,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { const otherJids: string[] = [] for(const { user, device } of devices) { const isMe = user === meUser - const jid = jidEncode(user, !isMe && isLid ? 'lid' : 's.whatsapp.net', device) + const jid = jidEncode(isMe && isLid ? authState.creds?.me?.lid!.split(':')[0] || user : user, !isMe && isLid ? 'lid' : 's.whatsapp.net', device) if(isMe) { meJids.push(jid) } else { From 4bddd3929bca0315345af63b10b181f701d0b434 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Mon, 2 Oct 2023 18:19:28 +0000 Subject: [PATCH 26/46] bug fix: sending message to lid --- src/Socket/messages-send.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 3b002bf..409093b 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -446,7 +446,7 @@ export const makeMessagesSocket = (config: SocketConfig) => { const otherJids: string[] = [] for(const { user, device } of devices) { const isMe = user === meUser - const jid = jidEncode(isMe && isLid ? authState.creds?.me?.lid!.split(':')[0] || user : user, !isMe && isLid ? 'lid' : 's.whatsapp.net', device) + const jid = jidEncode(isMe && isLid ? authState.creds?.me?.lid!.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device) if(isMe) { meJids.push(jid) } else { From ece99eab23a01d5efcaa14a19b4da9028b914135 Mon Sep 17 00:00:00 2001 From: azudin Date: Sat, 2 Dec 2023 07:26:09 +0800 Subject: [PATCH 27/46] Fixed star message --- src/Utils/chat-utils.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Utils/chat-utils.ts b/src/Utils/chat-utils.ts index b6668b8..dad0558 100644 --- a/src/Utils/chat-utils.ts +++ b/src/Utils/chat-utils.ts @@ -583,6 +583,19 @@ export const chatModificationToAppPatch = ( apiVersion: 5, operation: OP.SET } + } else if('star' in mod) { + const key = mod.star.messages[0] + patch = { + syncAction: { + starAction: { + starred: !!mod.star + } + }, + index: ['star', jid, key.id, key.fromMe ? '1' : '0', '0'], + type: 'regular_low', + apiVersion: 2, + operation: OP.SET + } } else if('delete' in mod) { patch = { syncAction: { From 4b3841d202ce98413395a65c97b4a5dd43a9a25d Mon Sep 17 00:00:00 2001 From: azudin Date: Sat, 2 Dec 2023 07:37:35 +0800 Subject: [PATCH 28/46] Update messages-recv.ts --- src/Socket/messages-recv.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 5ed6a7a..c545fd3 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -392,14 +392,13 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { }, } }) - } else if (child.tag === 'blocklist') { + } else if(child.tag === 'blocklist') { const blocklists = getBinaryNodeChildren(child, 'item') for(const { attrs } of blocklists) { - const blocklist = [attrs.jid] - const type = (attrs.action === 'block') ? 'add' : 'remove' - - ev.emit('blocklist.update', { blocklist, type }) + const blocklist = [attrs.jid] + const type = (attrs.action === 'block') ? 'add' : 'remove' + ev.emit('blocklist.update', { blocklist, type }) } } From 3d0632b563a056c3c5341c1af8800fe7f43f0a79 Mon Sep 17 00:00:00 2001 From: azudin Date: Sat, 2 Dec 2023 07:40:19 +0800 Subject: [PATCH 29/46] Update groups.ts --- src/Socket/groups.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Socket/groups.ts b/src/Socket/groups.ts index cfc11a9..7bfaff3 100644 --- a/src/Socket/groups.ts +++ b/src/Socket/groups.ts @@ -318,7 +318,7 @@ export const extractGroupMetadata = (result: BinaryNode) => { const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us') const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration - const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') == "all_member_add" + const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') == 'all_member_add' const metadata: GroupMetadata = { id: groupId, subject: group.attrs.subject, From 29ec56cd88706a2f9c43fad1a7be15257ea6f4d7 Mon Sep 17 00:00:00 2001 From: azudin Date: Sat, 2 Dec 2023 07:41:28 +0800 Subject: [PATCH 30/46] Update groups.ts --- src/Socket/groups.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Socket/groups.ts b/src/Socket/groups.ts index 7bfaff3..f1613c1 100644 --- a/src/Socket/groups.ts +++ b/src/Socket/groups.ts @@ -318,7 +318,7 @@ export const extractGroupMetadata = (result: BinaryNode) => { const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us') const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration - const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') == 'all_member_add' + const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add' const metadata: GroupMetadata = { id: groupId, subject: group.attrs.subject, From ed6b8a22e4e381ae299997e1a51c1147c93028b8 Mon Sep 17 00:00:00 2001 From: azudin Date: Sat, 2 Dec 2023 07:42:21 +0800 Subject: [PATCH 31/46] Update messages-recv.ts --- src/Socket/messages-recv.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index c545fd3..4565b2d 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -400,7 +400,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { const type = (attrs.action === 'block') ? 'add' : 'remove' ev.emit('blocklist.update', { blocklist, type }) } - } + } break case 'link_code_companion_reg': From 0898c7cd7697176b25b3d3a17374a7ea128a48e1 Mon Sep 17 00:00:00 2001 From: azudin Date: Thu, 7 Dec 2023 23:10:04 +0800 Subject: [PATCH 32/46] Update chats.ts --- src/Socket/chats.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index f38425f..b5803da 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -777,6 +777,18 @@ export const makeChatsSocket = (config: SocketConfig) => { return appPatch(patch) } + /** + * Star or Unstar a message + */ + const star = (jid, message, star) => { + return chatModify({ + star: { + message, + star + } + }, jid); + }; + /** * Adds label for the chats */ From d3cf789f821dbf604a81320acb166b2bb3f31b9c Mon Sep 17 00:00:00 2001 From: azudin Date: Thu, 7 Dec 2023 23:11:07 +0800 Subject: [PATCH 33/46] Update chat-utils.ts --- src/Utils/chat-utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils/chat-utils.ts b/src/Utils/chat-utils.ts index dad0558..22e4243 100644 --- a/src/Utils/chat-utils.ts +++ b/src/Utils/chat-utils.ts @@ -588,7 +588,7 @@ export const chatModificationToAppPatch = ( patch = { syncAction: { starAction: { - starred: !!mod.star + starred: !!mod.star.star } }, index: ['star', jid, key.id, key.fromMe ? '1' : '0', '0'], From d1b57cf990679807a89db322c5057974e256f1ca Mon Sep 17 00:00:00 2001 From: azudin Date: Thu, 7 Dec 2023 23:37:06 +0800 Subject: [PATCH 34/46] Update chats.ts --- src/Socket/chats.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index b5803da..103625e 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -780,7 +780,7 @@ export const makeChatsSocket = (config: SocketConfig) => { /** * Star or Unstar a message */ - const star = (jid, message, star) => { + const star = (jid: string, messages: [], star: boolean) => { return chatModify({ star: { message, From 13fcf827f4d846391d5751450d812b0c40eb0589 Mon Sep 17 00:00:00 2001 From: azudin Date: Thu, 7 Dec 2023 23:41:46 +0800 Subject: [PATCH 35/46] Update chats.ts --- src/Socket/chats.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index 103625e..ee1887f 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -780,7 +780,7 @@ export const makeChatsSocket = (config: SocketConfig) => { /** * Star or Unstar a message */ - const star = (jid: string, messages: [], star: boolean) => { + const star = (jid: string, messages: any, star: boolean) => { return chatModify({ star: { message, From 92dec36781fa1c5a94dbff5cd4af60bb7ca987b6 Mon Sep 17 00:00:00 2001 From: azudin Date: Thu, 7 Dec 2023 23:44:51 +0800 Subject: [PATCH 36/46] Update chats.ts --- src/Socket/chats.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index ee1887f..ccb3c6d 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -780,7 +780,7 @@ export const makeChatsSocket = (config: SocketConfig) => { /** * Star or Unstar a message */ - const star = (jid: string, messages: any, star: boolean) => { + const star = (jid: string, messages: { id: string; fromMe?: boolean }[], star: boolean) => { return chatModify({ star: { message, From 6f81ce95277da7979fbf82de9d871f852adbe555 Mon Sep 17 00:00:00 2001 From: azudin Date: Thu, 7 Dec 2023 23:51:22 +0800 Subject: [PATCH 37/46] Update chats.ts --- src/Socket/chats.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index ccb3c6d..8ec09e4 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -783,7 +783,7 @@ export const makeChatsSocket = (config: SocketConfig) => { const star = (jid: string, messages: { id: string; fromMe?: boolean }[], star: boolean) => { return chatModify({ star: { - message, + messages, star } }, jid); From 41321dc34e817819d47b49c268f5bbdaa3a83320 Mon Sep 17 00:00:00 2001 From: azudin Date: Thu, 7 Dec 2023 23:55:09 +0800 Subject: [PATCH 38/46] Update chats.ts --- src/Socket/chats.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index 8ec09e4..1b03fa0 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -781,13 +781,13 @@ export const makeChatsSocket = (config: SocketConfig) => { * Star or Unstar a message */ const star = (jid: string, messages: { id: string; fromMe?: boolean }[], star: boolean) => { - return chatModify({ - star: { - messages, - star - } - }, jid); - }; + return chatModify({ + star: { + messages, + star + } + }, jid) + } /** * Adds label for the chats From 9ce6e7b4e644e0ad8c50c2b037650d871fba61b0 Mon Sep 17 00:00:00 2001 From: azudin Date: Fri, 8 Dec 2023 00:01:10 +0800 Subject: [PATCH 39/46] Update chats.ts --- src/Socket/chats.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index 1b03fa0..e672bdf 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -780,7 +780,7 @@ export const makeChatsSocket = (config: SocketConfig) => { /** * Star or Unstar a message */ - const star = (jid: string, messages: { id: string; fromMe?: boolean }[], star: boolean) => { + const star = (jid: string, messages: { id: string, fromMe?: boolean }[], star: boolean) => { return chatModify({ star: { messages, @@ -788,7 +788,7 @@ export const makeChatsSocket = (config: SocketConfig) => { } }, jid) } - + /** * Adds label for the chats */ From b93d1f5bd783c5075319f0a8b37bb1a6bfd0309c Mon Sep 17 00:00:00 2001 From: azudin Date: Fri, 8 Dec 2023 00:13:17 +0800 Subject: [PATCH 40/46] Update chats.ts --- src/Socket/chats.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index e672bdf..286506d 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -1011,6 +1011,7 @@ export const makeChatsSocket = (config: SocketConfig) => { addChatLabel, removeChatLabel, addMessageLabel, - removeMessageLabel + removeMessageLabel, + star } } From 64ba1a7e1257e7e27b25543c195fd77b14be6eb8 Mon Sep 17 00:00:00 2001 From: azudin Date: Fri, 8 Dec 2023 00:19:25 +0800 Subject: [PATCH 41/46] Update README.md --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index c24c654..b95ea04 100644 --- a/README.md +++ b/README.md @@ -698,6 +698,15 @@ WA uses an encrypted form of communication to send chat/app updates. This has be }, '123456@s.whatsapp.net') ``` + +- Star/unstar a message + ``` ts + await sock.chatModify({ + star: { + messages: [{ id: 'messageID', fromMe: true // or `false` }], + star: true // - true: Star Message; false: Unstar Message + }},'123456@s.whatsapp.net'); + ``` **Note:** if you mess up one of your updates, WA can log you out of all your devices and you'll have to log in again. From b914a1f52ae66c1a8f0e401d0a865464bc5d6bfb Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Mon, 18 Dec 2023 16:31:41 +0200 Subject: [PATCH 42/46] Initial commit --- src/Utils/process-message.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Utils/process-message.ts b/src/Utils/process-message.ts index 294a63f..9f65d26 100644 --- a/src/Utils/process-message.ts +++ b/src/Utils/process-message.ts @@ -263,6 +263,22 @@ const processMessage = async( ephemeralSettingTimestamp: toNumber(message.messageTimestamp), ephemeralExpiration: protocolMsg.ephemeralExpiration || null }) + break + case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE: + const response = protocolMsg.peerDataOperationRequestResponseMessage! + if(response) { + const { peerDataOperationResult } = response + for(const result of peerDataOperationResult!) { + const { placeholderMessageResendResponse: retryResponse } = result + if(retryResponse) { + const webMessageInfo = proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes!) + ev.emit('messages.update', [ + { key: webMessageInfo.key, update: { message: webMessageInfo.message } } + ]) + } + } + } + break } } else if(content?.reactionMessage) { @@ -387,4 +403,4 @@ const processMessage = async( } } -export default processMessage \ No newline at end of file +export default processMessage From cbffb2941cd7e61142a25ef9e58149230621db36 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Mon, 18 Dec 2023 16:43:28 +0200 Subject: [PATCH 43/46] fix: Fix linting --- src/Socket/groups.ts | 2 +- src/Socket/messages-recv.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Socket/groups.ts b/src/Socket/groups.ts index cfc11a9..f1613c1 100644 --- a/src/Socket/groups.ts +++ b/src/Socket/groups.ts @@ -318,7 +318,7 @@ export const extractGroupMetadata = (result: BinaryNode) => { const groupId = group.attrs.id.includes('@') ? group.attrs.id : jidEncode(group.attrs.id, 'g.us') const eph = getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration - const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') == "all_member_add" + const memberAddMode = getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add' const metadata: GroupMetadata = { id: groupId, subject: group.attrs.subject, diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 5ed6a7a..ab8b87c 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -392,16 +392,16 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { }, } }) - } else if (child.tag === 'blocklist') { + } else if(child.tag === 'blocklist') { const blocklists = getBinaryNodeChildren(child, 'item') for(const { attrs } of blocklists) { - const blocklist = [attrs.jid] - const type = (attrs.action === 'block') ? 'add' : 'remove' + const blocklist = [attrs.jid] + const type = (attrs.action === 'block') ? 'add' : 'remove' - ev.emit('blocklist.update', { blocklist, type }) + ev.emit('blocklist.update', { blocklist, type }) } - } + } break case 'link_code_companion_reg': From dea709a5bb13721d438861541273281eee183985 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Fri, 22 Dec 2023 00:40:49 +0200 Subject: [PATCH 44/46] chore: fix formatting --- src/Socket/messages-send.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 409093b..070a1f8 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -643,9 +643,10 @@ export const makeMessagesSocket = (config: SocketConfig) => { relayMessage, sendReceipt, sendReceipts, + getButtonArgs, readMessages, refreshMediaConn, - waUploadToServer, + waUploadToServer, fetchPrivacySettings, updateMediaMessage: async(message: proto.IWebMessageInfo) => { const content = assertMediaContent(message.message) From f527c1247c09b3d25d3e5f3a6040930d6eefdc91 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sat, 23 Dec 2023 06:01:17 +0200 Subject: [PATCH 45/46] Create FUNDING.yml - include maintainer GH Sponsors --- .github/FUNDING.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..7d42ac1 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [purpshell, auties00, edgardmessias] From 8662be873dc4afd38750692228d8207eaf4e7f22 Mon Sep 17 00:00:00 2001 From: ShellTear Date: Tue, 26 Dec 2023 23:38:34 +0200 Subject: [PATCH 46/46] Update README.md Remove buttons from the readme. --- README.md | 92 ------------------------------------------------------- 1 file changed, 92 deletions(-) diff --git a/README.md b/README.md index c24c654..64b6929 100644 --- a/README.md +++ b/README.md @@ -376,65 +376,6 @@ const sentMsg = await sock.sendMessage( } ) -// send a buttons message! -const buttons = [ - {buttonId: 'id1', buttonText: {displayText: 'Button 1'}, type: 1}, - {buttonId: 'id2', buttonText: {displayText: 'Button 2'}, type: 1}, - {buttonId: 'id3', buttonText: {displayText: 'Button 3'}, type: 1} -] - -const buttonMessage = { - text: "Hi it's button message", - footer: 'Hello World', - buttons: buttons, - headerType: 1 -} - -const sendMsg = await sock.sendMessage(id, buttonMessage) - -//send a template message! -const templateButtons = [ - {index: 1, urlButton: {displayText: '⭐ Star Baileys on GitHub!', url: 'https://github.com/adiwajshing/Baileys'}}, - {index: 2, callButton: {displayText: 'Call me!', phoneNumber: '+1 (234) 5678-901'}}, - {index: 3, quickReplyButton: {displayText: 'This is a reply, just like normal buttons!', id: 'id-like-buttons-message'}}, -] - -const templateMessage = { - text: "Hi it's a template message", - footer: 'Hello World', - templateButtons: templateButtons -} - -const sendMsg = await sock.sendMessage(id, templateMessage) - -// send a list message! -const sections = [ - { - title: "Section 1", - rows: [ - {title: "Option 1", rowId: "option1"}, - {title: "Option 2", rowId: "option2", description: "This is a description"} - ] - }, - { - title: "Section 2", - rows: [ - {title: "Option 3", rowId: "option3"}, - {title: "Option 4", rowId: "option4", description: "This is a description V2"} - ] - }, -] - -const listMessage = { - text: "This is a list", - footer: "nice footer, link: https://google.com", - title: "Amazing boldfaced list title", - buttonText: "Required, text on the button to view the list", - sections -} - -const sendMsg = await sock.sendMessage(id, listMessage) - const reactionMessage = { react: { text: "💖", // use an empty string to remove the reaction @@ -489,39 +430,6 @@ await sock.sendMessage( { audio: { url: "./Media/audio.mp3" }, mimetype: 'audio/mp4' } { url: "Media/audio.mp3" }, // can send mp3, mp4, & ogg ) - -// send a buttons message with image header! -const buttons = [ - {buttonId: 'id1', buttonText: {displayText: 'Button 1'}, type: 1}, - {buttonId: 'id2', buttonText: {displayText: 'Button 2'}, type: 1}, - {buttonId: 'id3', buttonText: {displayText: 'Button 3'}, type: 1} -] - -const buttonMessage = { - image: {url: 'https://example.com/image.jpeg'}, - caption: "Hi it's button message", - footer: 'Hello World', - buttons: buttons, - headerType: 4 -} - -const sendMsg = await sock.sendMessage(id, buttonMessage) - -//send a template message with an image **attached**! -const templateButtons = [ - {index: 1, urlButton: {displayText: '⭐ Star Baileys on GitHub!', url: 'https://github.com/adiwajshing/Baileys'}}, - {index: 2, callButton: {displayText: 'Call me!', phoneNumber: '+1 (234) 5678-901'}}, - {index: 3, quickReplyButton: {displayText: 'This is a reply, just like normal buttons!', id: 'id-like-buttons-message'}}, -] - -const buttonMessage = { - text: "Hi it's a template message", - footer: 'Hello World', - templateButtons: templateButtons, - image: {url: 'https://example.com/image.jpeg'} -} - -const sendMsg = await sock.sendMessage(id, templateMessage) ``` ### Notes