Documentation Index Fetch the complete documentation index at: https://whiskeysockets-docs-jids-socket-config-ptbr.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Problemas comuns
A conexão fica caindo / reconectando
O Baileys não reconecta automaticamente — é proposital. Cheque DisconnectReason.loggedOut antes de retry. 401 = deslogado ativamente, não adianta retry. import makeWASocket , { DisconnectReason , useMultiFileAuthState } from '@whiskeysockets/baileys'
import { Boom } from '@hapi/boom'
async function connectToWhatsApp () {
const { state , saveCreds } = await useMultiFileAuthState ( 'auth_info_baileys' )
const sock = makeWASocket ({
auth: state
})
sock . ev . on ( 'connection.update' , ( update ) => {
const { connection , lastDisconnect } = update
if ( connection === 'close' ) {
const shouldReconnect = ( lastDisconnect . error as Boom )?. output ?. statusCode !== DisconnectReason . loggedOut
if ( shouldReconnect ) {
connectToWhatsApp ()
}
} else if ( connection === 'open' ) {
console . log ( 'opened connection' )
}
})
sock . ev . on ( 'creds.update' , saveCreds )
}
connectToWhatsApp ()
QR code não aparece ou fica atualizando
Se o QR nunca aparece, geralmente já existem credenciais válidas. Para forçar um QR novo, apague a pasta auth_info_baileys/ e reinicie. sock . ev . on ( 'connection.update' , ( update ) => {
console . log ( 'connection update:' , update )
})
printQRInTerminal está deprecated. Escute o 'qr' em connection.update e renderize com qrcode-terminal.
Mensagens falhando ao enviar
Implemente getMessage em SocketConfig: const sock = makeWASocket ({
getMessage : async ( key ) => await getMessageFromStore ( key )
})
Para retries completos: import NodeCache from '@cacheable/node-cache'
import { CacheStore } from '@whiskeysockets/baileys'
const msgRetryCounterCache = new NodeCache () as CacheStore
const sock = makeWASocket ({
msgRetryCounterCache ,
getMessage : async ( key ) => await getMessageFromStore ( key ),
})
Votos de enquete não decifrando
Você precisa de getMessage em SocketConfig e getAggregateVotesInPollMessage. import { getAggregateVotesInPollMessage } from '@whiskeysockets/baileys'
sock . ev . on ( 'messages.update' , event => {
for ( const { key , update } of event ) {
if ( update . pollUpdates ) {
const pollCreation = await getMessage ( key )
if ( pollCreation ) {
console . log (
'aggregation: ' ,
getAggregateVotesInPollMessage ({
message: pollCreation ,
pollUpdates: update . pollUpdates ,
})
)
}
}
}
})
Áudios não tocam em alguns aparelhos
Converta com ffmpeg: ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
await sock . sendMessage ( jid , {
audio: { url: './output.ogg' },
mimetype: 'audio/mp4'
})
Mensagens em grupo falhando ou lentas
Configure cachedGroupMetadata: import NodeCache from '@cacheable/node-cache'
const groupCache = new NodeCache ({ stdTTL: 5 * 60 , useClones: false })
const sock = makeWASocket ({
cachedGroupMetadata : async ( jid ) => groupCache . get ( jid )
})
sock . ev . on ( 'groups.update' , async ([ event ]) => {
const metadata = await sock . groupMetadata ( event . id )
groupCache . set ( event . id , metadata )
})
sock . ev . on ( 'group-participants.update' , async ( event ) => {
const metadata = await sock . groupMetadata ( event . id )
groupCache . set ( event . id , metadata )
})
Sendo deslogado de todos os aparelhos
Geralmente por chatModify com dados incorretos. // ok
await sock . chatModify ({ archive: true , lastMessages: [ lastMsgInChat ] }, jid )
// perigoso
await sock . chatModify ({ archive: true , lastMessages: [] }, jid )
Nunca chame chatModify com dados não verificados.
Apague a pasta de auth state
rm -rf auth_info_baileys/
Reinicie e escaneie novo QR
Verifique que salva creds em todo update
sock . ev . on ( 'creds.update' , saveCreds )
await sock . updateMediaMessage ( msg )
Em downloadMediaMessage: import { createWriteStream } from 'fs'
import { downloadMediaMessage , getContentType } from '@whiskeysockets/baileys'
sock . ev . on ( 'messages.upsert' , async ({ messages }) => {
for ( const m of messages ) {
if ( ! m . message ) return
const messageType = getContentType ( m . message )
if ( messageType === 'imageMessage' ) {
const stream = await downloadMediaMessage (
m ,
'stream' ,
{ },
{
logger ,
reuploadRequest: sock . updateMediaMessage
}
)
const writeStream = createWriteStream ( './my-download.jpeg' )
stream . pipe ( writeStream )
}
}
})
Debug logging completo
import makeWASocket from '@whiskeysockets/baileys'
import P from 'pino'
const sock = makeWASocket ({
logger: P ({ level: 'debug' }),
})
Para mais, veja Estender o Baileys .
Suporte
Discord do Baileys Servidor Discord da comunidade.