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.09k stars 1.2k forks source link

Wapi inject directly on whatsapp web does not work again #2795

Open josephMblT opened 2 months ago

josephMblT commented 2 months ago

Issue

Before, I used to inject the WAPI script directly into WhatsApp Web and could successfully get messages and create listeners. However, now when I try to retrieve all contacts or perform similar operations, it fails, and I notice that the Store object is always empty. I’m unsure if others have encountered this issue. While creating a new client with a Node.js server works, my use case requires running it directly on WhatsApp Web. Can you provide any insights or solutions for this problem?

i do this by running the bundle Wapi

i get and error here

Code

(async()=>{
        if (window.__debug)
            await A(),
            m();
        else {
            await A();
            const e = window[o.webpack].length - 1;
            !window[o.webpack][e][0].includes(o.parasite) && document.querySelectorAll("#app .two").length && m()
        }
    }

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '0')

when i try getting all contacts

WAPI.getAllContacts(); VM2465:1 Uncaught TypeError: Cannot read properties of undefined (reading 'map') at window.WAPI.window.WAPI.getAllContacts (:1:86008)

what i this is happening

function injectParasite() { if (window.__debug) { getStore(window.getModuleList()).finally(); } else { if ( window.webpackChunkwhatsapp_web_client && Array.isArray(window.webpackChunkwhatsapp_web_client) ) { const parasite = injectConfig.parasite; window[injectConfig.webpack].push([ [parasite], {}, async function (o) { let modules = []; for (let idx in o.m) { modules.push(o(idx)); } await getStore(modules); } ]); } } }

I try tracing the code and I noticed that

this inject parasite is been set and i don't think it is ever been called because from what I see when its been call, the Store is been populated

Please I really need help in this,

you can try by running yarn build:wapi

copy the code in the dist/lib/wapi/wapi.js and paste on the whatsapp web console and press Enter and try any WAPI function, none will work

ghayman commented 2 months ago

Can you install the code from Github orkestral/master directly?

There was a big update to WhatsApp a couple of months ago that totally broke the WAPI insertion and Store item generation.

A new method has been devised but has not been officially release yet - so if you can try master branch here, let us know how you get on

josephMblT commented 2 months ago

Hi @ghayman, normally if i create a node server and I install it as a dependency, it work well, my use case is am using an electron application and i need to inject the venom as a preload script into the webview.

Aetiru commented 2 months ago

Hi @ghayman, I am currently needing the same thing you mentioned, I thought about extracting the WhatsApp session this way

const sessionData = await view1.webContents.executeJavaScript( new Promise((resolve, reject) => { var request = window.indexedDB.open("wawc"); request.onsuccess = function() { var db = request.result; var transaction = db.transaction(["user"], "readonly"); var objectStore = transaction.objectStore("user"); var getAllRequest = objectStore.getAll(); getAllRequest.onsuccess = function() { resolve(getAllRequest.result); }; getAllRequest.onerror = function() { reject(getAllRequest.error); }; }; request.onerror = function() { reject(request.error); }; }); );

And then inject it into venom but I don't know if it's possible

ghayman commented 2 months ago

I'm not really familiar with how to use this with Electron. Does it use Chrome/Chromium browser?

Look at the latest code in master branch to see how this now does the code injection https://github.com/orkestral/venom/blob/master/src/api/whatsapp.ts : initService()

josephMblT commented 2 months ago

thanks for the above response, currently if am running with puppeteer, it appears that with puppeteer, wapi works well, am still trying to find out why it is not working when i code the webpack bundle of wapi and paste on the console it does not work.

am trying to figure out how the puppeteer Store gets populated

josephMblT commented 2 months ago

` await this.page.evaluate(() => { window['debug'] = eval("require('debug');"); console.log({code:window['__debug']});

  });`

  please i was able to trace the code and i know where my problem is coming from, please this
  `require('__debug` i need to know were it is coming from, so i can inject it to my script,
ghayman commented 2 months ago

__debug is the module that allows to access all the WhatsApp modules. (NOTE: webpack no longer exists due to WhatsApp changes - there is some backwards compatible code still in there to help when web.whatsapp.com updates in the browser)

It should be established before you try and inject wapi.js - here is venom code location src/api/whatsapp.ts: line 51

On line 60 you can see venom injecting wapi.js

josephMblT commented 2 months ago

@ghayman thanks for your help, i was able to have venom working as expected.