Skip to content

Commit c252f5f

Browse files
Merge pull request #20 from EvolutionAPI/revert-18-fetch-profile
Revert "Adição de FetchProfile"
2 parents 69f5cdd + 76d77ad commit c252f5f

File tree

5 files changed

+11
-134
lines changed

5 files changed

+11
-134
lines changed

src/validate/validate.schema.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -587,17 +587,6 @@ export const profilePictureSchema: JSONSchema7 = {
587587
},
588588
};
589589

590-
export const profileSchema: JSONSchema7 = {
591-
type: 'object',
592-
properties: {
593-
wuid: { type: 'string' },
594-
name: { type: 'string' },
595-
picture: { type: 'string' },
596-
status: { type: 'string' },
597-
isBusiness: { type: 'boolean' },
598-
},
599-
};
600-
601590
export const messageValidateSchema: JSONSchema7 = {
602591
$id: v4(),
603592
type: 'object',

src/whatsapp/controllers/chat.controller.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ export class ChatController {
4747
logger.verbose('requested fetchProfilePicture from ' + instanceName + ' instance');
4848
return await this.waMonitor.waInstances[instanceName].profilePicture(data.number);
4949
}
50-
51-
public async fetchProfile({ instanceName }: InstanceDto, data: NumberDto) {
52-
logger.verbose('requested fetchProfile from ' + instanceName + ' instance');
53-
return await this.waMonitor.waInstances[instanceName].fetchProfile(instanceName, data.number);
54-
}
5550

5651
public async fetchContacts({ instanceName }: InstanceDto, query: ContactQuery) {
5752
logger.verbose('requested fetchContacts from ' + instanceName + ' instance');

src/whatsapp/dto/chat.dto.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,6 @@ export class NumberDto {
2626
number: string;
2727
}
2828

29-
export class NumberBusiness {
30-
wid?: string;
31-
jid?: string;
32-
exists?: boolean;
33-
isBusiness: boolean;
34-
name?: string;
35-
message?: string;
36-
description?: string;
37-
email?: string;
38-
website?: string[];
39-
address?: string;
40-
}
41-
4229
export class ProfileNameDto {
4330
name: string;
4431
}

src/whatsapp/routers/chat.router.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
privacySettingsSchema,
99
profileNameSchema,
1010
profilePictureSchema,
11-
profileSchema,
1211
profileStatusSchema,
1312
readMessageSchema,
1413
whatsappNumberSchema,
@@ -130,23 +129,6 @@ export class ChatRouter extends RouterBroker {
130129

131130
return res.status(HttpStatus.OK).json(response);
132131
})
133-
.post(this.routerPath('fetchProfile'), ...guards, async (req, res) => {
134-
logger.verbose('request received in fetchProfile');
135-
logger.verbose('request body: ');
136-
logger.verbose(req.body);
137-
138-
logger.verbose('request query: ');
139-
logger.verbose(req.query);
140-
141-
const response = await this.dataValidate<NumberDto>({
142-
request: req,
143-
schema: profileSchema,
144-
ClassRef: NumberDto,
145-
execute: (instance, data) => chatController.fetchProfile(instance, data),
146-
});
147-
148-
return res.status(HttpStatus.OK).json(response);
149-
})
150132
.post(this.routerPath('findContacts'), ...guards, async (req, res) => {
151133
logger.verbose('request received in findContacts');
152134
logger.verbose('request body: ');

src/whatsapp/services/whatsapp.service.ts

Lines changed: 11 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ import {
8585
ArchiveChatDto,
8686
DeleteMessage,
8787
OnWhatsAppDto,
88-
NumberBusiness,
8988
PrivacySettingDto,
9089
ReadMessageDto,
9190
WhatsAppNumberDto,
@@ -1444,79 +1443,6 @@ export class WAStartupService {
14441443
};
14451444
}
14461445
}
1447-
1448-
public async getStatus(number: string) {
1449-
const jid = this.createJid(number);
1450-
1451-
this.logger.verbose('Getting profile status with jid:' + jid);
1452-
try {
1453-
this.logger.verbose('Getting status');
1454-
return {
1455-
wuid: jid,
1456-
status: (await this.client.fetchStatus(jid))?.status,
1457-
};
1458-
} catch (error) {
1459-
this.logger.verbose('Status not found');
1460-
return {
1461-
wuid: jid,
1462-
status: null,
1463-
};
1464-
}
1465-
}
1466-
1467-
public async fetchProfile(instanceName: string, number?: string) {
1468-
const jid = (number)
1469-
? this.createJid(number)
1470-
: this.client?.user?.id;
1471-
this.logger.verbose('Getting profile with jid: ' + jid);
1472-
try {
1473-
this.logger.verbose('Getting profile info');
1474-
const business = await this.fetchBusinessProfile(jid);
1475-
1476-
if (number) {
1477-
const info = (await this.whatsappNumber({ numbers: [jid] }))?.shift();
1478-
const picture = await this.profilePicture(jid);
1479-
const status = await this.getStatus(jid);
1480-
1481-
return {
1482-
wuid: jid,
1483-
name: info?.name,
1484-
numberExists: info?.exists,
1485-
picture: picture?.profilePictureUrl,
1486-
status: status?.status,
1487-
isBusiness: business.isBusiness,
1488-
email: business?.email,
1489-
description: business?.description,
1490-
website: business?.website?.shift(),
1491-
};
1492-
} else {
1493-
const info = await waMonitor.instanceInfo(instanceName);
1494-
1495-
return {
1496-
wuid: jid,
1497-
name: info?.instance?.profileName,
1498-
numberExists: true,
1499-
picture: info?.instance?.profilePictureUrl,
1500-
status: info?.instance?.profileStatus,
1501-
isBusiness: business.isBusiness,
1502-
email: business?.email,
1503-
description: business?.description,
1504-
website: business?.website?.shift(),
1505-
};
1506-
}
1507-
1508-
} catch (error) {
1509-
this.logger.verbose('Profile not found');
1510-
return {
1511-
wuid: jid,
1512-
name: null,
1513-
picture: null,
1514-
status: null,
1515-
os: null,
1516-
isBusiness: false,
1517-
};
1518-
}
1519-
}
15201446

15211447
private async sendMessageWithTyping<T = proto.IMessage>(
15221448
number: string,
@@ -2534,31 +2460,29 @@ export class WAStartupService {
25342460
}
25352461
}
25362462

2537-
public async fetchBusinessProfile(number: string) : Promise<NumberBusiness> {
2463+
public async fetchBusinessProfile(number: string) {
25382464
this.logger.verbose('Fetching business profile');
25392465
try {
2540-
const jid = (number)
2541-
? this.createJid(number)
2542-
: this.instance.wuid;
2466+
let jid;
2467+
2468+
if (!number) {
2469+
jid = this.instance.wuid;
2470+
} else {
2471+
jid = this.createJid(number);
2472+
}
25432473

25442474
const profile = await this.client.getBusinessProfile(jid);
25452475
this.logger.verbose('Trying to get business profile');
25462476

25472477
if (!profile) {
2548-
const info = await this.whatsappNumber({ numbers: [jid] });
2549-
25502478
return {
2551-
isBusiness: false,
2552-
message: 'Not is business profile',
2553-
...info?.shift()
2479+
exists: false,
2480+
message: 'Business profile not found',
25542481
};
25552482
}
25562483

25572484
this.logger.verbose('Business profile fetched');
2558-
return {
2559-
isBusiness: true,
2560-
...profile
2561-
};
2485+
return profile;
25622486
} catch (error) {
25632487
throw new InternalServerErrorException(
25642488
'Error updating profile name',

0 commit comments

Comments
 (0)