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.02k stars 796 forks source link

Fixing SendImage method Issue #1165

Open nadjib-boum opened 1 year ago

nadjib-boum commented 1 year ago

So I'm creating a chrome extension to automate message sending. I used the sendImage method `window.WAPI.sendImage = function (imgBase64, chatid, filename, caption, done) {

//var idUser = new window.Store.UserConstructor(chatid);

var idUser = new window.Store.UserConstructor(chatid, { intentionallyUsePrivateConstructor: true });

// create new chat

return Store.Chat.find(idUser).then((chat) => {

        var mediaBlob = window.WAPI.base64ImageToFile(imgBase64, filename);

        var mc = new Store.MediaCollection(chat);

        mc.processAttachments([{file: mediaBlob}, 1], chat, 1).then(() => {

                var media = mc.models[0];

                media.sendToChat(chat, { caption: caption });

                if (done !== undefined) done(true);

        });

});

} ` But It did not work, So what I did is changing: var media = mc.models[0]; with : var media = mc._models[0];

And It did Work! So in case someone is running into this problem, try this solution.

erm3nda commented 1 year ago

This happened few days ago with getUnreadMessages, had to prepend "_" to chat models. Happily this time is easy to fix again, thank you. Fixed and working again.