Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
npm run typecheck
npm run build
npm run lint:check
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ RUN chmod +x ./Docker/scripts/* && dos2unix ./Docker/scripts/*

RUN ./Docker/scripts/generate_database.sh

ENV NODE_OPTIONS="--max-old-space-size=4096"
ENV ESBUILD_MAX_THREADS=2

RUN npm run build

RUN NODE_OPTIONS="--max-old-space-size=4096" npm run typecheck
RUN NODE_OPTIONS="--max-old-space-size=4096" npm run build

FROM node:24-bookworm-slim AS final

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "./dist/main.js",
"type": "commonjs",
"scripts": {
"build": "tsc --noEmit && tsup",
"build": "tsup",
"start": "tsx ./src/main.ts",
"start:prod": "node dist/main",
"dev:server": "tsx watch ./src/main.ts",
Expand All @@ -20,7 +20,8 @@
"db:studio": "node runWithProvider.js \"npx prisma studio --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"",
"db:migrate:dev": "node runWithProvider.js \"rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate dev --schema ./prisma/DATABASE_PROVIDER-schema.prisma && cp -r ./prisma/migrations/* ./prisma/DATABASE_PROVIDER-migrations\"",
"db:migrate:dev:win": "node runWithProvider.js \"xcopy /E /I prisma\\DATABASE_PROVIDER-migrations prisma\\migrations && npx prisma migrate dev --schema prisma\\DATABASE_PROVIDER-schema.prisma\"",
"prepare": "husky"
"prepare": "husky",
"typecheck": "tsc --noEmit"
},
"repository": {
"type": "git",
Expand Down
18 changes: 13 additions & 5 deletions src/api/dto/chat.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export class OnWhatsAppDto {
) {}
}

export class LidToJidDto {
lid: string;
}

export class getBase64FromMediaMessageDto {
message: proto.WebMessageInfo;
convertToMp4?: boolean;
Expand Down Expand Up @@ -128,11 +132,15 @@ export class BlockUserDto {
status: 'block' | 'unblock';
}

class DecryptPollVoteMessageKeyDto {
id: string;
}

class DecryptPollVoteMessageDto {
key: DecryptPollVoteMessageKeyDto;
}

export class DecryptPollVoteDto {
message: {
key: {
id: string;
};
};
message: DecryptPollVoteMessageDto;
remoteJid: string;
}
7 changes: 7 additions & 0 deletions src/api/integrations/channel/whatsapp/baileys.controller.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LidToJidDto } from '@api/dto/chat.dto';
import { InstanceDto } from '@api/dto/instance.dto';
import { WAMonitoringService } from '@api/services/monitor.service';

Expand All @@ -10,6 +11,12 @@ export class BaileysController {
return instance.baileysOnWhatsapp(body?.jid);
}

public async lidToJid({ instanceName }: InstanceDto, data: LidToJidDto) {
const instance = this.waMonitor.waInstances[instanceName];

return instance.lidToJid(data?.lid);
}

public async profilePictureUrl({ instanceName }: InstanceDto, body: any) {
const instance = this.waMonitor.waInstances[instanceName];

Expand Down
12 changes: 12 additions & 0 deletions src/api/integrations/channel/whatsapp/baileys.router.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { RouterBroker } from '@api/abstract/abstract.router';
import { LidToJidDto } from '@api/dto/chat.dto';
import { InstanceDto } from '@api/dto/instance.dto';
import { HttpStatus } from '@api/routes/index.router';
import { baileysController } from '@api/server.module';
import { instanceSchema } from '@validate/instance.schema';
import { lidToJidSchema } from '@validate/validate.schema';
import { RequestHandler, Router } from 'express';

export class BaileysRouter extends RouterBroker {
Expand All @@ -19,6 +21,16 @@ export class BaileysRouter extends RouterBroker {

res.status(HttpStatus.OK).json(response);
})
.post(this.routerPath('lidToJid'), ...guards, async (req, res) => {
const response = await this.dataValidate<LidToJidDto>({
request: req,
schema: lidToJidSchema,
ClassRef: LidToJidDto,
execute: (instance, data) => baileysController.lidToJid(instance, data),
});

res.status(HttpStatus.OK).json(response);
})
.post(this.routerPath('profilePictureUrl'), ...guards, async (req, res) => {
const response = await this.dataValidate<InstanceDto>({
request: req,
Expand Down
21 changes: 19 additions & 2 deletions src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,10 @@ export class BaileysStartupService extends ChannelStartupService {

this.logger.verbose(messageRaw);

const msgKey = messageRaw.key as ExtendedIMessageKey & { remoteJidLid?: string };
const msgKey = messageRaw.key as ExtendedIMessageKey & {
remoteJidLid?: string;
originalLid?: string;
};
if (typeof msgKey.remoteJid === 'string' && msgKey.remoteJid.includes('@lid')) {
const originalLid = msgKey.remoteJid;
let normalizedJid: string | null = null;
Expand Down Expand Up @@ -1620,8 +1623,8 @@ export class BaileysStartupService extends ChannelStartupService {
const finalJid = domainPart ? `${cleanNumber}@${domainPart}` : `${cleanNumber}@s.whatsapp.net`;

msgKey.remoteJidLid = originalLid;
msgKey.originalLid = originalLid;
msgKey.remoteJid = finalJid;

if (!msgKey.remoteJidAlt || msgKey.remoteJidAlt.includes('@lid')) {
msgKey.remoteJidAlt = finalJid;
}
Expand Down Expand Up @@ -2357,6 +2360,20 @@ export class BaileysStartupService extends ChannelStartupService {
}
}

public async lidToJid(lid: string): Promise<{ jid: string | null }> {
try {
const jid = await this.client.signalRepository.lidMapping.getPNForLID(lid);

if (typeof jid === 'string' && jid.length > 0) {
return { jid };
}

return { jid: null };
} catch {
return { jid: null };
}
}

public async offerCall({ number, isVideo, callDuration }: OfferCallDto) {
const jid = createJid(number);

Expand Down
15 changes: 15 additions & 0 deletions src/validate/lid.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';

export const lidToJidSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
lid: {
type: 'string',
pattern: '^\\d+@lid$',
description: 'Invalid lid format. Expected: 08392017421739217@lid',
},
},
required: ['lid'],
};
3 changes: 1 addition & 2 deletions src/validate/validate.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ export * from './chat.schema';
export * from './group.schema';
export * from './instance.schema';
export * from './label.schema';
export * from './lid.schema';
export * from './message.schema';
export * from './proxy.schema';
export * from './settings.schema';
export * from './template.schema';
export * from './templateDelete.schema';
export * from './templateEdit.schema';
export * from '@api/integrations/chatbot/chatbot.schema';
export * from '@api/integrations/event/event.schema';
Loading