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_message_to_id no longer works like before #904

Open darkash opened 4 years ago

darkash commented 4 years ago

send_message_to_id no longer works like it was previously

right now it can only send message to someone who previously had chatroom. Meanwhile before Whatsapp Web update, you can create new chat room and send the message there. Is there alternative to this?

g4w4 commented 4 years ago

I have the same problem, something changed in how the chat room was created

ModelCreateError: Unknown at t.n (https://web.whatsapp.com/app.5be2ce7458b30031ac49.js:1:1041158) at new t (https://web.whatsapp.com/app.5be2ce7458b30031ac49.js:1:348068) at https://web.whatsapp.com/app2.13be54c9099a5680d99c.js:2:812334 at H (https://web.whatsapp.com/app.5be2ce7458b30031ac49.js:1:1011872) at MutationObserver.W (https://web.whatsapp.com/app.5be2ce7458b30031ac49.js:1:1011453)

alpires commented 4 years ago

Some idea about this?

mayconmano commented 4 years ago

Some idea about this? 2

DiegoLete commented 4 years ago

I have the same problem. Can't send a message to an Id if there is no previous chat. (sendMessageToID)

ghost commented 4 years ago

I've replaced window.WAPI.getChat function

    window.WAPI.getChat = async function(id, done) {
        id = typeof id == 'string' ? id : id._serialized;
        let found = window.Store.Chat.get(id);

        if (found === undefined) {
            //not found in Chat store
            const exists = await Store.WapQuery.queryExist(id);
            if (exists.status !== 404) {
                // Account exists
                const idUser = new window.Store.UserConstructor(id, { intentionallyUsePrivateConstructor: true })
                await Store.Chat.find(idUser)
                found = window.Store.Chat.get(id);
            } else {
                return false
            }
        }

        found.sendMessage = found.sendMessage ? found.sendMessage : function() {
            return window.Store.sendMessage.apply(this, arguments);
        };
        if (done !== undefined) done(found);
        return found;

    };
marcelocecin commented 4 years ago

or use: driver.send_message_to_id(message.chat_id['_serialized'],"text")

mayconmano commented 4 years ago

I've replaced window.WAPI.getChat function

    window.WAPI.getChat = async function(id, done) {
        id = typeof id == 'string' ? id : id._serialized;
        let found = window.Store.Chat.get(id);

        if (found === undefined) {
            //not found in Chat store
            const exists = await Store.WapQuery.queryExist(id);
            if (exists.status !== 404) {
                // Account exists
                const idUser = new window.Store.UserConstructor(id, { intentionallyUsePrivateConstructor: true })
                await Store.Chat.find(idUser)
                found = window.Store.Chat.get(id);
            } else {
                return false
            }
        }

        found.sendMessage = found.sendMessage ? found.sendMessage : function() {
            return window.Store.sendMessage.apply(this, arguments);
        };
        if (done !== undefined) done(found);
        return found;

    };

Sorry, but not work

ghost commented 4 years ago

@mayconmano check if you are awaiting your window.WAPI.getChat when sending message. Mine is working that way.

Manjit2003 commented 4 years ago

@lucasmori1 I have tried : WAPI.sendMessage('91xxxxxxxxxx@c.us', 'fsdfsd') but it is saying : TypeError: chat.sendMessage is not a function[Learn More] please help me fast....