Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/api/dto/sendMessage.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class Options {
mentionsEveryOne?: boolean;
mentioned?: string[];
webhookUrl?: string;
messageId?: string;
}

export class MediaMessage {
Expand Down Expand Up @@ -45,6 +46,7 @@ export class Metadata {
mentioned?: string[];
encoding?: boolean;
notConvertSticker?: boolean;
messageId?: string;
}

export class SendTextDto extends Metadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export class EvolutionStartupService extends ChannelStartupService {

let audioFile;

const messageId = v4();
const messageId = options?.messageId || v4();

let messageRaw: any;

Expand Down Expand Up @@ -548,6 +548,7 @@ export class EvolutionStartupService extends ChannelStartupService {
linkPreview: data?.linkPreview,
mentionsEveryOne: data?.mentionsEveryOne,
mentioned: data?.mentioned,
messageId: data?.messageId,
},
null,
isIntegration,
Expand Down Expand Up @@ -613,6 +614,7 @@ export class EvolutionStartupService extends ChannelStartupService {
linkPreview: data?.linkPreview,
mentionsEveryOne: data?.mentionsEveryOne,
mentioned: data?.mentioned,
messageId: data?.messageId,
},
file,
isIntegration,
Expand Down Expand Up @@ -711,6 +713,7 @@ export class EvolutionStartupService extends ChannelStartupService {
linkPreview: data?.linkPreview,
mentionsEveryOne: data?.mentionsEveryOne,
mentioned: data?.mentioned,
messageId: data?.messageId,
},
file,
isIntegration,
Expand All @@ -736,6 +739,7 @@ export class EvolutionStartupService extends ChannelStartupService {
quoted: data?.quoted,
mentionsEveryOne: data?.mentionsEveryOne,
mentioned: data?.mentioned,
messageId: data?.messageId,
},
null,
isIntegration,
Expand Down
6 changes: 6 additions & 0 deletions src/api/integrations/channel/whatsapp/baileys.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export class BaileysController {
return instance.baileysOnWhatsapp(body?.jid);
}

public async generateMessageID({ instanceName }: InstanceDto) {
const instance = this.waMonitor.waInstances[instanceName];

return instance.generateMessageID();
}

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

Expand Down
10 changes: 10 additions & 0 deletions src/api/integrations/channel/whatsapp/baileys.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ export class BaileysRouter extends RouterBroker {

res.status(HttpStatus.OK).json(response);
})
.get(this.routerPath('generateMessageID'), ...guards, async (req, res) => {
const response = await this.dataValidate<InstanceDto>({
request: req,
schema: instanceSchema,
ClassRef: InstanceDto,
execute: (instance) => baileysController.generateMessageID(instance),
});

res.status(HttpStatus.OK).json(response);
})
.post(this.routerPath('profilePictureUrl'), ...guards, async (req, res) => {
const response = await this.dataValidate<InstanceDto>({
request: req,
Expand Down
18 changes: 16 additions & 2 deletions src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCollectionsDto } from '@api/dto/business.dto';

Check failure on line 1 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Run autofix to sort these imports!
import { OfferCallDto } from '@api/dto/call.dto';
import {
ArchiveChatDto,
Expand Down Expand Up @@ -128,8 +128,9 @@
WAMessageKey,
WAPresence,
WASocket,
generateMessageIDV2
} from 'baileys';
import { Label } from 'baileys/lib/Types/Label';

Check failure on line 133 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Insert `,`
import { LabelAssociation } from 'baileys/lib/Types/LabelAssociation';
import { spawn } from 'child_process';
import { isArray, isBase64, isURL } from 'class-validator';
Expand Down Expand Up @@ -1979,6 +1980,13 @@
}
}

private async generateMessageID() {

return {
id: generateMessageIDV2(this.client.user?.id)
};
}

private async sendMessage(
sender: string,
message: any,
Expand Down Expand Up @@ -2215,9 +2223,9 @@
const cache = this.configService.get<CacheConf>('CACHE');
if (!cache.REDIS.ENABLED && !cache.LOCAL.ENABLED) group = await this.findGroup({ groupJid: sender }, 'inner');
else group = await this.getGroupMetadataCache(sender);
// group = await this.findGroup({ groupJid: sender }, 'inner');

Check failure on line 2226 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Delete `⏎`
} catch {
throw new NotFoundException('Group not found');

Check failure on line 2228 in src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

View workflow job for this annotation

GitHub Actions / check-lint-and-build

Insert `,`
}

if (!group) {
Expand All @@ -2242,7 +2250,7 @@
mentions,
linkPreview,
quoted,
null,
options.messageId,
group?.ephemeralDuration,
// group?.participants,
);
Expand All @@ -2264,7 +2272,7 @@
mentions,
linkPreview,
quoted,
null,
options.messageId,
undefined,
contextInfo,
);
Expand Down Expand Up @@ -2490,6 +2498,7 @@
linkPreview: data?.linkPreview,
mentionsEveryOne: data?.mentionsEveryOne,
mentioned: data?.mentioned,
messageId: data?.messageId,
},
isIntegration,
);
Expand All @@ -2506,6 +2515,7 @@
linkPreview: data?.linkPreview,
mentionsEveryOne: data?.mentionsEveryOne,
mentioned: data?.mentioned,
messageId: data?.messageId,
},
);
}
Expand Down Expand Up @@ -2819,6 +2829,7 @@
quoted: data?.quoted,
mentionsEveryOne: data?.mentionsEveryOne,
mentioned: data?.mentioned,
messageId: data?.messageId,
},
);

Expand All @@ -2841,6 +2852,7 @@
quoted: data?.quoted,
mentionsEveryOne: data?.mentionsEveryOne,
mentioned: data?.mentioned,
messageId: data?.messageId,
},
isIntegration,
);
Expand All @@ -2857,6 +2869,7 @@
quoted: data?.quoted,
mentionsEveryOne: data?.mentionsEveryOne,
mentioned: data?.mentioned,
messageId: data?.messageId,
};

if (file) mediaData.media = file.buffer.toString('base64');
Expand All @@ -2872,6 +2885,7 @@
quoted: data?.quoted,
mentionsEveryOne: data?.mentionsEveryOne,
mentioned: data?.mentioned,
messageId: data?.messageId,
},
isIntegration,
);
Expand Down
Loading