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

View File

@ -2556,6 +2556,12 @@ export class WAStartupService {
public async fetchProfile(instanceName: string, number?: string) { public async fetchProfile(instanceName: string, number?: string) {
const jid = number ? this.createJid(number) : this.client?.user?.id; 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); this.logger.verbose('Getting profile with jid: ' + jid);
try { try {
this.logger.verbose('Getting profile info'); this.logger.verbose('Getting profile info');
@ -3966,7 +3972,25 @@ export class WAStartupService {
public async findGroup(id: GroupJid, reply: 'inner' | 'out' = 'out') { public async findGroup(id: GroupJid, reply: 'inner' | 'out' = 'out') {
this.logger.verbose('Fetching group'); this.logger.verbose('Fetching group');
try { 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) { } catch (error) {
if (reply === 'inner') { if (reply === 'inner') {
return; return;
@ -3979,13 +4003,16 @@ export class WAStartupService {
this.logger.verbose('Fetching all groups'); this.logger.verbose('Fetching all groups');
try { try {
const fetch = Object.values(await this.client.groupFetchAllParticipating()); 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 = { const result = {
id: group.id, id: group.id,
subject: group.subject, subject: group.subject,
subjectOwner: group.subjectOwner, subjectOwner: group.subjectOwner,
subjectTime: group.subjectTime, subjectTime: group.subjectTime,
pictureUrl: picture.profilePictureUrl,
size: group.participants.length, size: group.participants.length,
creation: group.creation, creation: group.creation,
owner: group.owner, owner: group.owner,
@ -3999,8 +4026,8 @@ export class WAStartupService {
result['participants'] = group.participants; result['participants'] = group.participants;
} }
return result; groups = [...groups, result];
}); }
return groups; return groups;
} catch (error) { } catch (error) {