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 #854

Open GgAaYyAaNn opened 4 years ago

GgAaYyAaNn commented 4 years ago

send_message_to_id is always return False

ruanduarte commented 4 years ago

Return False for me too, but the message is sending with success.

g4w4 commented 4 years ago

this worked for me, if I send the message it returns True and if I don't send it a False

window.WAPI.sendMessageToID = function (id, message, done) {
    try {
        window.getContact = (id) => {
            return Store.WapQuery.queryExist(id);
        }
        window.getContact(id).then(contact => {
            console.log('0')
            if (contact.status === 404) {
                console.log('0.1')
                return done ? done(true) : true
            } else {
                Store.Chat.find(contact.jid).then(chat => {
                    console.log('1')
                    chat.sendMessage(message);
                    return done ? done(true) : true
                }).catch(reject => {
                    try {
                        if (WAPI.sendMessage(id, message)) {
                            return done ? done(true) : true
                        }else{
                            return done ? done(true) : true
                        }
                    } catch (error) {
                        return done ? done(false) : false
                    }
                });
            } 
        });
    } catch (e) {
        console.log('fue 2')
        if (window.Store.Chat.length === 0)
            return done ? done(false) : false

        firstChat = Store.Chat.models[0];
        var originalID = firstChat.id;
        firstChat.id = typeof originalID === "string" ? id : new window.Store.UserConstructor(id, { intentionallyUsePrivateConstructor: true });

        if( ! firstChat.sendMessage ){
            return done ? done(false) : false
        }else if (done !== undefined) {
            firstChat.sendMessage(message).then(function () {
                firstChat.id = originalID;
                done(true);
            });
            return true;
        } else {
            firstChat.sendMessage(message);
            firstChat.id = originalID;
            return true;
        }
    }
}
dev-bitrix commented 4 years ago

@andrew-shamin Advertising of monetized Frameworks is strictly forbidden and will be reported