adjusts in typebot

This commit is contained in:
Davidson Gomes
2024-06-10 16:38:11 -03:00
parent 4824ccafd6
commit fa3306b0f4
4 changed files with 34 additions and 21 deletions

View File

@@ -1,7 +1,7 @@
import { Message, TypebotSession } from '@prisma/client';
import axios from 'axios';
import { Auth, ConfigService, Typebot } from '../../../../config/env.config';
import { ConfigService, Typebot } from '../../../../config/env.config';
import { Logger } from '../../../../config/logger.config';
import { InstanceDto } from '../../../dto/instance.dto';
import { PrismaRepository } from '../../../repository/repository.service';
@@ -484,25 +484,35 @@ export class TypebotService {
const remoteJid = data.remoteJid;
const status = data.status;
const session = await this.prismaRepository.typebotSession.updateMany({
where: {
instanceId: instanceId,
if (status === 'closed') {
await this.prismaRepository.typebotSession.deleteMany({
where: {
remoteJid: remoteJid,
},
});
return { typebot: { ...instance, typebot: { remoteJid: remoteJid, status: status } } };
} else {
const session = await this.prismaRepository.typebotSession.updateMany({
where: {
instanceId: instanceId,
remoteJid: remoteJid,
},
data: {
status: status,
},
});
const typebotData = {
remoteJid: remoteJid,
},
data: {
status: status,
},
});
session,
};
const typebotData = {
remoteJid: remoteJid,
status: status,
session,
};
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_CHANGE_STATUS, typebotData);
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_CHANGE_STATUS, typebotData);
return { typebot: { ...instance, typebot: typebotData } };
return { typebot: { ...instance, typebot: typebotData } };
}
} catch (error) {
this.logger.error(error);
throw new Error('Error changing status');
@@ -569,9 +579,6 @@ export class TypebotService {
instanceName: instance.instanceName,
};
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES)
prefilledVariables['token'] = instance.token;
if (variables?.length) {
variables.forEach((variable: { name: string | number; value: string }) => {
prefilledVariables[variable.name] = variable.value;

View File

@@ -1120,7 +1120,11 @@ export class BaileysStartupService extends ChannelStartupService {
const contentMsg = received?.message[getContentType(received.message)] as any;
if (this.localWebhook.webhookBase64 === true && isMedia) {
if (
this.localWebhook.webhookBase64 === true ||
(this.configService.get<Typebot>('TYPEBOT').SEND_MEDIA_BASE64 && isMedia)
) {
console.log('Download media');
const buffer = await downloadMediaMessage(
{ key: received.key, message: received?.message },
'buffer',