pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
15.53k stars 3.7k forks source link

not work when deploy the app on linux #2678

Closed amjadalshah closed 11 months ago

amjadalshah commented 11 months ago

Is there an existing issue for this?

Describe the bug

the client not init and not got any error but on localhost its work i use linux vps with plesk i will try this command $ sudo apt install -y gconf-service libgbm-dev libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget but the most of packages is not exists

Expected behavior

i try with await and without it in client.initialize();

Steps to Reproduce the Bug or Issue

i try with await and without it in client.initialize();

Relevant Code

async function initClient(sessionName) { try { if (!clients.has(sessionName)) {

        const client = new Client({
            authStrategy: new LocalAuth({
                clientId: sessionName,
            })
        });

        client.on('authenticated', () => {
            console.error('authenticated:', sessionName)
            websocketService.sendForOne("Authentication failure!", SOCKETTYPES.AUTH_SUCCESS, sessionName);
        });

        client.on('qr', (qrCode) => {
            console.error('Scan the QR code:', qrCode);
            qrcode.generate(qrCode, { small: true });
            websocketService.sendForOne(qrCode, SOCKETTYPES.QRCODE, sessionName);
        });

        client.on("ready", () => {
            console.error(`WhatsApp bot is ready for ${sessionName}`);
            websocketService.sendForOne("ready!", SOCKETTYPES.READY, sessionName);
        });

        client.on('auth_failure', (message) => {
            console.error('Authentication failure:', message);
            websocketService.sendForOne("Authentication failure!", SOCKETTYPES.AUTH_FILED, sessionName);
        });

        client.on('disconnected', (reason) => {
            console.error('Client disconnected:', reason);
            websocketService.sendForOne("disconnected!", SOCKETTYPES.DISCONNECT, sessionName);
        });

        client.on("message", async (message) => {
            if (message.fromMe) return; // Ignore messages sent by the bot
            try {
                const reply = await getReply(message._data.body, sessionName)
                if (reply.success) {
                    const messageJson = JSON.parse(reply.data.message)
                    switch (reply.data.type) {
                        case MESSAGESTYPES.TEXT:
                            await message.reply(messageJson.body)
                            break;
                        case MESSAGESTYPES.MEDIA:
                            const media = await MessageMedia.fromUrl(process.env.API_STORAGE_URL + messageJson.mediaUrl);
                            await message.reply(media)
                            break;
                        case MESSAGESTYPES.LOCATION:
                            const location = new Location(parseFloat(messageJson.latitude), parseFloat(messageJson.longitude), { name: messageJson.description });
                            await message.reply(location);
                            break;
                        default:
                            await message.reply("no")
                            break;
                    }
                } else {
                    await message.reply("no")
                }
            } catch (error) {
                await message.reply("no")
            }

            // message.reply(JSON.stringify(message));

            websocketService.sendForOne(message, SOCKETTYPES.MESSAGE, sessionName);
        });

        clients.set(sessionName, client);

        await client.initialize();

        return client;
    } else {
        websocketService.sendForOne("user exists!", SOCKETTYPES.USER_EXISTS, sessionName);
        return null;
    }
} catch (err) {
    console.error("error in init whatsapp", err);
    return null
}

}

Browser Type

Chromium

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

linux web 1.23.0

18.17.1

Additional context

No response

alechkos commented 11 months ago

Not related to library issue

amjadalshah commented 11 months ago

yes but it related with it