WhiskeySockets / Baileys

Lightweight full-featured typescript/javascript WhatsApp Web API
https://baileys.whiskeysockets.io/
MIT License
3.08k stars 1.06k forks source link

NPM #37

Closed Teamolduser closed 9 months ago

Teamolduser commented 1 year ago

Can Anyone Upload This Modules In Npmjs.com

I Tried But Its Giving Error Of tsc and typedoc

andresayac commented 1 year ago

I have not had a problem generating the package. Be careful, I do not rule out that it is not like that, I am new

https://github.com/WhiskeySockets/Baileys/blob/master/.github/workflows/publish-release.yml

image image

Teamolduser commented 1 year ago

I have not had a problem generating the package. Be careful, I do not rule out that it is not like that, I am new

https://github.com/WhiskeySockets/Baileys/blob/master/.github/workflows/publish-release.yml

image image

Can i publish in my npm

Teamolduser commented 1 year ago

I have not had a problem generating the package. Be careful, I do not rule out that it is not like that, I am new

https://github.com/WhiskeySockets/Baileys/blob/master/.github/workflows/publish-release.yml

image image

how can i publish @adiwajshing/baileys@4.4.0 in my npm after i clone from npm of @adiwajshin/baileys@4.4.0

andresayac commented 1 year ago

you don't need to use the npmjs.com package you can use yarn add github:WhiskeySockets/Baileys instead while the release is being fixed

Teamolduser commented 1 year ago

you don't need to use the npmjs.com package you can use yarn add github:WhiskeySockets/Baileys instead while the release is being fixed

but i want a single auth one system so i ask to you

andresayac commented 1 year ago

The truth is that I have not understood very well, when you say single auth

dhirennjaypal commented 1 year ago

I used to use this module via require() but it no longer works i gives me this error Cannot find module '...\node_modules\@adiwajshing\baileys\lib\index.js'

andresayac commented 1 year ago

I used to use this module via require() but it no longer works i gives me this error Cannot find module '...\node_modules\@adiwajshing\baileys\lib\index.js'

share screenshot of your package.json

Teamolduser commented 1 year ago

you don't need to use the npmjs.com package you can use yarn add github:WhiskeySockets/Baileys instead while the release is being fixed

but i want a single auth one system so i ask to you

but i want so how can i upload 4.4.0 in my npm

choopchik commented 1 year ago

I used to use this module via require() but it no longer works i gives me this error Cannot find module '...\node_modules\@adiwajshing\baileys\lib\index.js'

share screenshot of your package.json

image

I'm trying to have Electron load the WhatsApp Web UI directly and use Baileys to connect to the same WebSocket.

preload.js:


const { contextBridge, ipcRenderer, webFrame } = require('electron');
const { WAConnection } = require('@adiwajshing/baileys');
const fs = require('fs');

contextBridge.exposeInMainWorld('electron', {
  interceptWebSocket: () => {
    ipcRenderer.send('intercept-websocket');
  },
});

ipcRenderer.on('intercept-websocket', async () => {
  const interceptWebSocket = `
    const originalWebSocket = WebSocket;

    WebSocket = function (...args) {
      const ws = new originalWebSocket(...args);
      if (args[0].includes('wss://web.whatsapp.com/ws')) {
        window.electron.interceptWebSocket(args[0]);
      }
      return ws;
    };

    WebSocket.prototype = originalWebSocket.prototype;
  `;

  ipcRenderer.send('execute-script', interceptWebSocket);
});

ipcRenderer.on('execute-script', (event, script) => {
  webFrame.executeJavaScript(script);
});

ipcRenderer.on('intercept-websocket', async (event, webSocketUrl) => {
  const conn = new WAConnection();

  conn.logger.level = 'warn';
  conn.autoReconnect = true;
  conn.connectOptions.timeoutMs = 60 * 1000;

  conn.on('connecting', () => {
    console.log('Connecting to WhatsApp...');
  });

  conn.on('open', () => {
    console.log('Connected to WhatsApp');
    fs.writeFileSync('./auth_info.json', JSON.stringify(conn.base64EncodedAuthInfo(), null, 2));
  });

  conn.on('close', ({ reason, isReconnecting }) => {
    console.log('Disconnected from WhatsApp:', reason, 'Reconnecting:', isReconnecting);
  });

  conn.on('message-new', (message) => {
    const sender = message.key.remoteJid;
    const text = message.message?.conversation || message.message?.extendedTextMessage?.text;
    if (text) {
      console.log(`New message from ${sender}: ${text}`);
    }
  });

  try {
    if (fs.existsSync('./auth_info.json')) {
      const authInfo = JSON.parse(fs.readFileSync('./auth_info.json', 'utf-8'));
      conn.loadAuthInfo(authInfo);
    }
    await conn.connect();
  } catch (error) {
    console.error('Error connecting to WhatsApp:', error);
  }
});

