Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing spinnies library from venom #2820

Open
9cb14c1ec0 opened this issue Nov 10, 2024 · 9 comments
Open

Removing spinnies library from venom #2820

9cb14c1ec0 opened this issue Nov 10, 2024 · 9 comments
Labels
enhancement New feature or request needs triage Needs avaliation

Comments

@9cb14c1ec0
Copy link
Contributor

Currently venom uses a third party library to add some eye-candy to the terminal output via progress spinners. This interferes automated log shipping and parsing. If I open a pull request to remove spinnies while retaining all other logged info, would it get merged?

@9cb14c1ec0 9cb14c1ec0 added enhancement New feature or request needs triage Needs avaliation labels Nov 10, 2024
@ghayman
Copy link
Contributor

ghayman commented Nov 12, 2024

@9cb14c1ec0 good idea! Let me test it out

@allanalcantara
Copy link

options {
disableSpins: true, // Will disable Spinnies animation, useful for containers (docker) for a better log
}

??

@byroncoetsee
Copy link

Would also love to get some clean logging that's functional, even if its not as pretty.

@allanalcantara that doesn't seem to make much of a difference for me.
Anything coming from spinnies still gets captured as errors (using pm2). Normal console.log messages are considered stdout.

  • see all the success messages and normal outputs from spinnes all captured in server-err.log.
Screenshot 2025-01-12 at 17 33 14

@allanalcantara
Copy link

allanalcantara commented Jan 14, 2025

Também adoraria obter um registro limpo e funcional, mesmo que não seja tão bonito.

@allanalcantaraisso não parece fazer muita diferença para mim. Qualquer coisa vinda de spinnies ainda é capturada como erros (usando pm2). Mensagens normais de console.log são consideradas stdout.

  • veja todas as mensagens de sucesso e saídas normais de spinnes, todas capturadas em server-err.log.
Captura de tela 2025-01-12 às 17 33 14

show-me you code , in this part
image

it will show your session status if you remove it it will not display...

@byroncoetsee
Copy link

Appologies it's a little verbose as I'm doing other things in the middle (I've tried to remove repeated code to shorten, like all the cases in the switch where I handle websocket connections differently)

  try {
    await create(
      sessionGuid,
      async (base64Qr, asciiQR) => {
        console.log(`QR Code for session ${sessionGuid}:`);
        console.log(asciiQR);

        // Save QR code image and send to clients
        if (base64Qr) {
          const matches = base64Qr.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/);
          if (matches && matches.length === 3) {
            const imageBuffer = Buffer.from(matches[2], "base64");
            const qrPath = join(sessionsDir, sessionGuid, `qr.png`);
            await writeFile(qrPath, imageBuffer);
            console.log(`QR code saved to: ${qrPath}`);

            // Send QR code to connected clients
            eventCallback("qr_code", {
              qrCode: base64Qr,
              qrPath,
            });
          }
        }
      },
      (statusSession, session) => {
        switch (statusSession) {
          case "isLogged":
            console.log(green(`Already logged in: ${sessionGuid}`));
            break;

          ...

          case "successChat":
            console.log(
              green(`Successfully connected to chat: ${sessionGuid}`)
            );
            break;
        }
      },
      {
        disableWelcome: true,
        disableSpins: true,
        logQR: false,
        folderNameToken: sessionsDir,
        createPathFileToken: true,
      }
    ).then((client) => {
      if (!clients.has(sessionGuid)) {
        clients.set(sessionGuid, client);
      }
      start(client, eventCallback);
      console.log(green(`WhatsApp client started for session: ${sessionGuid}`));
      eventCallback("status", { status: "connected" });
    });
  } catch (error) {
    console.error(
      `Error starting WhatsApp client for session ${sessionGuid}:`,
      error
    );
    eventCallback("error", { message: error.message });
    throw error;
  }

@allanalcantara
Copy link

allanalcantara commented Jan 21, 2025

