Skip to content

Commit b095c9d

Browse files
committed
fix: keyword_finish dont work
1 parent cd00eff commit b095c9d

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

src/whatsapp/services/typebot.service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ export class TypebotService {
613613
if (keyword_finish && content.toLowerCase() === keyword_finish.toLowerCase()) {
614614
const newSessions = await this.clearSessions(instance, remoteJid);
615615

616+
console.log('keyword_finish', newSessions);
616617
const typebotData = {
617618
enabled: findTypebot.enabled,
618619
url: url,
@@ -707,7 +708,7 @@ export class TypebotService {
707708
}
708709

709710
if (keyword_finish && content.toLowerCase() === keyword_finish.toLowerCase()) {
710-
sessions.splice(sessions.indexOf(session), 1);
711+
const newSessions = await this.clearSessions(instance, remoteJid);
711712

712713
const typebotData = {
713714
enabled: findTypebot.enabled,
@@ -718,7 +719,7 @@ export class TypebotService {
718719
delay_message: delay_message,
719720
unknown_message: unknown_message,
720721
listening_from_me: listening_from_me,
721-
sessions,
722+
sessions: newSessions,
722723
};
723724

724725
this.create(instance, typebotData);
@@ -799,7 +800,7 @@ export class TypebotService {
799800
}
800801

801802
if (keyword_finish && content.toLowerCase() === keyword_finish.toLowerCase()) {
802-
sessions.splice(sessions.indexOf(session), 1);
803+
const newSessions = await this.clearSessions(instance, remoteJid);
803804

804805
const typebotData = {
805806
enabled: findTypebot.enabled,
@@ -810,7 +811,7 @@ export class TypebotService {
810811
delay_message: delay_message,
811812
unknown_message: unknown_message,
812813
listening_from_me: listening_from_me,
813-
sessions,
814+
sessions: newSessions,
814815
};
815816

816817
this.create(instance, typebotData);

src/whatsapp/services/whatsapp.service.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,6 +2556,12 @@ export class WAStartupService {
25562556
public async fetchProfile(instanceName: string, number?: string) {
25572557
const jid = number ? this.createJid(number) : this.client?.user?.id;
25582558

2559+
const onWhatsapp = (await this.whatsappNumber({ numbers: [jid] }))?.shift();
2560+
2561+
if (!onWhatsapp.exists) {
2562+
throw new BadRequestException(onWhatsapp);
2563+
}
2564+
25592565
this.logger.verbose('Getting profile with jid: ' + jid);
25602566
try {
25612567
this.logger.verbose('Getting profile info');
@@ -3966,7 +3972,25 @@ export class WAStartupService {
39663972
public async findGroup(id: GroupJid, reply: 'inner' | 'out' = 'out') {
39673973
this.logger.verbose('Fetching group');
39683974
try {
3969-
return await this.client.groupMetadata(id.groupJid);
3975+
const group = await this.client.groupMetadata(id.groupJid);
3976+
3977+
const picture = await this.profilePicture(group.id);
3978+
3979+
return {
3980+
id: group.id,
3981+
subject: group.subject,
3982+
subjectOwner: group.subjectOwner,
3983+
subjectTime: group.subjectTime,
3984+
pictureUrl: picture.profilePictureUrl,
3985+
size: group.participants.length,
3986+
creation: group.creation,
3987+
owner: group.owner,
3988+
desc: group.desc,
3989+
descId: group.descId,
3990+
restrict: group.restrict,
3991+
announce: group.announce,
3992+
participants: group.participants,
3993+
};
39703994
} catch (error) {
39713995
if (reply === 'inner') {
39723996
return;
@@ -3979,13 +4003,16 @@ export class WAStartupService {
39794003
this.logger.verbose('Fetching all groups');
39804004
try {
39814005
const fetch = Object.values(await this.client.groupFetchAllParticipating());
4006+
let groups = [];
4007+
for (const group of fetch) {
4008+
const picture = await this.profilePicture(group.id);
39824009

3983-
const groups = fetch.map((group) => {
39844010
const result = {
39854011
id: group.id,
39864012
subject: group.subject,
39874013
subjectOwner: group.subjectOwner,
39884014
subjectTime: group.subjectTime,
4015+
pictureUrl: picture.profilePictureUrl,
39894016
size: group.participants.length,
39904017
creation: group.creation,
39914018
owner: group.owner,
@@ -3999,8 +4026,8 @@ export class WAStartupService {
39994026
result['participants'] = group.participants;
40004027
}
40014028

4002-
return result;
4003-
});
4029+
groups = [...groups, result];
4030+
}
40044031

40054032
return groups;
40064033
} catch (error) {

0 commit comments

Comments
 (0)