Closed coolnickname closed 6 years ago
I just merged our current master tree from our private repository with a working implementation to send messages. Keep in mind, that this is still very early development and that signatures may change.
Inline the comments in the main.go file from line 35 - 45 and enter a jid (number@s.whatsapp.com) and a custom text. Start the program with go run main.go
, scan the qr code in your terminal and after a couple of seconds you should see the message in your whatsapp app.
If you want to check out the code, look at the conn.go, sending.go files and the composing package. For more detailed information on the crypto and binary parts check out sigalor/whatsapp-web-reveng.
Thanks man! I'll be sure to check it out soon.
It works pretty neat, I think you're actually the first person to implement this š¤
Some things I have noticed is that it only works if the message sent from the wrapper is the first message in the conversation, so I have to keep clearing the chat in order to send a message. Also is the ID hardcoded? It seems like it's the same String every time.
If both of these are true I can see how they're connected.
The ID is not hardcoded, it is generated by the random number generator provided in the math
package if not specified in the MessageInfo
struct. The seed was not changed and so it generated the same message tags every time you start the program. Your WhatsApp-Client (APK) recognizes the message tag and does not sent the āsameā message again.
Now the seed is changed at package initialization and it should works as expected.
Thanks for the quick reply! Unforntunately this doesn't seem to have solved the issue. From what I can see in the console the ID is still the same, and I also still can't send multiple messages. The output in the console is:
[] 1 discarded msg: D1E2C64981855AD8681D,
[] 1 discarded msg: D1E2C64981855AD8681D,{"status":200,"t":1530115677}
[] 1 discarded msg: s7,["Msg",{"cmd":"ack","id":"D1E2C64981855AD8681D","ack":2,"from":"sender@c.us","to":"receiver@c.us","t":1530115677}]
I assume in this case D1E2C64981855AD8681D
is the ID?
I believe the ID doesn't matter as long as it isn't empty right? So could you point me to where I can manually set it so I can fiddle around with it?
EDIT: I'm new to golang and I couldn't figure out how to use the go get command, so I just cloned the repo. Could this cause the new init method that changes the randomizer seed to not trigger?
You can set the message ID by setting it in the MessageInfo struct inside the TextMessage. But it's weird that the setting of the seed did not solve the issue. For me and some very basic testing it solved the problem. Changing the seed to the local time should ensure that no IDs can appear multiple times.
The ID gets generated in the message.go if no ID is set or it is shorter than 2. Be careful: sending a message with an empty ID will crash your WhatsApp permanently and you have to delete all app data.
I'm not used to Go so please excuse me if I'm making a rookie mistake, but the method that sets the new Id doesn't seem to be called? For debugging I imported fmt in message.go and changed the code to:
fmt.Printf("Current Id: ", info.Id)
if info.Id == "" || len(info.Id) < 2 {
fmt.Printf("Id is too short")
b := make([]byte, 10)
rand.Read(b)
info.Id = strings.ToUpper(hex.EncodeToString(b))
}
fmt.Printf("New Id: ", info.Id)
However none of these messages appear in the console. Also since no attempt to change the Id so far seems to work I've decided to just use empty Id's. If it works it should now be pretty easy to spot, and I'm using throwaway accounts anyway to avoid getting banned.
If I set a breakpoint at the if-statement(ln. 35-39), I can see that the code block gets called every time. I am not specifying any IDĀ“s in my code manually. I cannot reproduce the issue any more after the latest fix. Can you show me/us your code interacting with our package?
All I have changed is removing the comment signs in main.go to send the message, and what I posted above in whatsapp/message.go. Could you show me exactly which line I'd need to edit to set the ID?
Like I said before, could this be caused by me using git clone instead of go get? Also I'm not sure how to print messages to the console on Go so I just copied something I saw you were using.
Retrieving the package by git clone should not change anything. You just have to resolve the dependencies manually. Did you pull the latest commit? Change your test code to:
fmt.Printf("Current Id: %v\n", info.Id)
status := proto.WebMessageInfo_STATUS(1)
if info.Id == "" || len(info.Id) < 2 {
b := make([]byte, 10)
rand.Read(b)
info.Id = strings.ToUpper(hex.EncodeToString(b))
}
fmt.Printf("New Id: %v\n", info.Id)
See godoc for more information on how to use fmt.Printf
I still don't see anything getting printed to the console and I can also still only send 1 message
Without further information we cantĀ“t help you. Ensure that you pulled from the repo or clone it again.
BTW: You should be able to set a custom id for every message. As @SchulteMK mentioned, we can't reproduce the issue, so maybe this helps you out.
text := whatsapp.TextMessage{
Info: whatsapp.MessageInfo{
Id: "id",
RemoteJid: "jid@s.whatsapp.net",
},
Text: "text",
}
err = wac.Send(text)
I've seen in another repo that figured out sending messages, presumably through this wrapper? And am wondering when that code will be available.
It doesn't need to be very polished I would just like to see how you implemented it.