mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Fix retry receipt, fix assertingPreKeys, uploadPreKeys to 30, generate QR timeout and update example (#833)
* update example * fix assertingPreKeys, uploadPreKeys to 30, generate QR timeout, sendRetryReceipt fix * update example, change clear qr to event connection.update * update example * firstQR flag * change checkConnection qr * update example * remove semis * update example
This commit is contained in:
@@ -32,9 +32,10 @@ import makeWASocket, { WASocket, AuthenticationState, DisconnectReason, AnyMessa
|
||||
JSON.stringify(state, BufferJSON.replacer, 2)
|
||||
)
|
||||
}
|
||||
|
||||
// start a connection
|
||||
const startSock = () => {
|
||||
const sock = makeWASocket({
|
||||
let sock = makeWASocket({
|
||||
logger: P({ level: 'trace' }),
|
||||
printQRInTerminal: true,
|
||||
auth: loadState()
|
||||
@@ -50,15 +51,32 @@ import makeWASocket, { WASocket, AuthenticationState, DisconnectReason, AnyMessa
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
sock.ev.on('messages.update', m => console.log(m))
|
||||
sock.ev.on('presence.update', m => console.log(m))
|
||||
sock.ev.on('chats.update', m => console.log(m))
|
||||
sock.ev.on('contacts.update', m => console.log(m))
|
||||
|
||||
sock.ev.on('connection.update', (update) => {
|
||||
const { connection, lastDisconnect } = update
|
||||
if(connection === 'close') {
|
||||
// reconnect if not logged out
|
||||
if((lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut) {
|
||||
sock = startSock()
|
||||
} else {
|
||||
console.log('connection closed')
|
||||
}
|
||||
}
|
||||
console.log('connection update', update)
|
||||
})
|
||||
// listen for when the auth state is updated
|
||||
// it is imperative you save this data, it affects the signing keys you need to have conversations
|
||||
sock.ev.on('auth-state.update', () => saveState())
|
||||
|
||||
return sock
|
||||
}
|
||||
|
||||
const sendMessageWTyping = async(msg: AnyMessageContent, jid: string) => {
|
||||
|
||||
await sock.presenceSubscribe(jid)
|
||||
await delay(500)
|
||||
|
||||
@@ -71,19 +89,4 @@ import makeWASocket, { WASocket, AuthenticationState, DisconnectReason, AnyMessa
|
||||
}
|
||||
|
||||
sock = startSock()
|
||||
sock.ev.on('connection.update', (update) => {
|
||||
const { connection, lastDisconnect } = update
|
||||
if(connection === 'close') {
|
||||
// reconnect if not logged out
|
||||
if((lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut) {
|
||||
sock = startSock()
|
||||
} else {
|
||||
console.log('connection closed')
|
||||
}
|
||||
}
|
||||
console.log('connection update', update)
|
||||
})
|
||||
// listen for when the auth state is updated
|
||||
// it is imperative you save this data, it affects the signing keys you need to have conversations
|
||||
sock.ev.on('auth-state.update', () => saveState())
|
||||
})()
|
||||
Reference in New Issue
Block a user