Giter VIP home page Giter VIP logo

Comments (6)

nuwaida avatar nuwaida commented on June 10, 2024 1

Hi,
As I said without calling contacts() I do not get anything.
When I call contacts() I see the printouts from your package, and it panics few times (I have panic recovery) while printing the contacts, and before each panic I see this print out (with broadcast):


**{user map[jid:status@broadcast] <nil>}**
echo: http: panic serving [::1]:51429: runtime error: slice bounds out of range
goroutine 712 [running]:
net/http.(*conn).serve.func1(0xc042207540)
   C:/Go/src/net/http/server.go:1726 +0xd7
panic(0x8f0240, 0xc5a950)
   C:/Go/src/runtime/panic.go:502 +0x237
github.com/Rhymen/go-whatsapp.(*Conn).decryptBinaryMessage(0xc0421de1c0, 0xc8ab78, 0x0, 0x0, 0x0, 0x0, 0x800a)
   C:/workspaces/src/github.com/Rhymen/go-whatsapp/conn.go:246 +0x3d2
github.com/Rhymen/go-whatsapp.(*Conn).query(0xc0421de1c0, 0x98a5fa, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
   C:/workspaces/src/github.com/Rhymen/go-whatsapp/contact.go:155 +0x40c
github.com/Rhymen/go-whatsapp.(*Conn).Contacts(0xc0421de1c0, 0x0, 0x0, 0xc8ab78)
   C:/workspaces/src/github.com/Rhymen/go-whatsapp/contact.go:103 +0x7d

I was able to fix this issue when I added this code, I'm not sure this is the correct fix:

func (wac *Conn) decryptBinaryMessage(msg []byte) (*binary.Node, error) {
	//message validation
        //---------------- MY CODE STARTS HERE
	if len(msg) == 0 {
		fmt.Println("Got empty msg to decrypt [%s]", msg)
		return nil, nil
	}
        //---------------- MY CODE FINISH HERE
	h2 := hmac.New(sha256.New, wac.session.MacKey)
	h2.Write([]byte(msg[32:])) 
....

from go-whatsapp.

jhow2892 avatar jhow2892 commented on June 10, 2024

Hi, I try to download the latest version and reinstall it, I am able to normally extract the user name through Contact with the following command wac.Store.Contacts [message.Info.RemoteJid] .Notify

from go-whatsapp.

Rhymen avatar Rhymen commented on June 10, 2024

I tried to debug it aswell, but I couldn't reproduce the error. As @jhow2892 mentioned, you can get the contact by looking into wac.Store.Contacts[jid]. The wac.Contacts() function is used to update the local store with the values from your phone. You don't need to do this when you start your program, because whatsapp syncs the contacts once after every login.

What does the wac.Contacts() func respond for you? Watch out to not expose any phone numbers or names. As for me it responds with {response map[type:contacts duplicate:true] <nil>}.

from go-whatsapp.

nuwaida avatar nuwaida commented on June 10, 2024

Hi,
Thanks guys for the quick response.
I'm looking to get all contacts, not only one by jid.
When I call wac.Contacts() from last week the code, I used to get this result {response map[type:contacts duplicate:true] }, but since I update to the new code, that stores the contact is wac.Store and I call wac.Contacts() I get the above panic.
I tried your suggestion, and now I'm not calling wac.Contacts(), I do login, I get a session with no errors, few seconds later I print out the wac.Store.Contacts, and I get empty map.
Here is my code: is there anything I'm doing wrong:


func (ws *waSession) GetContacts() (waContacts []WaContact, err error) {
	waContacts = make([]WaContact, 0)
	//_, err = ws.wac.Contacts()
	//if err != nil {
	//	return waContacts, fmt.Errorf("error loading contacts %s", err)
	//}

	contacts := ws.wac.Store.Contacts
	for key, contact := range contacts {
		fmt.Printf("contact (%s): %#v\n", key, contact)
		waContacts = append(waContacts, WaContact{
			Name: contact.Name,
			Phone: key,
			ShortName: contact.Short,
		})
	}
	return waContacts,nil
}

from go-whatsapp.

SchulteMK avatar SchulteMK commented on June 10, 2024

The stacktrace obove shows that the error got invoked in

C:/workspaces/src/github.com/Rhymen/go-whatsapp/contact.go:103 +0x7d

This line contains the wac.writeBinary(...) call inside the Presence(...) function. I don´t know why it fails, but this function call does not correspond to your described error for calling Contacts(). Maybe comment out the call of Presence(...) for testing purposes.

from go-whatsapp.

Rhymen avatar Rhymen commented on June 10, 2024

Fixed in 955ab6f

from go-whatsapp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.