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

WAPI.sendMessageToID does not work #1126

Open kivlanzein opened 2 years ago

kivlanzein commented 2 years ago

please help me, why sendMessageToID not work? , i can't send messages to the new number??

please help me..

vilsonei commented 2 years ago

Hi @Parveen-Mothsara, unfortunately I'm not using this function in WAPI.js.

Parveen-Mothsara commented 2 years ago

Hi @Parveen-Mothsara, unfortunately I'm not using this function in WAPI.js.

Hello @vilsonei any alternate available for download media.

erm3nda commented 1 year ago

Hi @vilsonei can you help me to Download media from incoming message.. How we use downloadFileWithCredentials or downloadFile.

Careful with that, in my experience even if the msg is created and distributed as "new message", the media could be not present or downloadable untill few ms/s after that. I had to use a retry function when downloading failed. The "download_with_credentials" thing just uses current cookie on the browser when downloading with XHR request, which is in my opinion, the right way to download everything.

Anyway, that should be an entirely new question.

vinay7722 commented 1 year ago

Hello, with the code bellow i can send messages to new ids without problem. There's just one weird thing about this function that its always returns "false". But the message is sent successfuly.

window.WAPI.sendMessageToID = function (id, message, done) {
    try {
        window.getContact = (id) => {
            return Store.WapQuery.queryExist(id);
        }
        window.getContact(id).then(contact => {
            if (contact.status === 404) {
                done(true);
            } else {
                if(typeof contact.jid === 'undefined') {
                        contact.jid = {
                            '_serialized' : id,
                            'server' : '@' + id.split('@')[1],
                            'user' : id.split('@')[0]
                        }
                 }
                Store.FindChat.findChat(contact.jid).then(chat => {
                    chat.sendMessage(message);
                    return true;
                }).catch(reject => {
                    if (WAPI.sendMessage(id, message)) {
                        done(true);
                        return true;
                    }else{
                        done(false);
                        return false;
                    }
                });
            }
        });
    } catch (e) {
        if (window.Store.Chat.length === 0)
            return false;

        firstChat = Store.Chat.models[0];
        var originalID = firstChat.id;
        firstChat.id = typeof originalID === "string" ? id : new window.Store.UserConstructor(id, { intentionallyUsePrivateConstructor: true });
        if (done !== undefined) {
            firstChat.sendMessage(message).then(function () {
                firstChat.id = originalID;
                done(true);
            });
            return true;
        } else {
            firstChat.sendMessage(message);
            firstChat.id = originalID;
            return true;
        }
    }
    if (done !== undefined) done(false);
    return false;
}

yeah its successfully sent the msg but in browsers console show many errors so can any have idea about this? error like this
image

erm3nda commented 1 year ago

I made my own function about this, which is simply as "get current count of true_ messages, sent it, read messages again then return the last id of the sent message. Found no other way to return the id of the sent message, which i really needed.

Regarding your question:

Store.FindChat.findChat(contact.jid).then(chat => {
                    chat.sendMessage(message); // THIS RETURNS NOTHING
                    return true;
                }).catch(reject => {
                    if (WAPI.sendMessage(id, message)) { // THIS RETURNS NOTHING
                        done(true);
                        return true;

Note that sendMessage function is not returning anything, so your code simple returns what that function returned, which is falsy value. No matter if you call chat.sendMessage function or WAPI.sendMessage, they end up being the same.

If you apply what I said in this line:

<-- count before ->>
chat.sendMessage(message);
<<-- count aftter ->>

Then you can return what you need. What you can't rely on is about if chat.sendMessage, which will be always false.

I can't share code right now, but that is the key here.

Parveen-Mothsara commented 3 months ago

Hi @vilsonei , How are you , I need your expertise, I have got error "WAPI is not defined error" . when i re download chromium its works some time and again show error, Please help me how to solve this.Thanks .

Parveen-Mothsara commented 3 months ago

Hi @vilsonei , You have any solution?

vilsonei commented 3 months ago

Hello @Parveen-Mothsara, Recently WhatsApp is making some updates to WhatsApp Web that change the way modules are exposed, no longer through webpackChunkwhatsapp_web_client, hence the error "WAPI is not defined error", because when loading WAPI An error occurs when reading the webpackChunkwhatsapp_web_client variable.

As the WAPI project has not been updated for a long time, I decided to migrate my projects to the https://github.com/wppconnect-team/wa-js project which is constantly being updated, so I recommend that you do so too.

Parveen-Mothsara commented 3 months ago

Thanks @vilsonei . I also migrate my projects to this https://github.com/wppconnect-team/wa-js project