pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
15.48k stars 3.69k forks source link

Whatsapp modules #7

Closed JRakhimov closed 5 years ago

JRakhimov commented 5 years ago

Now project uses moduleRaid to fetch api of whatsapp, but I cant find modules like MediaCollection and UserConstructor through mR.findModule() it returns empty array. I need them to send pics, or how can I send images? Thanks in advance, @pedroslopez

pedroslopez commented 5 years ago

The way moduleRaid's findModule function works is by specifying a string that specifies a property to check against all modules and returning all matches. In this case, those modules you suggested don't directly contain those properties.

In the case of MediaCollection, going by WBOT, which you have referenced before, it looks like MediaCollection is actually obtained by checking if the module contains the key default.prototype.processFiles, which can't be done AFAIK by simply using a string through the findModule function.

Looking more into moduleRaid, I see a couple improvements that could be made with regards to module searching. For now I've opened an issue asking the author of the intended functionality of its findFunction method, but as far as I can see, a slight modification can allow us to search for modules in a more specific manner. If my suggestion isn't the way it's intended to be done we'll see what the author says, but in any case we can make some modifications to our version of moduleRaid that allows this.

Let's wait a couple days and see if he replies on the linked issue I've opened.

pedroslopez commented 5 years ago

My pull request on moduleRaid was accepted, so I switched the project to use this new version. What you're mentioning here should now be possible using a search function, like so:

// Grab MediaCollection
window.Store.MediaCollection = window.mR.findModule((module) => module.default && module.default.prototype && module.default.prototype.processFiles !== undefined);

// Grab UserConstructor   
window.Store.UserConstructor = window.mR.findModule((module) => module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser);

This will be available once cf8c54879 is merged.