fix: keyword_finish dont work

This commit is contained in:
Davidson Gomes 2024-02-16 10:15:31 -03:00
parent cd00effcfe
commit b095c9dfb9
2 changed files with 36 additions and 8 deletions

View File

@ -613,6 +613,7 @@ export class TypebotService {
if (keyword_finish && content.toLowerCase() === keyword_finish.toLowerCase()) {
const newSessions = await this.clearSessions(instance, remoteJid);
console.log('keyword_finish', newSessions);
const typebotData = {
enabled: findTypebot.enabled,
url: url,
@ -707,7 +708,7 @@ export class TypebotService {
}
if (keyword_finish && content.toLowerCase() === keyword_finish.toLowerCase()) {
sessions.splice(sessions.indexOf(session), 1);
const newSessions = await this.clearSessions(instance, remoteJid);
const typebotData = {
enabled: findTypebot.enabled,
@ -718,7 +719,7 @@ export class TypebotService {
delay_message: delay_message,
unknown_message: unknown_message,
listening_from_me: listening_from_me,
sessions,
sessions: newSessions,
};
this.create(instance, typebotData);
@ -799,7 +800,7 @@ export class TypebotService {
}
if (keyword_finish && content.toLowerCase() === keyword_finish.toLowerCase()) {
sessions.splice(sessions.indexOf(session), 1);
const newSessions = await this.clearSessions(instance, remoteJid);
const typebotData = {
enabled: findTypebot.enabled,
@ -810,7 +811,7 @@ export class TypebotService {
delay_message: delay_message,
unknown_message: unknown_message,
listening_from_me: listening_from_me,
sessions,
sessions: newSessions,
};
this.create(instance, typebotData);

View File

@ -2556,6 +2556,12 @@ export class WAStartupService {
public async fetchProfile(instanceName: string, number?: string) {
const jid = number ? this.createJid(number) : this.client?.user?.id;
const onWhatsapp = (await this.whatsappNumber({ numbers: [jid] }))?.shift();
if (!onWhatsapp.exists) {
throw new BadRequestException(onWhatsapp);
}
this.logger.verbose('Getting profile with jid: ' + jid);
try {
this.logger.verbose('Getting profile info');
@ -3966,7 +3972,25 @@ export class WAStartupService {
public async findGroup(id: GroupJid, reply: 'inner' | 'out' = 'out') {
this.logger.verbose('Fetching group');
try {
return await this.client.groupMetadata(id.groupJid);
const group = await this.client.groupMetadata(id.groupJid);
const picture = await this.profilePicture(group.id);
return {
id: group.id,
subject: group.subject,
subjectOwner: group.subjectOwner,
subjectTime: group.subjectTime,
pictureUrl: picture.profilePictureUrl,
size: group.participants.length,
creation: group.creation,
owner: group.owner,
desc: group.desc,
descId: group.descId,
restrict: group.restrict,
announce: group.announce,
participants: group.participants,
};
} catch (error) {
if (reply === 'inner') {
return;
@ -3979,13 +4003,16 @@ export class WAStartupService {
this.logger.verbose('Fetching all groups');
try {
const fetch = Object.values(await this.client.groupFetchAllParticipating());
let groups = [];
for (const group of fetch) {
const picture = await this.profilePicture(group.id);
const groups = fetch.map((group) => {
const result = {
id: group.id,
subject: group.subject,
subjectOwner: group.subjectOwner,
subjectTime: group.subjectTime,
pictureUrl: picture.profilePictureUrl,
size: group.participants.length,
creation: group.creation,
owner: group.owner,
@ -3999,8 +4026,8 @@ export class WAStartupService {
result['participants'] = group.participants;
}
return result;
});
groups = [...groups, result];
}
return groups;
} catch (error) {