Error:


Error: Cannot find module '/home/user/dev/wa-desktop/node_modules/@adiwajshing/baileys/lib/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:416:19)
    at Module._findPath (node:internal/modules/cjs/loader:658:18)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1040:27)
    at o._resolveFilename (node:electron/js2c/renderer_init:2:3879)
    at Module._load (node:internal/modules/cjs/loader:900:27)
    at f._load (node:electron/js2c/asar_bundle:2:13330)
    at o._load (node:electron/js2c/renderer_init:2:3109)
    at Module.require (node:internal/modules/cjs/loader:1120:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/home/user/dev/wa-desktop/app/view_preload.js:3:26)
(```
Teamolduser commented 1 year ago

I used to use this module via require() but it no longer works i gives me this error Cannot find module '...\node_modules\@adiwajshing\baileys\lib\index.js'

From where you clone or download this

choopchik commented 1 year ago

I used to use this module via require() but it no longer works i gives me this error Cannot find module '...\node_modules\@adiwajshing\baileys\lib\index.js'

From where you clone or download this

yarn add github:WhiskeySockets/Baileys

Teamolduser commented 1 year ago

I used to use this module via require() but it no longer works i gives me this error Cannot find module '...\node_modules\@adiwajshing\baileys\lib\index.js'

From where you clone or download this

yarn add github:WhiskeySockets/Baileys

in which bot

choopchik commented 1 year ago

in which bot

Don't understand the question (?)

Teamolduser commented 1 year ago

in which bot

Don't understand the question (?)

In which folder you cloned or download it

choopchik commented 1 year ago

I ran yarn add github:WhiskeySockets/Baileys from the top folder of the project.

Teamolduser commented 1 year ago

I ran yarn add github:WhiskeySockets/Baileys from the top folder of the project.

Can you give a folder link ?

choopchik commented 1 year ago

Folder link?, you mean: /home/user/dev/wa-desktop/

In the error message, it says: `Cannot find module '...\node_modules\@adiwajshing\baileys\lib\index.js'

But when looking at the Baileys files inside node_modules, the 'lib\index.js' file isn't there. Could this be because Baileys uses TypeScript (.ts) while my project is in JavaScript (.js)? screenshot: image

andresayac commented 1 year ago

you are going the other way, the method indicated does not exist WAConnection

if you want to build you should use const { makeWASocket } = require('@adiwajshing/baileys'); image

Teamolduser commented 1 year ago

const { makeWASocket } = require('@adiwajshing/baileys');

const { makeWASocket } = require('@adiwajshing/baileys');.default

choopchik commented 1 year ago

changed to const { makeWASocket } = require('@adiwajshing/baileys'); Still getting the same error:


Error: Cannot find module '/home/user/dev/wa-desktop/node_modules/@adiwajshing/baileys/lib/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:416:19)
    at Module._findPath (node:internal/modules/cjs/loader:658:18)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1040:27)
    at o._resolveFilename (node:electron/js2c/renderer_init:2:3879)
    at Module._load (node:internal/modules/cjs/loader:900:27)
    at f._load (node:electron/js2c/asar_bundle:2:13330)
    at o._load (node:electron/js2c/renderer_init:2:3109)
    at Module.require (node:internal/modules/cjs/loader:1120:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/home/user/dev/assitant-desktop/app/view_preload.js:3:26)
