Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WEB WAM IMPLEMENTATION!!!!! #708

Merged
merged 3 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
924 changes: 924 additions & 0 deletions Example/boot_analytics_test.json

Large diffs are not rendered by default.

32 changes: 31 additions & 1 deletion Example/example.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Boom } from '@hapi/boom'
import NodeCache from 'node-cache'
import readline from 'readline'
import makeWASocket, { AnyMessageContent, delay, DisconnectReason, fetchLatestBaileysVersion, getAggregateVotesInPollMessage, makeCacheableSignalKeyStore, makeInMemoryStore, PHONENUMBER_MCC, proto, useMultiFileAuthState, WAMessageContent, WAMessageKey } from '../src'
import makeWASocket, { AnyMessageContent, BinaryInfo, delay, DisconnectReason, encodeWAM, fetchLatestBaileysVersion, getAggregateVotesInPollMessage, makeCacheableSignalKeyStore, makeInMemoryStore, PHONENUMBER_MCC, proto, useMultiFileAuthState, WAMessageContent, WAMessageKey } from '../src'
import MAIN_LOGGER from '../src/Utils/logger'
import open from 'open'
import fs from 'fs'
Expand Down Expand Up @@ -176,6 +176,36 @@ const startSock = async() => {
console.log('Connection closed. You are logged out.')
}
}

// WARNING: THIS WILL SEND A WAM EXAMPLE AND THIS IS A ****CAPTURED MESSAGE.****
// DO NOT ACTUALLY ENABLE THIS UNLESS YOU MODIFIED THE FILE.JSON!!!!!
// THE ANALYTICS IN THE FILE ARE OLD. DO NOT USE THEM.
// YOUR APP SHOULD HAVE GLOBALS AND ANALYTICS ACCURATE TO TIME, DATE AND THE SESSION
// THIS FILE.JSON APPROACH IS JUST AN APPROACH I USED, BE FREE TO DO THIS IN ANOTHER WAY.
// THE FIRST EVENT CONTAINS THE CONSTANT GLOBALS, EXCEPT THE seqenceNumber(in the event) and commitTime
// THIS INCLUDES STUFF LIKE ocVersion WHICH IS CRUCIAL FOR THE PREVENTION OF THE WARNING
const sendWAMExample = false;
if(connection === 'open' && sendWAMExample) {
/// sending WAM EXAMPLE
const {
header: {
wamVersion,
eventSequenceNumber,
},
events,
} = JSON.parse(await fs.promises.readFile("./boot_analytics_test.json", "utf-8"))

const binaryInfo = new BinaryInfo({
protocolVersion: wamVersion,
sequence: eventSequenceNumber,
events: events
})

const buffer = encodeWAM(binaryInfo);

const result = await sock.sendWAMBuffer(buffer)
console.log(result)
}

console.log('connection update', update)
}
Expand Down
19 changes: 19 additions & 0 deletions src/Socket/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,24 @@ export const makeSocket = (config: SocketConfig) => {
return Buffer.concat([salt, randomIv, ciphered])
}

const sendWAMBuffer = (wamBuffer: Buffer) => {
return query({
tag: 'iq',
attrs: {
to: S_WHATSAPP_NET,
id: generateMessageTag(),
xmlns: 'w:stats'
},
content: [
{
tag: 'add',
attrs: {},
content: wamBuffer
}
]
})
}

ws.on('message', onMessageRecieved)
ws.on('open', async() => {
try {
Expand Down Expand Up @@ -723,6 +741,7 @@ export const makeSocket = (config: SocketConfig) => {
requestPairingCode,
/** Waits for the connection to WA to reach a state */
waitForConnectionUpdate: bindWaitForConnectionUpdate(ev),
sendWAMBuffer,
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/WAM/BinaryInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { EventInputType } from './constants'

export class BinaryInfo {
PurpShell marked this conversation as resolved.
Show resolved Hide resolved
protocolVersion = 5
sequence = 0
events = [] as EventInputType[]
buffer: Buffer[] = []

constructor(options: Partial<BinaryInfo> = {}) {
Object.assign(this, options)
}
}
Loading
Loading