-
-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/mark online configurable #43
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| -- Allow processing messages from self and from groups (opt-in, default off) | ||
| ALTER TABLE whatsapp_connections ADD COLUMN process_from_self INTEGER DEFAULT 0 NOT NULL; | ||
| ALTER TABLE whatsapp_connections ADD COLUMN process_groups INTEGER DEFAULT 0 NOT NULL; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- Configurable: mark linked session as online on connect (default off so phone keeps notifications) | ||
| ALTER TABLE whatsapp_connections ADD COLUMN mark_online_on_connect INTEGER DEFAULT 0 NOT NULL; |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -97,13 +97,18 @@ class WhatsAppClientService { | |||||||
| const { state, saveCreds } = await useMultiFileAuthState(env.WHATSAPP_SESSION_PATH); | ||||||||
| this.saveCreds = saveCreds; | ||||||||
|
|
||||||||
| // Read connection options (markOnlineOnConnect etc.) from DB; default false so phone keeps notifications | ||||||||
| const connections = await whatsappConnectionRepository.findAll(); | ||||||||
| const markOnlineOnConnect = connections[0]?.markOnlineOnConnect ?? false; | ||||||||
|
|
||||||||
| // Create Baileys socket | ||||||||
| this.sock = makeWASocket({ | ||||||||
| auth: state, | ||||||||
| printQRInTerminal: false, // We'll handle QR code ourselves via WebSocket | ||||||||
| browser: ['WAMR', 'Chrome', '1.0.0'], | ||||||||
| syncFullHistory: false, | ||||||||
| markOnlineOnConnect: true, | ||||||||
| // When false, linked session does not mark as online; phone keeps notifications and unread badges | ||||||||
| markOnlineOnConnect, | ||||||||
| // Disable auto-retry to handle reconnection manually | ||||||||
| retryRequestDelayMs: 2000, | ||||||||
| }); | ||||||||
|
|
@@ -299,19 +304,23 @@ class WhatsAppClientService { | |||||||
| // Message received event | ||||||||
| this.sock.ev.on('messages.upsert', async (event) => { | ||||||||
| try { | ||||||||
| for (const message of event.messages) { | ||||||||
| // Skip messages from self | ||||||||
| if (message.key.fromMe) continue; | ||||||||
| const connections = await whatsappConnectionRepository.findAll(); | ||||||||
| const conn = connections[0]; | ||||||||
| const processFromSelf = conn?.processFromSelf ?? false; | ||||||||
| const processGroups = conn?.processGroups ?? false; | ||||||||
|
|
||||||||
| // Skip group messages - only process individual chats | ||||||||
| for (const message of event.messages) { | ||||||||
| const remoteJid = message.key.remoteJid; | ||||||||
| if (!remoteJid || remoteJid.endsWith('@g.us') || remoteJid === 'status@broadcast') { | ||||||||
| continue; | ||||||||
| } | ||||||||
| const fromMe = message.key.fromMe; | ||||||||
| const isGroup = remoteJid?.endsWith('@g.us') ?? false; | ||||||||
| const isBroadcast = remoteJid === 'status@broadcast'; | ||||||||
|
|
||||||||
| if (fromMe && !processFromSelf) continue; | ||||||||
| if ((isGroup || isBroadcast) && !processGroups) continue; | ||||||||
|
||||||||
| if ((isGroup || isBroadcast) && !processGroups) continue; | |
| if (isBroadcast) continue; | |
| if (isGroup && !processGroups) continue; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -286,6 +286,8 @@ describe('WhatsApp Controller', () => { | |
| id: 1, | ||
| filterType: 'contains', | ||
| filterValue: 'movie', | ||
| processFromSelf: false, | ||
| processGroups: false, | ||
| }; | ||
|
|
||
| (messageFilterSchema.safeParse as Mock).mockReturnValue({ | ||
|
|
@@ -301,17 +303,20 @@ describe('WhatsApp Controller', () => { | |
| expect(messageFilterSchema.safeParse).toHaveBeenCalledWith(filterData); | ||
| expect(whatsappConnectionRepository.updateMessageFilter).toHaveBeenCalledWith( | ||
| 'contains', | ||
| 'movie' | ||
| 'movie', | ||
| {} | ||
| ); | ||
| expect(logger.info).toHaveBeenCalledWith( | ||
| { filterType: 'contains', filterValue: 'movie' }, | ||
| { filterType: 'contains', filterValue: 'movie', processFromSelf: undefined, processGroups: undefined }, | ||
| 'Message filter updated' | ||
| ); | ||
| expect(mockResponse.json).toHaveBeenCalledWith({ | ||
| success: true, | ||
| message: 'Message filter updated successfully', | ||
| filterType: 'contains', | ||
| filterValue: 'movie', | ||
| processFromSelf: false, | ||
| processGroups: false, | ||
| }); | ||
|
Comment on lines
+318
to
320
|
||
| }); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
markOnlineOnConnectfield is missing from the export data. WhileprocessFromSelfandprocessGroupsare included in lines 225-226, themarkOnlineOnConnectfield should also be exported for data consistency.