whatsmeow
whatsmeow copied to clipboard
feat: example of multiple sessions
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.
hey is there any way to use our own db something like mongodb for sessions ?
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.
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 ?
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.
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.
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.
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: @.***>
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?
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.
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.
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: @.***>