Appologies it's a little verbose as I'm doing other things in the middle (I've tried to remove repeated code to shorten, like all the cases in the switch where I handle websocket connections differently)

  try {
    await create(
      sessionGuid,
      async (base64Qr, asciiQR) => {
        console.log(`QR Code for session ${sessionGuid}:`);
        console.log(asciiQR);

        // Save QR code image and send to clients
        if (base64Qr) {
          const matches = base64Qr.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/);
          if (matches && matches.length === 3) {
            const imageBuffer = Buffer.from(matches[2], "base64");
            const qrPath = join(sessionsDir, sessionGuid, `qr.png`);
            await writeFile(qrPath, imageBuffer);
            console.log(`QR code saved to: ${qrPath}`);

            // Send QR code to connected clients
            eventCallback("qr_code", {
              qrCode: base64Qr,
              qrPath,
            });
          }
        }
      },
      (statusSession, session) => {
        switch (statusSession) {
          case "isLogged":
            console.log(green(`Already logged in: ${sessionGuid}`));
            break;

          ...

          case "successChat":
            console.log(
              green(`Successfully connected to chat: ${sessionGuid}`)
            );
            break;
        }
      },
      {
        disableWelcome: true,
        disableSpins: true,
        logQR: false,
        folderNameToken: sessionsDir,
        createPathFileToken: true,
      }
    ).then((client) => {
      if (!clients.has(sessionGuid)) {
        clients.set(sessionGuid, client);
      }
      start(client, eventCallback);
      console.log(green(`WhatsApp client started for session: ${sessionGuid}`));
      eventCallback("status", { status: "connected" });
    });
  } catch (error) {
    console.error(
      `Error starting WhatsApp client for session ${sessionGuid}:`,
      error
    );
    eventCallback("error", { message: error.message });
    throw error;
  }

weird..

Image

Image

I just created it, and it showed me off...

const venom = require('venom-bot');
venom
    .create(
        'sessionName',
        (base64Qrimg, asciiQR, attempts, urlCode) => {
            // console.log('Number of attempts to read the qrcode:\n', attempts);
            console.log('Terminal qrcode:\n', asciiQR);
            console.log('urlCode (data-ref):\n', urlCode);
            console.log('base64 image string qrcode:\n', base64Qrimg);
        },
        (statusSession, session) => {
            console.log('Status Session: ', statusSession); //return isLogged || notLogged || browserClose || qrReadSuccess || qrReadFail || autocloseCalled
            // if (!statusSession) { return browserClose } // Se a sessão estiver invalida, enviar uma mensagem ao Dono para finalizar
        },
        {
            folderNameToken: 'tokens', //folder name when saving tokens
            mkdirFolderToken: '', //folder directory tokens, just inside the venom folder, example:  { mkdirFolderToken: '/node_modules', } //will save the tokens folder in the node_modules directory
            headless: 'new', // you should no longer use boolean false or true, now use false, true or 'new' learn more https://developer.chrome.com/articles/new-headless/
            devtools: true, // Open devtools by default
            useChrome: true, // If false will use Chromium instance
            debug: true, // Opens a debug session
            logQR: false, // Logs QR automatically in terminal
            logger: undefined, // Desativa logs no console
            browserWS: '', // If u want to use browserWSEndpoint
            browserArgs: ['--no-sandbox', '--disable-setuid-sandbox'], // Parameters to be added into the chrome browser instance
            addBrowserArgs: [''], // Add broserArgs without overwriting the project's original
            puppeteerOptions: {}, // Will be passed to puppeteer.launch
            disableSpins: true, // Will disable Spinnies animation, useful for containers (docker) for a better log
            disableWelcome: true, // Will disable the welcoming message which appears in the beginning
            updates: false, // Logs info updates automatically in terminal
            updatesLog: true, // Logs info updates automatically in terminal
            autoClose: 60000, // Automatically closes the venom-bot only when scanning the QR code (default 60 seconds, if you want to turn it off, assign 0 or false)
            createPathFileToken: false, // creates a folder when inserting an object in the client's browser, to work it is necessary to pass the parameters in the function create browserSessionToken
            addProxy: [''], // Add proxy server exemple : [e1.p.webshare.io:01, e1.p.webshare.io:01]
            userProxy: '', // Proxy login username
            userPass: '' // Proxy password
        }
    )
    .then((client) => {
        start(client);
    })
    .catch((erro) => {
        console.error('Erro - start a Bot. Error: ', erro);
    });
async function start(client) {
    client.onMessage(async (message) => {
        await processarMensagem(client, message);
    });
    async function processarMensagem(client, message) {
       console.log('response:\n', message);
        const receiveMsg = message.body;
        if (receiveMsg === 'Hi' && message.isGroupMsg === false) {
            client
                .sendText(message.from, 'Welcome Venom 🕷')
                .then((result) => {
                    console.log('Result: ', result); //return object success
                })
                .catch((erro) => {
                    console.error('Error when sending: ', erro); //return object error
                });
        }
    };
}

@byroncoetsee
Copy link

Can you show me what's above the QR data?
I just used your exact code from above, copy paste over mine, and got this:

Image

@allanalcantara
Copy link

Can you show me what's above the QR data? I just used your exact code from above, copy paste over mine, and got this:

Image

logdebug app

@byroncoetsee
Copy link

I'm sorry I don't understand?

I turned debug false if that's what you mean - it didn't change things.

From your initial screenshot, can you show me the lines above the qr data in your terminal (like shown in mine)? I want to see what prints in between You're up to date 🎉🎉🎉 and the QR data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage Needs avaliation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants