Skip to content

Commit

Permalink
Fix prettier errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jesus-chacon committed Jan 7, 2025
1 parent 2816a16 commit 0f2498b
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 37 deletions.
5 changes: 4 additions & 1 deletion src/api/controllers/proxy.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import axios from 'axios';
const logger = new Logger('ProxyController');

export class ProxyController {
constructor(private readonly proxyService: ProxyService, private readonly waMonitor: WAMonitoringService) {}
constructor(
private readonly proxyService: ProxyService,
private readonly waMonitor: WAMonitoringService,
) {}

public async createProxy(instance: InstanceDto, data: ProxyDto) {
if (!this.waMonitor.waInstances[instance.instanceName]) {
Expand Down
9 changes: 8 additions & 1 deletion src/api/dto/instance.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ export class InstanceDto extends IntegrationDto {
proxyProtocol?: string;
proxyUsername?: string;
proxyPassword?: string;
webhook?: { enabled?: boolean; events?: string[]; headers?: JsonValue; url?: string; byEvents?: boolean; base64?: boolean; };
webhook?: {
enabled?: boolean;
events?: string[];
headers?: { [key: string]: string };
url?: string;
byEvents?: boolean;
base64?: boolean;
};
chatwootAccountId?: string;
chatwootConversationPending?: boolean;
chatwootAutoCreate?: boolean;
Expand Down
31 changes: 17 additions & 14 deletions src/api/integrations/channel/meta/whatsapp.business.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,17 @@ export class BusinessStartupService extends ChannelStartupService {

const buffer = await axios.get(result.data.url, { headers, responseType: 'arraybuffer' });

const mediaType = message.messages[0].document
? 'document'
: message.messages[0].image
? 'image'
: message.messages[0].audio
? 'audio'
: 'video';
let mediaType;

if (message.messages[0].document) {
mediaType = 'document';
} else if (message.messages[0].image) {
mediaType = 'image';
} else if (message.messages[0].audio) {
mediaType = 'audio';
} else {
mediaType = 'video';
}

const mimetype = result.data?.mime_type || result.headers['content-type'];

Expand Down Expand Up @@ -797,7 +801,7 @@ export class BusinessStartupService extends ChannelStartupService {
}
if (message['media']) {
const isImage = message['mimetype']?.startsWith('image/');

content = {
messaging_product: 'whatsapp',
recipient_type: 'individual',
Expand All @@ -812,7 +816,7 @@ export class BusinessStartupService extends ChannelStartupService {
};
quoted ? (content.context = { message_id: quoted.id }) : content;
return await this.post(content, 'messages');
}
}
if (message['audio']) {
content = {
messaging_product: 'whatsapp',
Expand Down Expand Up @@ -1100,11 +1104,10 @@ export class BusinessStartupService extends ChannelStartupService {

if (file?.buffer) {
mediaData.audio = file.buffer.toString('base64');
}
else if(isURL(mediaData.audio)){
mediaData.audio = mediaData.audio
}
else {
} else if (isURL(mediaData.audio)) {
// DO NOTHING
// mediaData.audio = mediaData.audio;
} else {
console.error('El archivo no tiene buffer o file es undefined');
throw new Error('File or buffer is undefined');
}
Expand Down
5 changes: 4 additions & 1 deletion src/api/integrations/event/webhook/webhook.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { instanceSchema, webhookSchema } from '@validate/validate.schema';
import { RequestHandler, Router } from 'express';

export class WebhookRouter extends RouterBroker {
constructor(readonly configService: ConfigService, ...guards: RequestHandler[]) {
constructor(
readonly configService: ConfigService,
...guards: RequestHandler[]
) {
super();
this.router
.post(this.routerPath('set'), ...guards, async (req, res) => {
Expand Down
5 changes: 4 additions & 1 deletion src/api/routes/instance.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { RequestHandler, Router } from 'express';
import { HttpStatus } from './index.router';

export class InstanceRouter extends RouterBroker {
constructor(readonly configService: ConfigService, ...guards: RequestHandler[]) {
constructor(
readonly configService: ConfigService,
...guards: RequestHandler[]
) {
super();
this.router
.post('/create', ...guards, async (req, res) => {
Expand Down
5 changes: 4 additions & 1 deletion src/api/routes/template.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { RequestHandler, Router } from 'express';
import { HttpStatus } from './index.router';

export class TemplateRouter extends RouterBroker {
constructor(readonly configService: ConfigService, ...guards: RequestHandler[]) {
constructor(
readonly configService: ConfigService,
...guards: RequestHandler[]
) {
super();
this.router
.post(this.routerPath('create'), ...guards, async (req, res) => {
Expand Down
29 changes: 16 additions & 13 deletions src/api/services/monitor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@ export class WAMonitoringService {
public delInstanceTime(instance: string) {
const time = this.configService.get<DelInstance>('DEL_INSTANCE');
if (typeof time === 'number' && time > 0) {
setTimeout(async () => {
if (this.waInstances[instance]?.connectionStatus?.state !== 'open') {
if (this.waInstances[instance]?.connectionStatus?.state === 'connecting') {
if ((await this.waInstances[instance].integration) === Integration.WHATSAPP_BAILEYS) {
await this.waInstances[instance]?.client?.logout('Log out instance: ' + instance);
this.waInstances[instance]?.client?.ws?.close();
this.waInstances[instance]?.client?.end(undefined);
setTimeout(
async () => {
if (this.waInstances[instance]?.connectionStatus?.state !== 'open') {
if (this.waInstances[instance]?.connectionStatus?.state === 'connecting') {
if ((await this.waInstances[instance].integration) === Integration.WHATSAPP_BAILEYS) {
await this.waInstances[instance]?.client?.logout('Log out instance: ' + instance);
this.waInstances[instance]?.client?.ws?.close();
this.waInstances[instance]?.client?.end(undefined);
}
this.eventEmitter.emit('remove.instance', instance, 'inner');
} else {
this.eventEmitter.emit('remove.instance', instance, 'inner');
}
this.eventEmitter.emit('remove.instance', instance, 'inner');
} else {
this.eventEmitter.emit('remove.instance', instance, 'inner');
}
}
}, 1000 * 60 * time);
},
1000 * 60 * time,
);
}
}

Expand Down Expand Up @@ -219,7 +222,7 @@ export class WAMonitoringService {
id: data.instanceId,
name: data.instanceName,
connectionStatus:
data.integration && data.integration === Integration.WHATSAPP_BAILEYS ? 'close' : data.status ?? 'open',
data.integration && data.integration === Integration.WHATSAPP_BAILEYS ? 'close' : (data.status ?? 'open'),
number: data.number,
integration: data.integration || Integration.WHATSAPP_BAILEYS,
token: data.hash,
Expand Down
5 changes: 4 additions & 1 deletion src/cache/cacheengine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const logger = new Logger('CacheEngine');
export class CacheEngine {
private engine: ICache;

constructor(private readonly configService: ConfigService, module: string) {
constructor(
private readonly configService: ConfigService,
module: string,
) {
const cacheConf = configService.get<CacheConf>('CACHE');

if (cacheConf?.REDIS?.ENABLED && cacheConf?.REDIS?.URI !== '') {
Expand Down
5 changes: 4 additions & 1 deletion src/cache/localcache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export class LocalCache implements ICache {
private conf: CacheConfLocal;
static localCache = new NodeCache();

constructor(private readonly configService: ConfigService, private readonly module: string) {
constructor(
private readonly configService: ConfigService,
private readonly module: string,
) {
this.conf = this.configService.get<CacheConf>('CACHE')?.LOCAL;
}

Expand Down
5 changes: 4 additions & 1 deletion src/cache/rediscache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export class RedisCache implements ICache {
private client: RedisClientType;
private conf: CacheConfRedis;

constructor(private readonly configService: ConfigService, private readonly module: string) {
constructor(
private readonly configService: ConfigService,
private readonly module: string,
) {
this.conf = this.configService.get<CacheConf>('CACHE')?.REDIS;
this.client = redisClient.getConnection();
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/getConversationMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const getTypeMessage = (msg: any) => {
audioMessage: msg?.message?.speechToText
? msg?.message?.speechToText
: msg?.message?.audioMessage
? `audioMessage|${mediaId}`
: undefined,
? `audioMessage|${mediaId}`
: undefined,
imageMessage: msg?.message?.imageMessage
? `imageMessage|${mediaId}${msg?.message?.imageMessage?.caption ? `|${msg?.message?.imageMessage?.caption}` : ''}`
: undefined,
Expand Down

0 comments on commit 0f2498b

Please sign in to comment.