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

Send VCard is no longer working #649

Open daniel-scatigno opened 5 years ago

daniel-scatigno commented 5 years ago

When trying to send a vcard, the follow javascript error happen: chat.addAndSendMsg is not a function

This is happening since Whatsappweb changes

daniel-scatigno commented 5 years ago

I´m trying to find a solution, it looks like the object chat doesn't have anymore a function named addAndSendMsg But this function is called on native Whatsapp script at the function sendContact

{
    key: "sendContact",
    value: function (e, t) {
        var i = t && t.msgContextInfo(this.id),
        a = P.default.defaults({
                ack: 0,
                body: Ve.default.fromContactModel(e).vcard,
                from: z.default.me,
                id: new ge.default({
                    from: z.default.me,
                    to: this.id,
                    id: (0, Ue.default)(),
                    participant: void 0,
                    selfDir: "out"
                }),
                local: !0,
                self: "out",
                subtype: e.formattedName,
                t: q.default.globalUnixTime(),
                to: this.id,
                type: "vcard",
                isNewMsg: !0
            }, i || {});
        debugger;
        (0, Xe.addAndSendMsgToChat)(this, a)
    }
}

For me this function creates a VCard from a Contact Object but I don't know where this "Xe" come from Can someone explain this better? What is (0, Xe.addAndSendMsgToChat)(this, a) doing?

erknkaya commented 5 years ago

Hi,

Try this.

    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.processFiles !== undefined) ? module.default : null },
            { id: "ChatClass", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.Collection !== undefined && module.default.prototype.Collection === "Chat") ? module : 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: "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: "AddAndSendMsgToChat", conditions: (module) => (module.addAndSendMsgToChat) ? module.addAndSendMsgToChat : 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.ChatClass.default.prototype.sendMessage = function (e) {
                        return window.Store.SendTextMsgToChat(this, ...arguments);
                    }
                    window.Store.ChatClass.default.prototype.addAndSendMsg = function (e) {
                        return window.Store.AddAndSendMsgToChat(this, ...arguments);
                    }                           
                    return window.Store;
                }
            }
        }
    }
smashah commented 4 years ago

A bit late but now it is fixed here: https://github.com/smashah/sulla/blob/master/src/lib/wapi.js

daniel-scatigno commented 4 years ago

I have tested the proposed solution And it works fine!

group2tts commented 4 years ago

Немного поздно, но теперь это исправлено здесь: https://github.com/smashah/sulla/blob/master/src/lib/wapi.js

Error: MsgKey error: something's not a wid: from:79999999999@c.us to:78797895685@c.us p:undefined at new e (app2.376a0367d0e928b68f73.js:2) at Object.createQuotedMsg (app2.376a0367d0e928b68f73.js:2) at a.value [as _getQuotedMsgObj] (app2.376a0367d0e928b68f73.js:2) at a.value [as quotedMsgObj] (app2.376a0367d0e928b68f73.js:2) at u.value (app.389d6565f1dd26f59e83.js:2) at t.value (app2.376a0367d0e928b68f73.js:2) at t.value (app2.376a0367d0e928b68f73.js:2) at mo (vendor1.dc5cb2396e48aed774d4.js:12) at bo (vendor1.dc5cb2396e48aed774d4.js:12) at ql (vendor1.dc5cb2396e48aed774d4.js:12)