chrishubert / whatsapp-api

This project is a REST API wrapper for the whatsapp-web.js library, providing an easy-to-use interface to interact with the WhatsApp Web platform.
https://www.christophehubert.com
Other
574 stars 285 forks source link

When I scan Qr code it successfully scanned. in mobile it show connected (Active) but when i hit status check api it gave session_not connected status #189

Open hetsalk opened 3 months ago

hetsalk commented 3 months ago

When I scan Qr code it successfully scanned. in mobile it show connected (Active) but when i hit status check api it gave session_not connected status. So please guide me.

It gave Below error in terminal that

Initialize error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'default') at puppeteer_evaluation_script:5:95

alvarolucasno commented 3 months ago

I'm experiencing the same issue

tiagopierredev commented 3 months ago

getting the same error

andrew-belyi commented 2 months ago

same issue here

ubeyou commented 2 months ago

Unfortunately it's issue by whatsapp web js and if you wanted to use this, you need to update the source. need to update the web cache + use whatsapp web js (webpack-exodus branch) inside package.js

update package.js

{
  "name": "whatsapp-web-api",
  "version": "1.0.0",
  "description": "REST API wrapper for whatsapp-web.js",
  "main": "server.js",
  "scripts": {
    "start": "node server.js",
    "test": "jest --runInBand",
    "swagger": "node swagger.js"
  },
  "dependencies": {
    "axios": "^1.6.5",
    "dotenv": "^16.3.1",
    "express": "^4.18.2",
    "express-rate-limit": "^6.11.2",
    "qr-image": "^3.2.0",
    "qrcode-terminal": "^0.12.0",
    "swagger-ui-express": "^4.6.3",
    "whatsapp-web.js": "pedroslopez/whatsapp-web.js#webpack-exodus"
  },
  "devDependencies": {
    "eslint": "^8.38.0",
    "eslint-config-standard": "^17.0.0",
    "eslint-plugin-import": "^2.27.5",
    "eslint-plugin-n": "^15.7.0",
    "eslint-plugin-promise": "^6.1.1",
    "jest": "^29.5.0",
    "supertest": "^6.3.3",
    "swagger-autogen": "^2.23.7"
  },
  "keywords": [
    "whatsapp",
    "whatsapp-web",
    "api",
    "wrapper",
    "rest",
    "express",
    "axios"
  ],
  "author": "Christophe Hubert",
  "license": "MIT",
  "engines": {
    "node": ">=14.17.0"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/chrishubert/whatsapp-web-api.git"
  },
  "bugs": {
    "url": "https://github.com/chrishubert/whatsapp-web-api/issues"
  },
  "homepage": "https://github.com/chrishubert/whatsapp-web-api",
  "private": true
}

inside docker-compose.yaml

from

  app:
    container_name: whatsapp_web_api
    image: chrishubert/whatsapp-web-api:latest # Pull the image from Docker Hub

to

  app:
    container_name: whatsapp_web_api
    build:
      context: . #do
      dockerfile: Dockerfile 

and the environment add

    environment:
      - WEB_VERSION_CACHE_TYPE=REMOTE
      - WEB_VERSION=2.3000.1012536975-alpha

Dockerfile change to

# Use the official Node.js Alpine image as the base image
FROM node:20-alpine

# Set the working directory
WORKDIR /usr/src/app

# Install Chromium and Git
ENV CHROME_BIN="/usr/bin/chromium-browser" \
    PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true" \
    NODE_ENV="production"

RUN set -x \
    && apk update \
    && apk upgrade \
    && apk add --no-cache \
       udev \
       ttf-freefont \
       chromium \
       git

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install the dependencies
RUN npm install --only=production

# Copy the rest of the source code to the working directory
COPY . .

# Expose the port the API will run on
EXPOSE 3000

# Start the API
CMD ["npm", "start"]

later just docker compose up will do.

arktnld commented 2 months ago

I managed to resolve here #190

andrew-belyi commented 2 months ago

this temp solution is working I did:

Im running not via docker, but using npm run start command

Thanks!

proahmed22 commented 2 months ago

Hello ,How Can Deploy this Code in Vps Server ?

