whatsmeow icon indicating copy to clipboard operation
whatsmeow copied to clipboard

feat: example of multiple sessions

Open mateusfmello opened this issue 1 year ago • 13 comments

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.

mateusfmello avatar Oct 02 '23 04:10 mateusfmello

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

apoorvcodes avatar Nov 06 '23 16:11 apoorvcodes

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.

mateusfmello avatar Nov 09 '23 21:11 mateusfmello

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 ?

huzairuje avatar Apr 06 '24 16:04 huzairuje

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.

mateusfmello avatar Apr 06 '24 22:04 mateusfmello

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.

huzairuje avatar Apr 07 '24 14:04 huzairuje

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.

mateusfmello avatar Apr 07 '24 19:04 mateusfmello

Simply pass :memory: in the sqlite driver filename

On Mon, 8 Apr, 2024, 1:27 am Mateus Fernandes de Mello, < @.***> wrote:

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

I believe it is possible, @tulir https://github.com/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.

— Reply to this email directly, view it on GitHub https://github.com/tulir/whatsmeow/pull/471#issuecomment-2041584357, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMHFAGOIXOGOVYYFWYKISDDY4GQL7AVCNFSM6AAAAAA5O3MX5SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGU4DIMZVG4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Manjit2003 avatar Apr 08 '24 00:04 Manjit2003

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?

lairhas avatar May 05 '24 14:05 lairhas

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.

mateusfmello avatar May 07 '24 23:05 mateusfmello

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.

lairhas avatar May 08 '24 08:05 lairhas

Cool, i will try too

Pada Rab, 8 Mei 2024 15.36, lairhas @.***> menulis:

Hello @mateusfmello https://github.com/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.

— Reply to this email directly, view it on GitHub https://github.com/tulir/whatsmeow/pull/471#issuecomment-2100054884, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALJQY2EIU5JUGUV67YW46GLZBHP2HAVCNFSM6AAAAAA5O3MX5SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBQGA2TIOBYGQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

hrizal avatar May 08 '24 13:05 hrizal