Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(session): accept @lid JID when marking chats as read (#241)

Suraj Patelbbd0a4a52752
diff --git a/src/modules/session/dto/mark-chat-read.dto.spec.ts b/src/modules/session/dto/mark-chat-read.dto.spec.ts
new file mode 100644
index 000000000..61f8c9322
--- /dev/null
+++ b/src/modules/session/dto/mark-chat-read.dto.spec.ts
@@ -0,0 +1,18 @@
+import { validateSync } from 'class-validator';
+import { plainToInstance } from 'class-transformer';
+import { MarkChatReadDto } from './mark-chat-read.dto';
+
+const errorCount = (chatId: unknown): number => validateSync(plainToInstance(MarkChatReadDto, { chatId })).length;
+
+describe('MarkChatReadDto chatId validation', () => {
+ it.each(['[email protected]', '[email protected]', '1234567890@lid'])('accepts a valid JID: %s', chatId => {
+ expect(errorCount(chatId)).toBe(0);
+ });
+
+ it.each(['', 'not-a-jid', '[email protected]', '[email protected]', '[email protected]'])(
+ 'rejects an invalid chatId: %s',
+ chatId => {
+ expect(errorCount(chatId)).toBeGreaterThan(0);
+ },
+ );
+});
diff --git a/src/modules/session/dto/mark-chat-read.dto.ts b/src/modules/session/dto/mark-chat-read.dto.ts
index e9826a947..2ba021a27 100644
--- a/src/modules/session/dto/mark-chat-read.dto.ts
+++ b/src/modules/session/dto/mark-chat-read.dto.ts
@@ -3,14 +3,15 @@ import { IsNotEmpty, IsString, Matches } from 'class-validator';
export class MarkChatReadDto {
@ApiProperty({
- description: 'WhatsApp chat ID to mark as read (e.g., [email protected] or [email protected])',
+ description: 'WhatsApp chat ID to mark as read (e.g., [email protected], [email protected], or 1234567890@lid)',
example: '[email protected]',
})
@IsString()
@IsNotEmpty()
// Reject malformed IDs early with a clear 400 instead of a silent no-op at the engine layer.
- @Matches(/^[0-9-]+@[cg]\.us$/, {
- message: 'chatId must be a valid WhatsApp JID (e.g. [email protected] or [email protected])',
+ // @lid is the privacy "Linked ID" address newer WhatsApp assigns to some 1:1 contacts.
+ @Matches(/^[0-9-]+@(?:[cg]\.us|lid)$/, {
+ message: 'chatId must be a valid WhatsApp JID (e.g. [email protected], [email protected], or 1234567890@lid)',
})
chatId: string;
}