mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix(master): generate new message id
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { Boom } from '@hapi/boom'
|
||||
import axios, { AxiosRequestConfig } from 'axios'
|
||||
import { randomBytes } from 'crypto'
|
||||
import { createHash, randomBytes } from 'crypto'
|
||||
import { platform, release } from 'os'
|
||||
import { Logger } from 'pino'
|
||||
import { proto } from '../../WAProto'
|
||||
import { version as baileysVersion } from '../Defaults/baileys-version.json'
|
||||
import { BaileysEventEmitter, BaileysEventMap, DisconnectReason, WACallUpdateType, WAVersion } from '../Types'
|
||||
import { BinaryNode, getAllBinaryNodeChildren } from '../WABinary'
|
||||
import { BinaryNode, getAllBinaryNodeChildren, jidDecode } from '../WABinary'
|
||||
|
||||
const PLATFORM_MAP = {
|
||||
'aix': 'AIX',
|
||||
@@ -170,6 +170,27 @@ export async function promiseTimeout<T>(ms: number | undefined, promise: (resolv
|
||||
return p as Promise<T>
|
||||
}
|
||||
|
||||
// inspired from whatsmeow code
|
||||
// https://github.com/tulir/whatsmeow/blob/64bc969fbe78d31ae0dd443b8d4c80a5d026d07a/send.go#L42
|
||||
export const generateMessageIDV2 = (userId?: string): string => {
|
||||
const data = Buffer.alloc(8 + 20 + 16)
|
||||
data.writeBigUInt64BE(BigInt(Math.floor(Date.now() / 1000)))
|
||||
|
||||
if (userId) {
|
||||
const id = jidDecode(userId)
|
||||
if (id?.user) {
|
||||
data.write(id.user, 8)
|
||||
data.write('@c.us', 8 + id.user.length)
|
||||
}
|
||||
}
|
||||
|
||||
const random = randomBytes(16)
|
||||
random.copy(data, 28)
|
||||
|
||||
const hash = createHash('sha256').update(data).digest()
|
||||
return '3EB0' + hash.toString('hex').toUpperCase().substring(0, 18)
|
||||
}
|
||||
|
||||
// generate a random ID to attach to a message
|
||||
export const generateMessageID = () => '3EB0' + randomBytes(18).toString('hex').toUpperCase()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user