mukulhase / WebWhatsapp-Wrapper

An API for sending and receiving messages over web.whatsapp [Working as of 18th May 2018]
https://webwhatsapi.readthedocs.io/en/latest/
MIT License
2.03k stars 797 forks source link

Error on load modules (Chat and Msg) #889

Open felippeefreire opened 4 years ago

felippeefreire commented 4 years ago

unfortunately WhatsApp has changed the way of encapsulating the modules. For this, I created this PR adapting for both versions.

https://github.com/mukulhase/WebWhatsapp-Wrapper/pull/888/files

g4w4 commented 4 years ago

In addition to your change, after logging in with the "wait_for_login" function, change the 'mainPage' attribute

location file: webwhatsapi wapi_js_wrapper.py

'mainPage': ".app.two"

by

'mainPage': ".app.h70RQ.two"

alpires commented 4 years ago

These changes didn't work to me in version 2.2023.2 of whatsapp web. Store.Chat dont work.

chirag90851 commented 4 years ago

working

if (!window.Store) { (function () { function getStore(modules) { let foundCount = 0; let neededObjects = [ { id: "Store", conditions: (module) => (module.Chat && module.Msg) ? module : null }, { id: "MediaCollection", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.processAttachments) ? module.default : null }, { id: "MediaProcess", conditions: (module) => (module.BLOB) ? module : null }, { id: "Wap", conditions: (module) => (module.createGroup) ? module : null }, { id: "ServiceWorker", conditions: (module) => (module.default && module.default.killServiceWorker) ? module : null }, { id: 'Presence', conditions: (value) => (value.default && value.default.Presence) ? value.default : null }, { id: "State", conditions: (module) => (module.STATE && module.STREAM) ? module : null }, { id: "WapDelete", conditions: (module) => (module.sendConversationDelete && module.sendConversationDelete.length == 2) ? module : null }, { id: "Conn", conditions: (module) => (module.default && module.default.ref && module.default.refTTL) ? module.default : null }, { id: "WapQuery", conditions: (module) => (module.queryExist) ? module : ((module.default && module.default.queryExist) ? module.default : null) }, { id: "CryptoLib", conditions: (module) => (module.decryptE2EMedia) ? module : null }, { id: "OpenChat", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.openChat) ? module.default : null }, { id: "UserConstructor", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null }, { id: "SendTextMsgToChat", conditions: (module) => (module.sendTextMsgToChat) ? module.sendTextMsgToChat : null }, { id: "SendSeen", conditions: (module) => (module.sendSeen) ? module.sendSeen : null }, { id: "sendDelete", conditions: (module) => (module.sendDelete) ? module.sendDelete : null } ]; for (let idx in modules) { if ((typeof modules[idx] === "object") && (modules[idx] !== null)) { let first = Object.values(modules[idx])[0]; if ((typeof first === "object") && (first.exports)) { for (let idx2 in modules[idx]) { let module = modules(idx2); if (!module) { continue; } neededObjects.forEach((needObj) => { if (!needObj.conditions || needObj.foundedModule) return; let neededModule = needObj.conditions(module); if (neededModule !== null) { foundCount++; needObj.foundedModule = neededModule; } }); if (foundCount == neededObjects.length) { break; } }

                    let neededStore = neededObjects.find((needObj) => needObj.id === "Store");
                    window.Store = neededStore.foundedModule ? neededStore.foundedModule : {};
                    neededObjects.splice(neededObjects.indexOf(neededStore), 1);
                    neededObjects.forEach((needObj) => {
                        if (needObj.foundedModule) {
                            window.Store[needObj.id] = needObj.foundedModule;
                        }
                    });
                    window.Store.sendMessage = function (e) {
                        return window.Store.SendTextMsgToChat(this, ...arguments);
                    };

                    if (window.Store.Presence) {
                        for (const prop in window.Store.Presence) {
                            if (prop === "Presence") {
                                continue;
                            }
                            console.log(prop);
                            window.Store[prop] = window.Store.Presence[prop] || window.Store[prop];
                        }
                    }

                    return window.Store;
                }
            }
        }

    }

    if (typeof webpackJsonp === 'function') {
        webpackJsonp([], {'parasite': (x, y, z) => getStore(z)}, ['parasite']);
    } else {
        webpackJsonp.push([
            ['parasite'],
            {
                parasite: function (o, e, t) {
                    getStore(t);
                }
            },
            [['parasite']]
        ]);
    }

})();

}

fnevesgx commented 4 years ago

Tested solution and worked well on 2.2023.2!!

Thanks for @felippeefreire and @chirag90851 for solving this issue so fastly \o/\o/\o/

michelcruz89 commented 4 years ago

Hi Guys

I tried on Whatsapp Web version 2.2023.2 this:

https://raw.githubusercontent.com/mukulhase/WebWhatsapp-Wrapper/master/webwhatsapi/js/wapi.js

Showed up message below:

Uncaught TypeError: window.Store.Msg is undefined debugger eval code:1144

I did a test in old version works fine.

michelcruz89 commented 4 years ago

Hi @ijoaobatista Workfine now. Many thanks. Cheers...

mhndm commented 4 years ago

.app its now just .two "mainPage": ".two",

jrrcdev commented 4 years ago

A better solution:

https://github.com/mukulhase/WebWhatsapp-Wrapper/pull/891

marcelofuhr commented 4 years ago

@mhndm Thank you!!!

amitmaliik commented 4 years ago

after changing it to .two got another issue: raise exception_class(message, screen, stacktrace) selenium.common.exceptions.JavascriptException: Message: TypeError: window.Store.Msg is undefined

which upon finding this issue we changed time.sleep(5) to time.sleep(60) but that too didn't help.

what do you think is the issue @mukulhase ?

kiyoshi-satoo commented 4 years ago

These changes didn't work to me in version 2.2023.2 of whatsapp web. Store.Chat dont work.

And many other modules don't work too....