rizkyjs commented 2 months ago

This work for me, for windows 10 and im running not via docker and still using npm run start

WEB_VERSION_CACHE_TYPE=local

npm uninstall whatsapp-web.js npm install github:pedroslopez/whatsapp-web.js#webpack-exodus

chrishubert commented 2 months ago

Please use the latest docker version 🙏

raffus commented 2 months ago

Even after doing all the tips shown here, I'm unable to connect the number. Callback shows:

{"dataType":"loading_screen","data":{"percent":100,"message":"WhatsApp"},"sessionId":"1"} {"dataType":"loading_screen","data":{"percent":0,"message":"WhatsApp"},"sessionId":"1"} {"dataType":"loading_screen","data":{"percent":0,"message":"WhatsApp"},"sessionId":"1"} {"dataType":"loading_screen","data":{"percent":0,"message":"WhatsApp"},"sessionId":"1"} {"dataType":"loading_screen","data":{"percent":72,"message":"WhatsApp"},"sessionId":"1"} {"dataType":"loading_screen","data":{"percent":95,"message":"WhatsApp"},"sessionId":"1"} {"dataType":"loading_screen","data":{"percent":99,"message":"WhatsApp"},"sessionId":"1"}

node -v

v21.7.3

npm -v

10.5.0

npm uninstall whatsapp-web.js

npm install github:pedroslopez/whatsapp-web.js#webpack-exodus

npm WARN deprecated puppeteer@18.2.1: < 21.8.0 is no longer supported

npm run start

whatsapp-web-api@1.0.0 start node server.js

(node:1123768) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead. at node:punycode:3:9 at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:398:7) at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/realm:337:10) at loadBuiltinModule (node:internal/modules/helpers:104:7) at Module._load (node:internal/modules/cjs/loader:999:17) at Module.require (node:internal/modules/cjs/loader:1230:19) at require (node:internal/modules/helpers:179:18) at Object. (/home/rafael/whatsapp-api/node_modules/whatwg-url/lib/url-state-machine.js:2:18) at Module._compile (node:internal/modules/cjs/loader:1368:14) at Module._extensions..js (node:internal/modules/cjs/loader:1426:10) Server running on port 3000

I've noticed that when installing github:pedroslopez/whatsapp-web.js#webpack-exodus, npm tries to install an old puppeter version (18.2.1), which seems not being supported anymore. May this be the trick? How to fix it?

Please help.

Thanks

Roei639 commented 2 months ago

getting the same error

mdestafadilah commented 2 months ago

no update yet :(

mdestafadilah commented 2 months ago

this temp solution is working I did:

  • updated package,json to pedroslopez/whatsapp-web.js#webpack-exodus
  • changed variables WEB_VERSION_CACHE_TYPE=REMOTE, WEB_VERSION=2.3000.1012536975-alpha

Im running not via docker, but using npm run start command

Thanks!

still not working, always ssession_not_connected

arislanhaikal commented 2 months ago

Please use the latest docker version 🙏

After update with latest version after connected and i check sessions return

{
  "success": false,
  "state": null,
  "message": "browser tab closed"
}

any update?

arislanhaikal commented 2 months ago

2.3000.1012536975-alpha

I am solved with change docker env

- RATE_LIMIT_MAX=1000
- RATE_LIMIT_WINDOW_MS=1000
- WEB_VERSION='2.3000.1012536975-alpha'
- WEB_VERSION_CACHE_TYPE=remote
- RECOVER_SESSIONS=TRUE
mdestafadilah commented 2 months ago

2.3000.1012536975-alpha

I am solved with change docker env

  • RATE_LIMIT_MAX=1000
  • RATE_LIMIT_WINDOW_MS=1000
  • WEB_VERSION='2.3000.1012536975-alpha'
  • WEB_VERSION_CACHE_TYPE=remote
  • RECOVER_SESSIONS=TRUE

working with non-docker package!! thanks!!

Roei639 commented 1 month ago

Is the problem found?

mdestafadilah commented 1 month ago

Is the problem found?

not sure, but i success with trick like here https://github.com/chrishubert/whatsapp-api/issues/189#issuecomment-2089405230