(
choopchik commented 1 year ago

This is the package.json of my Baileys:


{
  "name": "@adiwajshing/baileys",
  "version": "5.0.0",
  "description": "WhatsApp API",
  "homepage": "https://github.com/adiwajshing/Baileys",
  "main": "lib/index.js",
  "types": "lib/index.d.ts",
  "keywords": [
    "whatsapp",
    "js-whatsapp",
    "whatsapp-api",
    "whatsapp-web",
    "whatsapp",
    "whatsapp-chat",
    "whatsapp-group",
    "automation",
    "multi-device"
  ],
  "scripts": {
    "test": "jest",
    "prepare": "tsc",
    "build:all": "tsc && typedoc",
    "build:docs": "typedoc",
    "build:tsc": "tsc",
    "example": "node --inspect -r ts-node/register Example/example.ts",
    "gen:protobuf": "sh WAProto/GenerateStatics.sh",
    "lint": "eslint . --ext .js,.ts,.jsx,.tsx",
    "lint:fix": "eslint . --fix --ext .js,.ts,.jsx,.tsx"
  },
  "author": "Adhiraj Singh",
  "license": "MIT",
  "repository": {
    "url": "git@github.com:adiwajshing/baileys.git"
  },
  "dependencies": {
    "@hapi/boom": "^9.1.3",
    "axios": "^1.3.3",
    "futoin-hkdf": "^1.5.1",
    "libsignal": "https://github.com/adiwajshing/libsignal-node.git",
    "music-metadata": "^7.12.3",
    "node-cache": "^5.1.2",
    "pino": "^7.0.0",
    "protobufjs": "^6.11.3",
    "ws": "^8.0.0"
  },
  "peerDependencies": {
    "@adiwajshing/keyed-db": "^0.2.4",
    "jimp": "^0.16.1",
    "link-preview-js": "^3.0.0",
    "qrcode-terminal": "^0.12.0",
    "sharp": "^0.30.5"
  },
  "peerDependenciesMeta": {
    "@adiwajshing/keyed-db": {
      "optional": true
    },
    "jimp": {
      "optional": true
    },
    "qrcode-terminal": {
      "optional": true
    },
    "sharp": {
      "optional": true
    },
    "link-preview-js": {
      "optional": true
    }
  },
  "files": [
    "lib/*",
    "WAProto/*",
    "WASignalGroup/*.js"
  ],
  "devDependencies": {
    "@adiwajshing/eslint-config": "https://github.com/adiwajshing/eslint-config.git",
    "@adiwajshing/keyed-db": "^0.2.4",
    "@types/got": "^9.6.11",
    "@types/jest": "^27.5.1",
    "@types/node": "^16.0.0",
    "@types/sharp": "^0.29.4",
    "@types/ws": "^8.0.0",
    "eslint": "^8.0.0",
    "jest": "^27.0.6",
    "jimp": "^0.16.1",
    "link-preview-js": "^3.0.0",
    "qrcode-terminal": "^0.12.0",
    "sharp": "^0.30.5",
    "ts-jest": "^27.0.3",
    "ts-node": "^10.8.1",
    "typedoc": "^0.22.0",
    "typescript": "^4.0.0"
  }
}
Teamolduser commented 1 year ago

``

changed to const { makeWASocket } = require('@adiwajshing/baileys'); Still getting the same error:

Error: Cannot find module '/home/user/dev/wa-desktop/node_modules/@adiwajshing/baileys/lib/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:416:19)
    at Module._findPath (node:internal/modules/cjs/loader:658:18)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1040:27)
    at o._resolveFilename (node:electron/js2c/renderer_init:2:3879)
    at Module._load (node:internal/modules/cjs/loader:900:27)
    at f._load (node:electron/js2c/asar_bundle:2:13330)
    at o._load (node:electron/js2c/renderer_init:2:3109)
    at Module.require (node:internal/modules/cjs/loader:1120:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/home/user/dev/assitant-desktop/app/view_preload.js:3:26)
(

use yarn add @adiwajshing/baileys@github:WhiskeySockets

choopchik commented 1 year ago

$ yarn add @adiwajshing/baileys@github:WhiskeySockets
yarn add v1.22.19
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
error Invalid hosted git fragment "github:WhiskeySockets".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
Teamolduser commented 1 year ago
$ yarn add @adiwajshing/baileys@github:WhiskeySockets
yarn add v1.22.19
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
error Invalid hosted git fragment "github:WhiskeySockets".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

try to run with npm i @adiwajshing/baileys@github:WhiskeySockets

choopchik commented 1 year ago

$ npm i @adiwajshing/baileys@github:WhiskeySockets
npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/null/WhiskeySockets.git
npm ERR! git@github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2023-05-03T21_27_16_831Z-debug-0.log
Teamolduser commented 1 year ago
$ npm i @adiwajshing/baileys@github:WhiskeySockets
npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/null/WhiskeySockets.git
npm ERR! git@github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2023-05-03T21_27_16_831Z-debug-0.log

can you told me what are you trying to do

Teamolduser commented 1 year ago
$ npm i @adiwajshing/baileys@github:WhiskeySockets
npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/null/WhiskeySockets.git
npm ERR! git@github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2023-05-03T21_27_16_831Z-debug-0.log

try this yarn add @adiwajshing/baileys@github:WhiskeySockets/baileys

choopchik commented 1 year ago

can you told me what are you trying to do

To require Baileys into my project

Teamolduser commented 1 year ago

can you told me what are you trying to do

To require Baileys into my project

which project

choopchik commented 1 year ago

whatsapp desktop app using electron

Teamolduser commented 1 year ago

whatsapp desktop app using electron

oh

try this yarn add @adiwajshing/baileys@github:WhiskeySockets/baileys

if this will show trouble with network then use npm i instead of yarn add

choopchik commented 1 year ago

still brings me the same error for require


Eror: Cannot find module '/home/user/dev/wa-desktop/node_modules/@adiwajshing/baileys/lib/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:416:19)
    at Module._findPath (node:internal/modules/cjs/loader:658:18)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1040:27)
    at o._resolveFilename (node:electron/js2c/renderer_init:2:3879)
    at Module._load (node:internal/modules/cjs/loader:900:27)
    at f._load (node:electron/js2c/asar_bundle:2:13330)
    at o._load (node:electron/js2c/renderer_init:2:3109)
    at Module.require (node:internal/modules/cjs/loader:1120:19)
    at require (node:internal/modules/cjs/helpers:103:18)
