text: const { create, Client } = require('@open-wa/wa-automate')
  const welcome = require('./lib/welcome')
  const msgHandler = require('./msgHndlr')
  const options = require('./options')
  
  const start = async (client = new Client()) => {
          console.log('[SERVER] Server Started!')
          // Force it to keep the current session
          client.onStateChanged((state) => {
              console.log('[Client State]', state)
              if (state === 'CONFLICT' || state === 'UNLAUNCHED') client.forceRefocus()
          })
          // listening on message
          client.onMessage((async (message) => {
              client.getAmountOfLoadedMessages()
              .then((msg) => {
                  if (msg >= 3000) {
                      client.cutMsgCache()
                  }
              })
              msgHandler(client, message)
          }))
  
          client.onGlobalParicipantsChanged((async (heuh) => {
              await welcome(client, heuh)
              //left(client, heuh)
              }))
          
          client.onAddedToGroup(((chat) => {
              let totalMem = chat.groupMetadata.participants.length
              if (totalMem < 10) { 
              	client.sendText(chat.id, `Cih member cuma ${totalMem}. Kalo mau invite bot, minimal jumlah member ada 10`).then(() => client.leaveGroup(chat.id)).then(() => client.deleteChat(chat.id))
              } else {
                  client.sendText(chat.groupMetadata.id, `Halo warga grup *${chat.contact.name}*\nTerimakasih sudah menginvite bot ini, untuk melihat menu silahkan ketik *!help*`)
              }
          }))
  
          /*client.onAck((x => {
              const { from, to, ack } = x
              if (x !== 3) client.sendSeen(to)
          }))*/
  
          // listening on Incoming Call
          client.onIncomingCall(( async (call) => {
              await client.sendText(call.peerJid, 'Maaf, BOT tidak bisa menerima panggilan.\n\nTelpon / VC = Block / Banned!')
              .then(() => client.contactBlock(call.peerJid))
          }))
      }
  
  create(options(true, start))
      .then(client => start(client))
      .catch((error) => console.log(error))
  