WhiskeySockets / Baileys

Lightweight full-featured typescript/javascript WhatsApp Web API
https://baileys.whiskeysockets.io/
MIT License
3.92k stars 1.34k forks source link

[BUG] TypeError: makeWASocket is not a function #459

Closed feri-irawan closed 1 year ago

feri-irawan commented 1 year ago
const sock = makeWASocket({ auth: state })
             ^
TypeError: makeWASocket is not a function
    at connectToWhatsApp (/home/runner/bot/index.ts:8:16)

Node.js v18.12.1

Code:

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('creds.update', saveCreds)

  sock.ev.on('connection.update', (update) => {
    const { connection, lastDisconnect } = update
    if (connection === 'close') {
      const shouldReconnect = (lastDisconnect?.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
      console.log('connection closed due to ', lastDisconnect?.error, ', reconnecting ', shouldReconnect)
      // reconnect if not logged out
      if (shouldReconnect) {
        connectToWhatsApp()
      }
    } else if (connection === 'open') {
      console.log('opened connection')
    }
  })

}
// run in main file
connectToWhatsApp()
Riders004 commented 12 months ago

Use MakeWaSocket