open-wa/wa-automate-nodejs

onAddedToGroup Is not working #1413

ferhacks posted onGitHub

<!-- READ THIS FIRST: - Make sure you are running the latest version of @open-wa/wa-automate before reporting an issue. - Provide as many details as possible. Paste logs, configuration samples and code into the backticks. DO NOT DELETE ANY TEXT from this template! Otherwise, your issue may be closed without comment. -->

Describe the bug In more recent versions The variable onAddedToGroup has not been working

Steps to Reproduce 1.Start bot (npm start) 2.Add to a group 3.The bot does not give a response when added, but the commands work

create() code This is the code you use to create the client. e.g

const canvas = require('canvas-constructor')
const fs = require('fs-extra')
const kconfig = require('./config')
const options = require('./options')
const color = require('./lib/color')
const { sleep } = require('./lib/functions')
const config = require('./lib/config/config.json')
const welkom = JSON.parse(fs.readFileSync('./lib/config/welcome.json'))
const bklist = JSON.parse(fs.readFileSync('./lib/config/anti.json'))
const anti = JSON.parse(fs.readFileSync('./lib/config/blacklist.json'))
const fks = JSON.parse(fs.readFileSync('./lib/config/fake.json'))

// Cria um cliente de inicialização da BOT
const start = (kill = new Client()) => {
    console.log(color('\n[DEV]', 'red'), color('- +52 9984 9077 94 <-> https://chat.whatsapp.com/Dwu4XpOYOGCDHYDlSoZZG0'))
    console.log(color('[Íris]', 'red'), color('[Samu330] READY... Ya puedes usar coamndos\n'))

        // Forçar recarregamento caso obtenha erros
        kill.onStateChanged((state) => {
            console.log('[Estado da Íris]', state)
            if (state === 'UNPAIRED' || state === 'CONFLICT' || state === 'UNLAUNCHED') kill.forceRefocus()
        })

        // Le as mensagens e limpa cache
        kill.onMessage((async (message) => {
            kill.getAmountOfLoadedMessages()
            .then((msg) => {
                if (msg >= 3000) {
                    kill.cutMsgCache()
                }
            })
            kconfig(kill, message)
        }))

        // Funções para caso seja adicionada em um grupo
        kill.onAddedToGroup(async (chat) => {
            const wlcmsg = `Hola! \nMe solicitaron como BOT para este grupo, y estaré a su disposición! 烙\nSi quieres ver mis funciones usa ${config.prefix}menu!`
            const lmtgru = await kill.getAllGroups()
            let totalMem = chat.groupMetadata.participants.length
            if (chat.groupMetadata.participants.includes(config.owner)) {
                await kill.sendText(chat.id, wlcmsg)
            } else if (gc.length > config.memberLimit) {
                await kill.sendText(chat.id, `Un nuevo grupo, 7u7! \nLástima que no tenga el requisito, que es tener al menos ${config.memberLimit} miembros. Tú tienes ${totalMem}, reune más gente! `)
                await kill.leaveGroup(chat.id)
                await kill.deleteChat(chat.id)
            } else if (lmtgruc.length > config.gpLimit) {
                await kill.sendText(chat.id, `Lo sentimos, estamos en grupos máximos!\nActualmente estamos en ${lmtgru.length}/${config.gpLimit}`)
                await kill.leaveGroup(chat.id)
                await kill.deleteChat(chat.id)
            } else {
                kill.sendText(chat.id, wlcmsg)
            }
        })


        // Bloqueia na call
        kill.onIncomingCall(async (call) => {
            await kill.sendText(call.peerJid, `Que pena! Las llamadas no son compatibles y dificultan mucho! \nTe bloqueé para evitar digustos, contacta al dueño wa.me/${config.owner.replace('c.us', '')} para desbloquear. `)
            await kill.contactBlock(call.peerJid)
        })
    }

create(options(true, start))
    .then((kill) => start(kill))
    .catch((err) => new Error(err))

Expected behavior I expected the bot to be added to give a welcome response DEBUG INFO

Debug Info { WA_VERSION: 2.2106.5, PAGE_UA: WhatsApp/2.2037.6 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36, WA_AUTOMATE_VERSION: 3.6.13, BROWSER_VERSION: Chrome/88.0.4324.182 }

Screenshots image

Host (please complete the following information):

  • OS: [Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-65-generic x86_64)]

Additional context This variable onAddedToGroup worked in 3.2.4

I have seen that nobody else had put it, so it only happens to me?

thanks


I'm not sure if my issue is related but the onPartcipantsChanged() event fires randomly sometimes for all group members with the "add" action.

This has prevented me from adding a welcome message for new group members.

posted by Sp0derDev almost 4 years ago

@ferhacks is this still happening? is it replicable? It seems to be working fine for me.

Please share the create config maybe the issue is from there

posted by smashah almost 4 years ago

@ferhacks is this still happening?

Yes, this has been going on for some time

And I really don't know what's wrong either

Since I don't get any kind of error.

Please share the create config maybe the issue is from there

const options = {
        sessionId: 'Iris',
        headless: false,
        qrTimeout: 0,
        authTimeout: 0,
        restartOnCrash: start,
        cacheEnabled: false,
        useChrome: true,
        killProcessOnBrowserClose: true,
        throwErrorOnTosBlock: false,
        chromiumArgs: [
            '--no-sandbox',
            '--disable-setuid-sandbox',
            '--aggressive-cache-discard',
            '--disable-cache',
            '--disable-application-cache',
            '--disable-offline-load-stale-cache',
            '--disk-cache-size=0'
posted by ferhacks almost 4 years ago

@ferhacks is this still happening? I was not able to recreate this issue with your config. If it's still happening please hop into the discord to discuss further so we can resolve this issue asap.

posted by smashah almost 4 years ago

Feel free to message in the discord channel if this problem persists.

Closing for now.

Thanks

posted by smashah almost 4 years ago

Fund this Issue

$0.00
Funded

Pull requests