ndunks / WaJs

WhatsApp Web NodeJS
85 stars 33 forks source link

Query Message implmentation #6

Open knvpk opened 4 years ago

knvpk commented 4 years ago

Hi, Im trying to get the previous chat list of a contact or group, by debugging the whatsapp web im able to see that is related to query, as below

[
    "query",
    {
        count: "50",
        epoch: "5",
        index: "7A7B3E4A12A9F5BB266B1BBDE95EDF59",
        kind: "before",
        owner: "true",
        participant: undefined,
        type: "message",
        jid: {
            server: "c.us",
            user: "919133xxxxx",
            _serialized: "919133xxxxx@c.us"
        }

    },
    undefined
]

so im trying to implement it but getting error as writer:writeString passed non-string/wid type:, i think because the jid is Object in my message.

Can you tell me how to proceed furthur.

ndunks commented 4 years ago

You can convert JID/WID object to string with this function

knvpk commented 4 years ago

That function is returning a string combining values in server and user, but in original whatsapp web it is sending as object, if i use your helper function it will send as string which will not work for whatsapp server.

ndunks commented 4 years ago

can you attach the dump from web whatsapp? or point me to the code in web whatsapp js?

ndunks commented 4 years ago

Also, you not attach your code so I can't check it. Some binary need metric byte or it will fail. that byte is not part of the encrypted content.

knvpk commented 4 years ago

Im actually cloned the whatsappweb and debugging it please check below screenshots to understand ww_breakpoints_app2 This is there where i kept console.log for read and write places. ww_browser_console Total expanded console log object when writing

knvpk commented 4 years ago

I added below function in index.ts under whatsapp folder after queryStatus function thats it.

    queryMessage() {
        return this.query({
            count: "50",
            epoch: "5",
            index: "7A7B3E4A12A9F5BB266B1BBDE95EDF59",
            kind: "before",
            owner: "true",
            participant: undefined,
            type: "message",
            jid: widHelper.serialize({
                server: "c.us",
                user: "919133985985",
            })
        })
    }
ndunks commented 4 years ago

AFAIK, JID/WID is sent as string to whatsapp server. I never seen it send as object, you can look into binary writer in whatsapp code. It does replace all WID to string with correct "suffix" like replacing @c.us to @s.whatsapp.net.

If you sure that WID is sent as object, so you can try to change that suffix.

Also the group id is differ from user WID, something like {creator}-{timestamp}@c.us

knvpk commented 4 years ago

Im using the WID helper but getting the 401 status do you have any idea. Im using the same account in whatsapp web and this lib also. please check below logs i have annotated required parts

QUERY_MESSAGE_401

knvpk commented 4 years ago

I changed the metric in interface from QUERY_MESSAGES to QUERY_MESSAGE https://github.com/ndunks/WaJs/blob/a900da7b60e5b9f79d8da349a4727e58c8a6d252/src/whatsapp/interfaces.ts#L257

because the type should be converted to query_{type}.

After doing that it is working got response from whatsapp server but another problem of handling binary for message. please check below screenshots messages_with_metric Sending metric as 7 messages_response Response is 16 messages but unable to handle. what to do here.

knvpk commented 4 years ago

Ans also when second response came (which has actual content), the callback is not called.

ndunks commented 4 years ago

Ah yes, just add little patch to not remove handle. make the handle function remove it self after all data received. Look here

tmandinyenya commented 4 years ago

@pavankumarkatakam can you kindly guide me on how I can clone the whatsapp web and run locally as you are doing. I would like to learn and test it too.