mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
update WA version + presence update tracking
This commit is contained in:
@@ -32,10 +32,13 @@ const list = wsMessages.map ((item, i) => {
|
|||||||
const buffer = item.data.includes(',') ? item.data : Buffer.from (item.data, 'base64')
|
const buffer = item.data.includes(',') ? item.data : Buffer.from (item.data, 'base64')
|
||||||
try {
|
try {
|
||||||
const [tag, json, binaryTags] = decrypt (buffer, item.type === 'send')
|
const [tag, json, binaryTags] = decrypt (buffer, item.type === 'send')
|
||||||
|
|
||||||
|
if (json && json[1] && json[1].add) return
|
||||||
return {tag, json: json && JSON.stringify(json), binaryTags}
|
return {tag, json: json && JSON.stringify(json), binaryTags}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { error: error.message, data: buffer.toString('utf-8') }
|
return { error: error.message, data: buffer.toString('utf-8') }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.filter (Boolean)
|
||||||
const str = JSON.stringify (list, null, '\t')
|
const str = JSON.stringify (list, null, '\t')
|
||||||
fs.writeFileSync ('decoded-ws.json', str)
|
fs.writeFileSync ('decoded-ws.json', str)
|
||||||
@@ -30,7 +30,7 @@ import { STATUS_CODES } from 'http'
|
|||||||
|
|
||||||
export class WAConnection extends EventEmitter {
|
export class WAConnection extends EventEmitter {
|
||||||
/** The version of WhatsApp Web we're telling the servers we are */
|
/** The version of WhatsApp Web we're telling the servers we are */
|
||||||
version: [number, number, number] = [2, 2035, 14]
|
version: [number, number, number] = [2, 2037, 6]
|
||||||
/** The Browser we're telling the WhatsApp Web servers we are */
|
/** The Browser we're telling the WhatsApp Web servers we are */
|
||||||
browserDescription: [string, string, string] = Utils.Browsers.baileys ('Chrome')
|
browserDescription: [string, string, string] = Utils.Browsers.baileys ('Chrome')
|
||||||
/** Metadata like WhatsApp id, name set on WhatsApp etc. */
|
/** Metadata like WhatsApp id, name set on WhatsApp etc. */
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as QR from 'qrcode-terminal'
|
import * as QR from 'qrcode-terminal'
|
||||||
import { WAConnection as Base } from './3.Connect'
|
import { WAConnection as Base } from './3.Connect'
|
||||||
import { WAMessageStatusUpdate, WAMessage, WAContact, WAChat, WAMessageProto, WA_MESSAGE_STUB_TYPE, WA_MESSAGE_STATUS_TYPE, MessageLogLevel, PresenceUpdate, BaileysEvent, DisconnectReason, WANode, WAOpenResult } from './Constants'
|
import { WAMessageStatusUpdate, WAMessage, WAContact, WAChat, WAMessageProto, WA_MESSAGE_STUB_TYPE, WA_MESSAGE_STATUS_TYPE, MessageLogLevel, PresenceUpdate, BaileysEvent, DisconnectReason, WANode, WAOpenResult, Presence } from './Constants'
|
||||||
import { whatsappID, unixTimestampSeconds, isGroupID, toNumber } from './Utils'
|
import { whatsappID, unixTimestampSeconds, isGroupID, toNumber } from './Utils'
|
||||||
|
|
||||||
export class WAConnection extends Base {
|
export class WAConnection extends Base {
|
||||||
@@ -10,17 +10,29 @@ export class WAConnection extends Base {
|
|||||||
// new messages
|
// new messages
|
||||||
this.registerCallback(['action', 'add:relay', 'message'], json => {
|
this.registerCallback(['action', 'add:relay', 'message'], json => {
|
||||||
const message = json[2][0][2] as WAMessage
|
const message = json[2][0][2] as WAMessage
|
||||||
|
const jid = whatsappID( message.key.remoteJid )
|
||||||
|
if (jid.endsWith('@s.whatsapp.net')) {
|
||||||
|
const contact = this.contacts[jid]
|
||||||
|
if (contact && contact?.lastKnownPresence === Presence.composing) {
|
||||||
|
contact.lastKnownPresence = Presence.available
|
||||||
|
}
|
||||||
|
}
|
||||||
this.chatAddMessageAppropriate (message)
|
this.chatAddMessageAppropriate (message)
|
||||||
})
|
})
|
||||||
// presence updates
|
// presence updates
|
||||||
this.registerCallback('Presence', json => {
|
this.registerCallback('Presence', json => {
|
||||||
const update = json[1] as PresenceUpdate
|
const update = json[1] as PresenceUpdate
|
||||||
const jid = whatsappID(update.participant || update.id)
|
|
||||||
|
const jid = whatsappID(update.id)
|
||||||
const contact = this.contacts[jid]
|
const contact = this.contacts[jid]
|
||||||
if (!isGroupID(jid) && contact) {
|
if (jid.endsWith('@s.whatsapp.net')) { // if its a single chat
|
||||||
contact.lastKnownPresence = update.type
|
|
||||||
if (update.t) contact.lastSeen = +update.t
|
if (update.t) contact.lastSeen = +update.t
|
||||||
|
else if (update.type === Presence.unavailable && contact.lastKnownPresence !== Presence.unavailable) {
|
||||||
|
contact.lastSeen = unixTimestampSeconds()
|
||||||
|
}
|
||||||
|
contact.lastKnownPresence = update.type
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emit('user-presence-update', update)
|
this.emit('user-presence-update', update)
|
||||||
})
|
})
|
||||||
// If a message has been updated (usually called when a video message gets its upload url)
|
// If a message has been updated (usually called when a video message gets its upload url)
|
||||||
|
|||||||
Reference in New Issue
Block a user