Teamolduser commented 1 year ago

still brings me the same error for require

Eror: Cannot find module '/home/user/dev/wa-desktop/node_modules/@adiwajshing/baileys/lib/index.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:416:19)
    at Module._findPath (node:internal/modules/cjs/loader:658:18)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1040:27)
    at o._resolveFilename (node:electron/js2c/renderer_init:2:3879)
    at Module._load (node:internal/modules/cjs/loader:900:27)
    at f._load (node:electron/js2c/asar_bundle:2:13330)
    at o._load (node:electron/js2c/renderer_init:2:3109)
    at Module.require (node:internal/modules/cjs/loader:1120:19)
    at require (node:internal/modules/cjs/helpers:103:18)

First remove old @adiwajshing/baileys Then try yarn add @adiwajshing/baileys@github:WhiskeySockets/baileys

choopchik commented 1 year ago

Did it. same error

Baileys, package.json file contains "main": "lib/index.js", but that file is clearly not present in the code

https://github.com/WhiskeySockets/Baileys/blob/master/package.json

I wonder why

Teamolduser commented 1 year ago

I have not had a problem generating the package. Be careful, I do not rule out that it is not like that, I am new

https://github.com/WhiskeySockets/Baileys/blob/master/.github/workflows/publish-release.yml

image image

Then i don't know ask to @PurpShell and @andresayac

Teamolduser commented 1 year ago

Did it. same error

Baileys, package.json file contains "main": "lib/index.js", but that file is clearly not present in the code

https://github.com/WhiskeySockets/Baileys/blob/master/package.json

I wonder why

still having issue try yarn add @adiwajshing/baileys@npm:@queenanya/baileys@5.0.0

PurpShell commented 1 year ago

We are working on this, we have an NPM org ready

ahmedRSA commented 1 year ago

We are working on this, we have an NPM org ready

Is there any update on when will you release it?

jmedellinc commented 1 year ago

I had troubles as well using baileys in a CJS node project (using require() instead of IMPORT)

They way I solved is as follows

const makeWASocketCont = require("@whiskeysockets/baileys");
const makeWASocket = makeWASocketCont.default;
const { useMultiFileAuthState, DisconnectReason } = makeWASocketCont;
Marcoant007 commented 1 year ago

You don't need yarn anymore using the normal npm already get the latest version and it works perfectly.

https://www.npmjs.com/package/@whiskeysockets/baileys

Teamolduser commented 9 months ago

You don't need yarn anymore using the normal npm already get the latest version and it works perfectly.

https://www.npmjs.com/package/@whiskeysockets/baileys

But how can u install module now a days npm has some issue than the other option is yarn to use

Teamolduser commented 9 months ago

I had troubles as well using baileys in a CJS node project (using require() instead of IMPORT)

They way I solved is as follows

const makeWASocketCont = require("@whiskeysockets/baileys");
const makeWASocket = makeWASocketCont.default;
const { useMultiFileAuthState, DisconnectReason } = makeWASocketCont;

You can use const makeWASocket = require("@whiskeysockets/baileys").default;

Abdullasl321 commented 1 month ago

I had troubles as well using baileys in a CJS node project (using require() instead of IMPORT)

They way I solved is as follows

const makeWASocketCont = require("@whiskeysockets/baileys");
const makeWASocket = makeWASocketCont.default;
const { useMultiFileAuthState, DisconnectReason } = makeWASocketCont;

It Worked Thx Bro :-)