Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Message implmentation #6

Open
knvpk opened this issue Jul 8, 2020 · 12 comments
Open

Query Message implmentation #6

knvpk opened this issue Jul 8, 2020 · 12 comments

Comments

@knvpk
Copy link

knvpk commented Jul 8, 2020

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: "[email protected]"
        }

    },
    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
Copy link
Owner

ndunks commented Jul 8, 2020

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

@knvpk
Copy link
Author

knvpk commented Jul 9, 2020

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
Copy link
Owner

ndunks commented Jul 9, 2020

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

@ndunks
Copy link
Owner

ndunks commented Jul 9, 2020

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
Copy link
Author

knvpk commented Jul 9, 2020

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
Copy link
Author

knvpk commented Jul 9, 2020

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
Copy link
Owner

ndunks commented Jul 9, 2020

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
Copy link
Author

knvpk commented Jul 10, 2020

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
Copy link
Author

knvpk commented Jul 10, 2020

I changed the metric in interface from QUERY_MESSAGES to QUERY_MESSAGE

QUERY_MESSAGES = 7,

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
Copy link
Author

knvpk commented Jul 10, 2020

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

@ndunks
Copy link
Owner

ndunks commented Jul 10, 2020

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

@tmandinyenya
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants