orkestral / venom

Venom is a high-performance system developed with JavaScript to create a bot for WhatsApp, support for creating any interaction, such as customer service, media sending, sentence recognition based on artificial intelligence and all types of design architecture for WhatsApp.
https://orkestral.io
Apache License 2.0
6.13k stars 1.21k forks source link

Lib not working #2350

Closed almcarvalho closed 1 year ago

almcarvalho commented 1 year ago

Description

it doesn't repply

[Description of the bug, When Issue Happens] TimeoutError: waiting for function failed: timeout 30000ms exceeded at new WaitTask (C:\Users\Lucas\Documents\GitHub\botwhatsapp-venom\node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:680:34) at DOMWorld.waitForFunction (C:\Users\Lucas\Documents\GitHub\botwhatsapp-venom\node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:611:26) at Frame.waitForFunction (C:\Users\Lucas\Documents\GitHub\botwhatsapp-venom\node_modules\puppeteer\lib\cjs\puppeteer\common\FrameManager.js:1089:32) at Page.waitForFunction (C:\Users\Lucas\Documents\GitHub\botwhatsapp-venom\node_modules\puppeteer\lib\cjs\puppeteer\common\Page.js:2385:33) at injectApi (C:\Users\Lucas\Documents\GitHub\botwhatsapp-venom\node_modules\venom-bot\dist\controllers\browser.js:140:16) at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5) at async create (C:\Users\Lucas\Documents\GitHub\botwhatsapp-venom\node_modules\venom-bot\dist\controllers\initializer.js:297:9)

Environment

Steps to Reproduce

  1. Run a basic hello world
  2. Autenticate and send a message
  3. wait for the repply

Log Output

Your Code

import { create } from 'venom-bot';
import { stages, getStage } from './stages.js';

var pessoas = [];

create({
  session: 'store',
  multidevice: true,
  headless: false,
})
  .then((client) => start(client))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

function responder(cliente, from, texto) {
  cliente.sendText(from, texto).then(() => {
    console.log(`Messagem ${texto} enviada.`);
  }).catch(error => console.error('Error when sending message', error));
}

function start(client) {
  client.onMessage((message) => {
    console.log('recebeu nova mensagem ou mensagem de grupo');
    if (!message.isGroupMsg) {

      console.log('recebeu nova mensagem');

      client.sendText(message.from, "oi").then(() => {
        console.log('Message sent.');
      }).catch(error => console.error('Error when sending message', error));

      switch (message.text) {
        case '1':
          client.sendVoice(message.from, './teste.mp3').then((result) => {
            console.log('Result: ', result); //return object success
          }).catch((erro) => {
            console.error('Error when sending: ', erro); //return object error
          });
          break;

        case '2':
          // Send Messages with Buttons Reply
          const buttons = [
            {
              "buttonText": {
                "displayText": "Text of Button 1"
              }
            },
            {
              "buttonText": {
                "displayText": "Text of Button 2"
              }
            }
          ]
          client.sendButtons(message.from, 'Title', buttons, 'Description')
            .then((result) => {
              console.log('Result: ', result); //return object success
            })
            .catch((erro) => {
              console.error('Error when sending: ', erro); //return object error
            });

          break;

        case '3':
          //-10.7922474, -37.7556548
          client.sendLocation(message.from, '-10.7922474', '-37.7556548', 'Brasil')
            .then((result) => {
              console.log('Result: ', result); //return object success
            })
            .catch((erro) => {
              console.error('Error when sending: ', erro); //return object error
            });
          break;

        case '4':
          client
            .sendLinkPreview(
              message.from,
              'https://www.policeweb.com.br',
              'Software policial para GTAV-Fivem'
            )
            .then((result) => {
              console.log('Result: ', result); //return object success
            })
            .catch((erro) => {
              console.error('Error when sending: ', erro); //return object error
            });
          break;

        case '5':
          client
            .sendImage(
              message.from,
              './lucas.jpg',
              'image-name',
              'O dia que fui na casa do Steve!'
            )
            .then((result) => {
              console.log('Result: ', result); //return object success
            })
            .catch((erro) => {
              console.error('Error when sending: ', erro); //return object error
            });
          break;

        case '6':
          client
            .sendFile(
              message.from,
              './pdftest.pdf',
              'file_name',
              'Vou te mandar um pdf, dá uma olhada!'
            )
            .then((result) => {
              console.log('Result: ', result); //return object success
            })
            .catch((erro) => {
              console.error('Error when sending: ', erro); //return object error
            });
          break;

        case '7':
          client.setProfileStatus('Josh - Tô on! Manda ver! ✈️');
          client.sendText(message.from, "Status do perfil alterado!").then(() => {
            console.log('Message sent.');
          }).catch(error => console.error('Error when sending message', error));
          break;

        case '8':
          client.setProfileStatus('Josh - Estamos fechados!!! abriremos amanhã as 9h horas!');
          client.sendText(message.from, "Status do perfil alterado!").then(() => {
            console.log('Message sent.');
          }).catch(error => console.error('Error when sending message', error));
          break;

        case '9':
          client.setProfilePic('./store-open.jpg');
          client.sendText(message.from, "Foto de perfil aberto").then(() => {
            console.log('Message sent.');
          }).catch(error => console.error('Error when sending message', error));
          break;

        case '10':
          client.setProfilePic('./store-close.jpg');
          client.sendText(message.from, "Foto do perfil fechado").then(() => {
            console.log('Message sent.');
          }).catch(error => console.error('Error when sending message', error));
          break;

        default:
          var menu = '👋 Olá, como vai? \n\nEu sou o Josh, o *assistente virtual* do Fictícius Store. \n*Posso te ajudar?* 🙋‍♂️ \n *Escolha uma opção de 1 a 10* \n-----------------------------------\n1 - ```ENVIE AUDIO``` \n2 - ```MANDE BOTÕES```\n3 - ```LOCALIZAÇÃO```\n4 - ENVIE UM LINK\n5 - ENVIE UMA IMAGEM\n6 - ENVIE UM PDF\n7 - TROQUE O STATUS DO MEU PERFIL\n8 - VOLTE O STATUS DO MEU PERFIL\n9 - FOTO PERFIL ABERTO\n10 - FOTO PERFIL FECHADO - ```FALAR COM ATENDENTE - 0```';
          client.sendText(message.from, menu).then(() => {
            console.log('Message sent.');
          }).catch(error => console.error('Error when sending message', error));
          break;
      }

    }
  });
};
almcarvalho commented 1 year ago

you can close this issue, solved with: npm i venom-bot@latest thanks!