codigoencasa / bot-whatsapp

🤖 Crear Chatbot WhatsApp en minutos. Únete a este proyecto OpenSource (Typescript Version Pronto)
https://bot-whatsapp.netlify.app
MIT License
2.29k stars 799 forks source link

Implementar en Modo Producción #7

Closed eduande closed 2 years ago

eduande commented 2 years ago

Hola Leifer, como estás?

Mi nombre es Andres, estoy intentando lanzar a producción tu bot pero me devuelve error, aclaro que tengo poco conocimiento de programación...

Te comento los pasos;

Estoy en Linode: 1) Con Ubuntu 20.04 LTS lanzado los siguientes comandos en el root@localhost:

sudo apt-get update sudo apt-get upgrade curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - sudo apt-get install -y nodejs node --version npm --version sudo apt-get install git git clone https://github.com/leifermendez/bot-whatsapp.git

2) Después me dirijo a la carpeta bot-whatsapp, estando en ella ejecuto los siguientes comando para instalar las librerías que comentas:

npm install cp .env.example .env npm i express --save npm i moment --save npm i exceljs --save npm i whatsapp-web.js --save npm i qrcode-terminal --save npm i mime-db --save

3) Ejecuto npm start y me devuelve el siguiente error:

test-ws-bot@1.0.0 start /root/bot-whatsapp node ./app.js

No tenemos session guardada events.js:377 throw er; // Unhandled 'error' event ^

Error: listen EADDRINUSE: address already in use :::3000 at Server.setupListenHandle [as _listen2] (net.js:1331:16) at listenInCluster (net.js:1379:12) at Server.listen (net.js:1465:7) at Object. (/root/bot-whatsapp/app.js:219:8) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:12) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12) at internal/main/run_main_module.js:17:47 Emitted 'error' event on Server instance at: at emitErrorNT (net.js:1358:8) at processTicksAndRejections (internal/process/task_queues.js:82:21) { code: 'EADDRINUSE', errno: -98, syscall: 'listen', address: '::', port: 3000 } npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! test-ws-bot@1.0.0 start: node ./app.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the test-ws-bot@1.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2022-02-21T15_11_24_651Z-debug.log root@localhost:~/bot-whatsapp#

Cual podría ser la solución? Andrés ¡Muchas gracias!

leifermendez commented 2 years ago

Buenas ese error te sale porque parece que el puerto 3000 ya esta en uso. trata cambiando el puerto por otro puede ser 3001, 3002

eduande commented 2 years ago

Leifer, muchas gracias por tu atención, me podrás decir donde se cambia de puerto? en los archivos del proyecto o en el sistema operativo ejecutando comandos?

Porque ahora estoy en una instancia de Amazon Lightsail probando y me devuelve el siguiente error:

No tenemos session guardada El server esta listo por el puerto 3000 (node:31554) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process ! /home/ubuntu/bot-whatsapp/node_modules/puppeteer/.local-chromium/linux-961656/chrome-linux /chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

at onClose (/home/ubuntu/bot-whatsapp/node_modules/puppeteer/lib/cjs/puppeteer/node/Br

owserRunner.js:229:20) at Interface. (/home/ubuntu/bot-whatsapp/node_modules/puppeteer/lib/cjs/pup peteer/node/BrowserRunner.js:219:68) at Interface.emit (events.js:412:35) at Interface.close (readline.js:530:8) at Socket.onend (readline.js:254:10) at Socket.emit (events.js:412:35) at endReadableNT (internal/streams/readable.js:1334:12) at processTicksAndRejections (internal/process/task_queues.js:82:21) (Use node --trace-warnings ... to show where the warning was created) (node:31554) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error ori ginated either by throwing inside of an async function without a catch block, or by reject ing a promise which was not handled with .catch(). To terminate the node process on unhand led promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodej s.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:31554) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process wi th a non-zero exit code.


Después ejecuté los comandos que dejastes en el README, pense que podía ser eso: sudo apt-get install -y libgbm-dev sudo apt install -y gconf-service 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

Y me devuelve el primer error de que el puerto 300 está en uso...

test-ws-bot@1.0.0 start /home/ubuntu/bot-whatsapp node ./app.js

No tenemos session guardada events.js:377 throw er; // Unhandled 'error' event ^

Error: listen EADDRINUSE: address already in use :::3000 at Server.setupListenHandle [as _listen2] (net.js:1331:16) at listenInCluster (net.js:1379:12) at Server.listen (net.js:1465:7) at Object. (/home/ubuntu/bot-whatsapp/app.js:219:8) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:12) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12) at internal/main/run_main_module.js:17:47 Emitted 'error' event on Server instance at: at emitErrorNT (net.js:1358:8) at processTicksAndRejections (internal/process/task_queues.js:82:21) { code: 'EADDRINUSE', errno: -98, syscall: 'listen', address: '::', port: 3000 } npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! test-ws-bot@1.0.0 start: node ./app.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the test-ws-bot@1.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging outpu t above.

npm ERR! A complete log of this run can be found in: npm ERR! /home/ubuntu/.npm/_logs/2022-02-21T17_27_19_019Z-debug.log ubuntu@ip-172-26-1-104:~/bot-whatsapp$

leifermendez commented 2 years ago

https://github.com/leifermendez/bot-whatsapp/blob/main/app.js#L39 lo puedes cambiar aquí lo recomendado es en el archivo .env PORT=3001 y establecer el puerto

leifermendez commented 2 years ago

@eduande pásate por la guía de instalación de Ubuntu https://github.com/leifermendez/bot-whatsapp/wiki/Instalaci%C3%B3n