Skip to content

Commit

Permalink
fix: instances
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidsonGomes committed Jun 10, 2024
1 parent 4879bdb commit 28e5b2f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Instance" ADD COLUMN "profileName" VARCHAR(100);
1 change: 1 addition & 0 deletions prisma/mysql-schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ model Instance {
name String @unique @db.VarChar(255)
connectionStatus InstanceConnectionStatus @default(open)
ownerJid String? @db.VarChar(100)
profileName String? @db.VarChar(100)
profilePicUrl String? @db.VarChar(500)
integration String? @db.VarChar(100)
number String? @db.VarChar(100)
Expand Down
1 change: 1 addition & 0 deletions prisma/postgresql-schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ model Instance {
name String @unique @db.VarChar(255)
connectionStatus InstanceConnectionStatus @default(open)
ownerJid String? @db.VarChar(100)
profileName String? @db.VarChar(100)
profilePicUrl String? @db.VarChar(500)
integration String? @db.VarChar(100)
number String? @db.VarChar(100)
Expand Down
6 changes: 3 additions & 3 deletions src/api/controllers/instance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ export class InstanceController {
const env = this.configService.get<Auth>('AUTHENTICATION').API_KEY;

let name = instanceName;
let arrayReturn = false;
// let arrayReturn = false;

if (env.KEY !== key) {
const instanceByKey = await this.prismaRepository.instance.findUnique({
Expand All @@ -521,14 +521,14 @@ export class InstanceController {

if (instanceByKey) {
name = instanceByKey.name;
arrayReturn = true;
// arrayReturn = true;
} else {
throw new UnauthorizedException();
}
}

if (name) {
return this.waMonitor.instanceInfo(name, arrayReturn);
return this.waMonitor.instanceInfo(name);
} else if (instanceId || number) {
return this.waMonitor.instanceInfoById(instanceId, number);
}
Expand Down
10 changes: 6 additions & 4 deletions src/api/services/channels/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ffmpegPath from '@ffmpeg-installer/ffmpeg';
import { Boom } from '@hapi/boom';
import { Instance } from '@prisma/client';
import makeWASocket, {
AnyMessageContent,
BufferedEventData,
Expand Down Expand Up @@ -419,6 +420,7 @@ export class BaileysStartupService extends ChannelStartupService {
where: { id: this.instanceId },
data: {
ownerJid: this.instance.wuid,
profileName: (await this.getProfileName()) as string,
profilePicUrl: this.instance.profilePictureUrl,
connectionStatus: 'open',
},
Expand Down Expand Up @@ -1650,15 +1652,15 @@ export class BaileysStartupService extends ChannelStartupService {
website: business?.website?.shift(),
};
} else {
const info = await waMonitor.instanceInfo(instanceName);
const info: Instance = await waMonitor.instanceInfo(instanceName);
const business = await this.fetchBusinessProfile(jid);

return {
wuid: jid,
// name: info?.instance?.profileName,
name: info?.profileName,
numberExists: true,
// picture: info?.instance?.profilePictureUrl,
// status: info?.instance?.profileStatus,
picture: info?.profilePicUrl,
status: info?.connectionStatus,
isBusiness: business.isBusiness,
email: business?.email,
description: business?.description,
Expand Down
2 changes: 1 addition & 1 deletion src/api/services/monitor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class WAMonitoringService {
}
}

public async instanceInfo(instanceName?: string, arrayReturn = false) {
public async instanceInfo(instanceName?: string): Promise<any> {
if (instanceName && !this.waInstances[instanceName]) {
throw new NotFoundException(`Instance "${instanceName}" not found`);
}
Expand Down

0 comments on commit 28e5b2f

Please sign in to comment.