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

feat: example of multiple sessions #471

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mateusfmello
Copy link

In order to facilitate the initiation of new WhatsMeow users, I am adding another example that demonstrates the use of the project with multiple sessions.

@apoorvcodes
Copy link

hey is there any way to use our own db something like mongodb for sessions ?

@mateusfmello
Copy link
Author

hey is there any way to use our own db something like mongodb for sessions ?

As far as I know, it only supports PostgreSQL, I don't see any point in using a non-relational database in this project.

@huzairuje
Copy link

hey is there any way to use our own db something like mongodb for sessions ?

As far as I know, it only supports PostgreSQL, I don't see any point in using a non-relational database in this project.

can we use slice or in-memory golang instead ? and implement an interface for it ?

@mateusfmello
Copy link
Author

can we use slice or in-memory golang instead ? and implement an interface for it ?

I believe it is possible, @tulir can help you better with this issue, as I have never implemented anything like this with Whatsmeow.

@huzairuje
Copy link

can we use slice or in-memory golang instead ? and implement an interface for it ?

I believe it is possible, @tulir can help you better with this issue, as I have never implemented anything like this with Whatsmeow.

yes i haseen the code on when do pair success it will call container.Save() and the function Save() is only implement the sqlstore method, i think we can implement another interface on memory slice type.

@mateusfmello
Copy link
Author

can we use slice or in-memory golang instead ? and implement an interface for it ?

I believe it is possible, @tulir can help you better with this issue, as I have never implemented anything like this with Whatsmeow.

yes i haseen the code on when do pair success it will call container.Save() and the function Save() is only implement the sqlstore method, i think we can implement another interface on memory slice type.

Do you know that you can use PostgreSQL and SQLite in memory?
If your intention is to have the persistence layer in memory you can use one of the two in memory, I believe it is the fastest and simplest way to achieve this goal.

@Manjit2003
Copy link

Manjit2003 commented Apr 8, 2024 via email

@lairhas
Copy link

lairhas commented May 5, 2024

Hello @mateusfmello, thank you. I've applied your method and managed to run a variable number of devices using a single binary.

Is there a method to determine which device an event is originating from?

@mateusfmello
Copy link
Author

Hello @mateusfmello, thank you. I've applied your method and managed to run a variable number of devices using a single binary.

Is there a method to determine which device an event is originating from?

From what I remember, within the messages comes the JID (WhatsApp ID) of the device, if you don't have it when making the connection and informing the handlers, pass the JID as a parameter to the handler methods that need to know which device the event came from / message.

But I believe that the messages / events have the JID of the recipient / device, I'm just not sure at the moment.

@lairhas
Copy link

lairhas commented May 8, 2024

Hello @mateusfmello, thank you. I've applied your method and managed to run a variable number of devices using a single binary.
Is there a method to determine which device an event is originating from?

From what I remember, within the messages comes the JID (WhatsApp ID) of the device, if you don't have it when making the connection and informing the handlers, pass the JID as a parameter to the handler methods that need to know which device the event came from / message.

But I believe that the messages / events have the JID of the recipient / device, I'm just not sure at the moment.

I have read more and found this on client.go:

// If you want to access the Client instance inside the event handler, the recommended way is to
// wrap the whole handler in another struct:

	type MyClient struct {
		WAClient *whatsmeow.Client
		eventHandlerID uint32
	}

	func (mycli *MyClient) register() {
		mycli.eventHandlerID = mycli.WAClient.AddEventHandler(mycli.myEventHandler)
	}

	func (mycli *MyClient) myEventHandler(evt interface{}) {
		// Handle event and access mycli.WAClient
        }

I modified the wrapper a little for my needs and solved my multi sessions problem with it.

@hrizal
Copy link

hrizal commented May 8, 2024 via email

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

Successfully merging this pull request may close these issues.

None yet

6 participants