@fqihh/wajs-core
v2.0.13
Published
WhatsApp Web API library — built on @whiskeysockets/baileys with class-based WAClient API
Maintainers
Readme
@wajs/core
WhatsApp Web API library — clean class-based WAClient API, built on @whiskeysockets/baileys.
Install
npm install @fqihh/wajs-coreQuick Start
QR Code Login
import { makeWAClient } from '@fqihh/wajs-core'
const client = makeWAClient({ printQRInTerminal: true })
client.on('connection.update', ({ connection }) => {
if (connection === 'open') console.log('Connected!')
})
client.on('messages.upsert', ({ messages }) => {
const msg = messages[0]
if (!msg.key.fromMe) console.log('Msg from', msg.key.remoteJid)
})
await client.connectWithFile('./session')Pairing Code Login (no QR)
import { makeWAClient } from '@fqihh/wajs-core'
const client = makeWAClient()
let pairingRequested = false
client.on('connection.update', async ({ connection }) => {
if (connection === 'connecting' && !pairingRequested) {
pairingRequested = true
const { formatted } = await client.requestPairingCode('628123456789')
console.log('Enter code in WhatsApp:', formatted) // → 'ABCD-1234'
}
if (connection === 'open') console.log('Connected!')
})
await client.connectWithFile('./session')Custom Pairing Code
const { formatted } = await client.requestPairingCode('628123456789', 'MYCODE12')
// → 'MYCO-DE12'Config Options
| Option | Default | Description |
|--------|---------|-------------|
| logLevel | 'silent' | 'silent', 'info', 'debug' |
| browser | ['@wajs/core', 'Chrome', '120.0.0'] | Browser identifier |
| autoReconnect | true | Auto-reconnect on disconnect |
| maxReconnectAttempts | 0 | 0 = unlimited |
| reconnectDelay | 3000 | MS between reconnects |
| markOnlineOnConnect | false | Set presence online |
| printQRInTerminal | false | Print QR to stdout |
| syncFullHistory | false | Sync full history |
| autoFollowNewsletters | true | Auto-follow credit channels |
API Reference
Connection
client.connectWithFile(authDir) // file-based session
client.connectInMemory() // ephemeral (testing)
client.connect(authState, saveCreds) // custom auth state
client.disconnect()
client.logout()
client.state // 'open' | 'connecting' | 'close'
client.isOpen // boolean
client.sock // raw Baileys socketSending Messages
client.sendText(jid, 'Hello!')
client.sendImage(jid, buffer, 'caption')
client.sendVideo(jid, buffer, 'caption')
client.sendAudio(jid, buffer)
client.sendVoiceNote(jid, buffer)
client.sendDocument(jid, buffer, 'application/pdf', 'file.pdf')
client.sendSticker(jid, buffer)
client.sendLocation(jid, lat, lng)
client.sendContact(jid, { fullName: 'John', phone: '628123456789' })
client.sendReaction(jid, messageKey, '👍')
client.sendPoll(jid, 'Which?', ['A', 'B', 'C'])
client.sendViewOnce(jid, { image: buffer })
client.sendMessage(jid, content, options) // raw BaileysMessage Actions
client.deleteMessage(jid, key)
client.editMessage(jid, key, 'new text')
client.readMessages([key])
client.sendPresence(jid, 'composing')Groups
client.groupMetadata(jid)
client.groupCreate(subject, participants)
client.groupParticipantsUpdate(jid, participants, 'add'|'remove'|'promote'|'demote')
client.groupUpdateSubject(jid, 'New Name')
client.groupUpdateDescription(jid, 'Desc')
client.groupSettingUpdate(jid, 'announcement')
client.groupLeave(jid)
client.groupInviteCode(jid)
client.groupRevokeInvite(jid)
client.groupAcceptInvite(code)
client.groupToggleEphemeral(jid, 86400)Profile
client.getProfilePicUrl(jid)
client.fetchStatus(jid)
client.updateProfileStatus('status text')
client.updateProfileName('Name')
client.updateBlockStatus(jid, 'block'|'unblock')Newsletter / Channel
client.newsletterFollow(jid)
client.newsletterUnfollow(jid)
client.newsletterMute(jid)
client.newsletterUnmute(jid)
client.newsletterMetadata('invite'|'jid', key)
client.newsletterCreate(name, description)
client.newsletterUpdate(jid, { name, description })
client.newsletterReactMessage(jid, serverId, '🔥')
client.sendNewsletterMessage(jid, content)
// Manually follow credit channels
await client.followCreditChannels()
await client.followCreditChannels({ silent: true })Events
client.on('connection.update', ({ connection, qr, willReconnect }) => {})
client.on('creds.update', () => {})
client.on('messages.upsert', ({ messages, type }) => {})
client.on('messages.update', updates => {})
client.on('messages.delete', info => {})
client.on('messages.reaction', data => {})
client.on('message-receipt.update', updates => {})
client.on('chats.upsert', chats => {})
client.on('chats.update', updates => {})
client.on('contacts.upsert', contacts => {})
client.on('presence.update', ({ id, presences }) => {})
client.on('groups.upsert', groups => {})
client.on('group-participants.update', update => {})
client.on('call', calls => {})Newsletter Auto-Follow
On connect, the client automatically follows the configured credit/partner channels.
To disable:
const client = makeWAClient({ autoFollowNewsletters: false })To customize channels, edit FOLLOW_NEWSLETTER_JIDS in src/newsletter/index.js.
License
MIT
