integrations

This commit is contained in:
Davidson Gomes 2024-06-08 10:31:52 -03:00
parent cbb5d1d048
commit de89f03f13
7 changed files with 145 additions and 287 deletions

View File

@ -72,7 +72,6 @@ model Session {
model Chat { model Chat {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
remoteJid String @db.VarChar(100) remoteJid String @db.VarChar(100)
lastMsgTimestamp String? @db.VarChar(100)
labels Json? @db.JsonB labels Json? @db.JsonB
createdAt DateTime? @default(now()) @db.Date createdAt DateTime? @default(now()) @db.Date
updatedAt DateTime? @updatedAt @db.Date updatedAt DateTime? @updatedAt @db.Date
@ -100,7 +99,7 @@ model Message {
message Json @db.JsonB message Json @db.JsonB
contextInfo Json? @db.JsonB contextInfo Json? @db.JsonB
source DeviceMessage source DeviceMessage
messageTimestamp String @db.VarChar(100) messageTimestamp Int @db.Integer
chatwootMessageId Int? @db.Integer chatwootMessageId Int? @db.Integer
chatwootInboxId Int? @db.Integer chatwootInboxId Int? @db.Integer
chatwootConversationId Int? @db.Integer chatwootConversationId Int? @db.Integer
@ -119,7 +118,7 @@ model MessageUpdate {
remoteJid String @db.VarChar(100) remoteJid String @db.VarChar(100)
fromMe Boolean @db.Boolean fromMe Boolean @db.Boolean
participant String? @db.VarChar(100) participant String? @db.VarChar(100)
dateTime DateTime @db.Date dateTime Int @db.Integer
pollUpdates Json? @db.JsonB pollUpdates Json? @db.JsonB
status String @db.VarChar(30) status String @db.VarChar(30)
Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade) Message Message @relation(fields: [messageId], references: [id], onDelete: Cascade)

View File

@ -18,8 +18,8 @@ export class TypebotController {
} else { } else {
const saveData = await this.typebotService.find(instance); const saveData = await this.typebotService.find(instance);
if (saveData.enabled) { if (saveData?.typebot?.enabled) {
data.sessions = saveData.sessions; data.sessions = saveData?.sessions;
} }
} }

View File

@ -2,9 +2,10 @@ import { Message } from '@prisma/client';
import axios from 'axios'; import axios from 'axios';
import EventEmitter2 from 'eventemitter2'; import EventEmitter2 from 'eventemitter2';
import { ConfigService, Typebot } from '../../../../config/env.config'; import { Auth, ConfigService, Typebot } from '../../../../config/env.config';
import { Logger } from '../../../../config/logger.config'; import { Logger } from '../../../../config/logger.config';
import { InstanceDto } from '../../../dto/instance.dto'; import { InstanceDto } from '../../../dto/instance.dto';
import { PrismaRepository } from '../../../repository/repository.service';
import { WAMonitoringService } from '../../../services/monitor.service'; import { WAMonitoringService } from '../../../services/monitor.service';
import { Events } from '../../../types/wa.types'; import { Events } from '../../../types/wa.types';
import { TypebotDto } from '../dto/typebot.dto'; import { TypebotDto } from '../dto/typebot.dto';
@ -13,6 +14,7 @@ export class TypebotService {
constructor( constructor(
private readonly waMonitor: WAMonitoringService, private readonly waMonitor: WAMonitoringService,
private readonly configService: ConfigService, private readonly configService: ConfigService,
private readonly prismaRepository: PrismaRepository,
private readonly eventEmitter: EventEmitter2, private readonly eventEmitter: EventEmitter2,
) { ) {
this.eventEmitter.on('typebot:end', async (data) => { this.eventEmitter.on('typebot:end', async (data) => {
@ -31,17 +33,26 @@ export class TypebotService {
return { typebot: { ...instance, typebot: data } }; return { typebot: { ...instance, typebot: data } };
} }
public async find(instance: InstanceDto): Promise<TypebotDto> { public async find(instance: InstanceDto): Promise<any> {
try { try {
const result = await this.waMonitor.waInstances[instance.instanceName].findTypebot(); const typebot = await this.waMonitor.waInstances[instance.instanceName].findTypebot();
if (Object.keys(result).length === 0) { if (Object.keys(typebot).length === 0) {
throw new Error('Typebot not found'); throw new Error('Typebot not found');
} }
return result; const sessions = await this.prismaRepository.typebotSession.findMany({
where: {
typebotId: typebot.id,
},
});
return {
typebot,
sessions,
};
} catch (error) { } catch (error) {
return { enabled: false, url: '', typebot: '', expire: 0, sessions: [] }; return null;
} }
} }
@ -51,96 +62,55 @@ export class TypebotService {
const findData = await this.find(instance); const findData = await this.find(instance);
const session = findData.sessions.find((session) => session.remoteJid === remoteJid); const session = await this.prismaRepository.typebotSession.updateMany({
where: {
if (session) { typebotId: findData?.typebot?.id,
if (status === 'closed') { remoteJid: remoteJid,
findData.sessions.splice(findData.sessions.indexOf(session), 1); },
data: {
const typebotData = { status: status,
enabled: findData.enabled, },
url: findData.url, });
typebot: findData.typebot,
expire: findData.expire,
keywordFinish: findData.keywordFinish,
delayMessage: findData.delayMessage,
unknownMessage: findData.unknownMessage,
listeningFromMe: findData.listeningFromMe,
sessions: findData.sessions,
};
this.create(instance, typebotData);
return { typebot: { ...instance, typebot: typebotData } };
}
findData.sessions.map((session) => {
if (session.remoteJid === remoteJid) {
session.status = status;
}
});
} else if (status === 'paused') {
// const session: Session = {
// remoteJid: remoteJid,
// sessionId: Math.floor(Math.random() * 10000000000).toString(),
// status: status,
// createdAt: Date.now(),
// updateAt: Date.now(),
// prefilledVariables: {
// remoteJid: remoteJid,
// pushName: '',
// additionalData: {},
// },
// };
// findData.sessions.push(session);
}
const typebotData = { const typebotData = {
enabled: findData.enabled,
url: findData.url,
typebot: findData.typebot,
expire: findData.expire,
keywordFinish: findData.keywordFinish,
delayMessage: findData.delayMessage,
unknownMessage: findData.unknownMessage,
listeningFromMe: findData.listeningFromMe,
sessions: findData.sessions,
};
this.create(instance, typebotData);
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_CHANGE_STATUS, {
remoteJid: remoteJid, remoteJid: remoteJid,
status: status, status: status,
url: findData.url, url: findData?.typebot?.url,
typebot: findData.typebot, typebot: findData?.typebot?.typebot,
session, session,
}); };
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_CHANGE_STATUS, typebotData);
return { typebot: { ...instance, typebot: typebotData } }; return { typebot: { ...instance, typebot: typebotData } };
} }
public async clearSessions(instance: InstanceDto, remoteJid: string) { public async clearSessions(instance: InstanceDto, remoteJid: string) {
const findTypebot = await this.find(instance); const findTypebot = await this.find(instance);
const sessions = []; const sessions = await this.prismaRepository.typebotSession.findMany({
// const sessions = (findTypebot.sessions as Session[]) ?? []; where: {
typebotId: findTypebot?.typebot?.id,
remoteJid: remoteJid,
},
});
const sessionWithRemoteJid = sessions.filter((session) => session.remoteJid === remoteJid); if (sessions.length > 0) {
await this.prismaRepository.typebotSession.deleteMany({
if (sessionWithRemoteJid.length > 0) { where: {
sessionWithRemoteJid.forEach((session) => { typebotId: findTypebot?.typebot?.id,
sessions.splice(sessions.indexOf(session), 1); remoteJid: remoteJid,
},
}); });
const typebotData = { const typebotData = {
enabled: findTypebot.enabled, enabled: findTypebot?.typebot?.enabled,
url: findTypebot.url, url: findTypebot?.typebot?.url,
typebot: findTypebot.typebot, typebot: findTypebot?.typebot?.typebot,
expire: findTypebot.expire, expire: findTypebot?.typebot?.expire,
keywordFinish: findTypebot.keywordFinish, keywordFinish: findTypebot?.typebot?.keywordFinish,
delayMessage: findTypebot.delayMessage, delayMessage: findTypebot?.typebot?.delayMessage,
unknownMessage: findTypebot.unknownMessage, unknownMessage: findTypebot?.typebot?.unknownMessage,
listeningFromMe: findTypebot.listeningFromMe, listeningFromMe: findTypebot?.typebot?.listeningFromMe,
sessions, sessions,
}; };
@ -161,17 +131,20 @@ export class TypebotService {
const startSession = data.startSession; const startSession = data.startSession;
const variables = data.variables; const variables = data.variables;
const findTypebot = await this.find(instance); const findTypebot = await this.find(instance);
const expire = findTypebot.expire; const expire = findTypebot?.typebot?.expire;
const keywordFinish = findTypebot.keywordFinish; const keywordFinish = findTypebot?.typebot?.keywordFinish;
const delayMessage = findTypebot.delayMessage; const delayMessage = findTypebot?.typebot?.delayMessage;
const unknownMessage = findTypebot.unknownMessage; const unknownMessage = findTypebot?.typebot?.unknownMessage;
const listeningFromMe = findTypebot.listeningFromMe; const listeningFromMe = findTypebot?.typebot?.listeningFromMe;
const prefilledVariables = { const prefilledVariables = {
remoteJid: remoteJid, remoteJid: remoteJid,
instanceName: instance.instanceName, instanceName: instance.instanceName,
}; };
if (this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES)
prefilledVariables['token'] = instance.token;
if (variables?.length) { if (variables?.length) {
variables.forEach((variable: { name: string | number; value: string }) => { variables.forEach((variable: { name: string | number; value: string }) => {
prefilledVariables[variable.name] = variable.value; prefilledVariables[variable.name] = variable.value;
@ -179,10 +152,15 @@ export class TypebotService {
} }
if (startSession) { if (startSession) {
const newSessions = await this.clearSessions(instance, remoteJid); await this.prismaRepository.typebotSession.deleteMany({
where: {
typebotId: findTypebot.typebot.id,
remoteJid: remoteJid,
},
});
const response = await this.createNewSession(instance, { const response = await this.createNewSession(instance, {
enabled: findTypebot.enabled, enabled: findTypebot?.typebot?.enabled,
url: url, url: url,
typebot: typebot, typebot: typebot,
remoteJid: remoteJid, remoteJid: remoteJid,
@ -191,8 +169,8 @@ export class TypebotService {
delayMessage: delayMessage, delayMessage: delayMessage,
unknownMessage: unknownMessage, unknownMessage: unknownMessage,
listeningFromMe: listeningFromMe, listeningFromMe: listeningFromMe,
sessions: newSessions,
prefilledVariables: prefilledVariables, prefilledVariables: prefilledVariables,
typebotId: findTypebot.typebot.id,
}); });
if (response.sessionId) { if (response.sessionId) {
@ -306,70 +284,6 @@ export class TypebotService {
return messageContent; return messageContent;
} }
private getAudioMessageContent(msg: any) {
const types = this.getTypeMessage(msg);
const audioContent = types.audioMessage;
return audioContent;
}
private getImageMessageContent(msg: any) {
const types = this.getTypeMessage(msg);
const imageContent = types.imageMessage;
return imageContent;
}
private getVideoMessageContent(msg: any) {
const types = this.getTypeMessage(msg);
const videoContent = types.videoMessage;
return videoContent;
}
private getDocumentMessageContent(msg: any) {
const types = this.getTypeMessage(msg);
const documentContent = types.documentMessage;
return documentContent;
}
private getContactMessageContent(msg: any) {
const types = this.getTypeMessage(msg);
const contactContent = types.contactMessage;
return contactContent;
}
private getLocationMessageContent(msg: any) {
const types = this.getTypeMessage(msg);
const locationContent = types.locationMessage;
return locationContent;
}
private getViewOnceMessageV2Content(msg: any) {
const types = this.getTypeMessage(msg);
const viewOnceContent = types.viewOnceMessageV2;
return viewOnceContent;
}
private getListResponseMessageContent(msg: any) {
const types = this.getTypeMessage(msg);
const listResponseContent = types.listResponseMessage || types.responseRowId;
return listResponseContent;
}
public async createNewSession(instance: InstanceDto, data: any) { public async createNewSession(instance: InstanceDto, data: any) {
if (data.remoteJid === 'status@broadcast') return; if (data.remoteJid === 'status@broadcast') return;
const id = Math.floor(Math.random() * 10000000000).toString(); const id = Math.floor(Math.random() * 10000000000).toString();
@ -407,33 +321,22 @@ export class TypebotService {
const request = await axios.post(url, reqData); const request = await axios.post(url, reqData);
if (request?.data?.sessionId) { if (request?.data?.sessionId) {
data.sessions.push({ await this.prismaRepository.typebotSession.create({
remoteJid: data.remoteJid, data: {
sessionId: `${id}-${request.data.sessionId}`,
status: 'opened',
createdAt: Date.now(),
updateAt: Date.now(),
prefilledVariables: {
...data.prefilledVariables,
remoteJid: data.remoteJid, remoteJid: data.remoteJid,
pushName: data.pushName || '', pushName: data.pushName || '',
instanceName: instance.instanceName, sessionId: `${id}-${request.data.sessionId}`,
status: 'opened',
prefilledVariables: {
...data.prefilledVariables,
remoteJid: data.remoteJid,
pushName: data.pushName || '',
instanceName: instance.instanceName,
},
typebotId: data.typebotId,
instanceId: instance.instanceId,
}, },
}); });
const typebotData = {
enabled: data.enabled,
url: data.url,
typebot: data.typebot,
expire: data.expire,
keywordFinish: data.keywordFinish,
delayMessage: data.delayMessage,
unknownMessage: data.unknownMessage,
listeningFromMe: data.listeningFromMe,
sessions: data.sessions,
};
this.create(instance, typebotData);
} }
return request.data; return request.data;
} catch (error) { } catch (error) {
@ -636,16 +539,14 @@ export class TypebotService {
public async sendTypebot(instance: InstanceDto, remoteJid: string, msg: Message) { public async sendTypebot(instance: InstanceDto, remoteJid: string, msg: Message) {
const findTypebot = await this.find(instance); const findTypebot = await this.find(instance);
const url = findTypebot.url; const url = findTypebot.typebot?.url;
const typebot = findTypebot.typebot; const typebot = findTypebot.typebot?.typebot;
// const sessions = (findTypebot.sessions as Session[]) ?? []; const sessions = findTypebot.sessions;
const sessions = []; const expire = findTypebot.typebot?.expire;
const expire = findTypebot.expire; const keywordFinish = findTypebot.typebot?.keywordFinish;
const keywordFinish = findTypebot.keywordFinish; const delayMessage = findTypebot.typebot?.delayMessage;
const delayMessage = findTypebot.delayMessage; const unknownMessage = findTypebot.typebot?.unknownMessage;
const unknownMessage = findTypebot.unknownMessage; const listeningFromMe = findTypebot.typebot?.listeningFromMe;
const listeningFromMe = findTypebot.listeningFromMe;
const messageType = this.getTypeMessage(msg.message).messageType;
const session = sessions.find((session) => session.remoteJid === remoteJid); const session = sessions.find((session) => session.remoteJid === remoteJid);
@ -653,15 +554,22 @@ export class TypebotService {
if (session && expire && expire > 0) { if (session && expire && expire > 0) {
const now = Date.now(); const now = Date.now();
const diff = now - session.updateAt; const sessionUpdatedAt = new Date(session.updatedAt).getTime();
const diff = now - sessionUpdatedAt;
const diffInMinutes = Math.floor(diff / 1000 / 60); const diffInMinutes = Math.floor(diff / 1000 / 60);
if (diffInMinutes > expire) { if (diffInMinutes > expire) {
const newSessions = await this.clearSessions(instance, remoteJid); await this.prismaRepository.typebotSession.deleteMany({
where: {
typebotId: findTypebot.typebot.id,
remoteJid: remoteJid,
},
});
const data = await this.createNewSession(instance, { const data = await this.createNewSession(instance, {
enabled: findTypebot.enabled, enabled: findTypebot.typebot.enabled,
url: url, url: url,
typebot: typebot, typebot: typebot,
expire: expire, expire: expire,
@ -669,9 +577,9 @@ export class TypebotService {
delayMessage: delayMessage, delayMessage: delayMessage,
unknownMessage: unknownMessage, unknownMessage: unknownMessage,
listeningFromMe: listeningFromMe, listeningFromMe: listeningFromMe,
sessions: newSessions,
remoteJid: remoteJid, remoteJid: remoteJid,
pushName: msg.pushName, pushName: msg.pushName,
typebotId: findTypebot.typebot.id,
}); });
await this.sendWAMessage(instance, remoteJid, data.messages, data.input, data.clientSideActions); await this.sendWAMessage(instance, remoteJid, data.messages, data.input, data.clientSideActions);
@ -691,22 +599,12 @@ export class TypebotService {
} }
if (keywordFinish && content.toLowerCase() === keywordFinish.toLowerCase()) { if (keywordFinish && content.toLowerCase() === keywordFinish.toLowerCase()) {
const newSessions = await this.clearSessions(instance, remoteJid); await this.prismaRepository.typebotSession.deleteMany({
where: {
const typebotData = { typebotId: findTypebot.typebot.id,
enabled: findTypebot.enabled, remoteJid: remoteJid,
url: url, },
typebot: typebot, });
expire: expire,
keywordFinish: keywordFinish,
delayMessage: delayMessage,
unknownMessage: unknownMessage,
listeningFromMe: listeningFromMe,
sessions: newSessions,
};
this.create(instance, typebotData);
return; return;
} }
@ -752,7 +650,7 @@ export class TypebotService {
if (!session) { if (!session) {
const data = await this.createNewSession(instance, { const data = await this.createNewSession(instance, {
enabled: findTypebot.enabled, enabled: findTypebot.typebot?.enabled,
url: url, url: url,
typebot: typebot, typebot: typebot,
expire: expire, expire: expire,
@ -760,15 +658,12 @@ export class TypebotService {
delayMessage: delayMessage, delayMessage: delayMessage,
unknownMessage: unknownMessage, unknownMessage: unknownMessage,
listeningFromMe: listeningFromMe, listeningFromMe: listeningFromMe,
sessions: sessions,
remoteJid: remoteJid, remoteJid: remoteJid,
pushName: msg.pushName, pushName: msg.pushName,
prefilledVariables: { typebotId: findTypebot.typebot.id,
messageType: messageType,
},
}); });
await this.sendWAMessage(instance, remoteJid, data.messages, data.input, data.clientSideActions); await this.sendWAMessage(instance, remoteJid, data?.messages, data?.input, data?.clientSideActions);
if (data.messages.length === 0) { if (data.messages.length === 0) {
const content = this.getConversationMessage(msg.message); const content = this.getConversationMessage(msg.message);
@ -785,21 +680,12 @@ export class TypebotService {
} }
if (keywordFinish && content.toLowerCase() === keywordFinish.toLowerCase()) { if (keywordFinish && content.toLowerCase() === keywordFinish.toLowerCase()) {
const newSessions = await this.clearSessions(instance, remoteJid); await this.prismaRepository.typebotSession.deleteMany({
where: {
const typebotData = { typebotId: findTypebot.typebot.id,
enabled: findTypebot.enabled, remoteJid: remoteJid,
url: url, },
typebot: typebot, });
expire: expire,
keywordFinish: keywordFinish,
delayMessage: delayMessage,
unknownMessage: unknownMessage,
listeningFromMe: listeningFromMe,
sessions: newSessions,
};
this.create(instance, typebotData);
return; return;
} }
@ -838,26 +724,15 @@ export class TypebotService {
return; return;
} }
sessions.map((session) => { await this.prismaRepository.typebotSession.update({
if (session.remoteJid === remoteJid) { where: {
session.updateAt = Date.now(); id: session.id,
} },
data: {
status: 'opened',
},
}); });
const typebotData = {
enabled: findTypebot.enabled,
url: url,
typebot: typebot,
expire: expire,
keywordFinish: keywordFinish,
delayMessage: delayMessage,
unknownMessage: unknownMessage,
listeningFromMe: listeningFromMe,
sessions,
};
this.create(instance, typebotData);
const content = this.getConversationMessage(msg.message); const content = this.getConversationMessage(msg.message);
if (!content) { if (!content) {
@ -872,22 +747,12 @@ export class TypebotService {
} }
if (keywordFinish && content.toLowerCase() === keywordFinish.toLowerCase()) { if (keywordFinish && content.toLowerCase() === keywordFinish.toLowerCase()) {
const newSessions = await this.clearSessions(instance, remoteJid); await this.prismaRepository.typebotSession.deleteMany({
where: {
const typebotData = { typebotId: findTypebot.typebot.id,
enabled: findTypebot.enabled, remoteJid: remoteJid,
url: url, },
typebot: typebot, });
expire: expire,
keywordFinish: keywordFinish,
delayMessage: delayMessage,
unknownMessage: unknownMessage,
listeningFromMe: listeningFromMe,
sessions: newSessions,
};
this.create(instance, typebotData);
return; return;
} }

View File

@ -24,13 +24,13 @@ export const typebotSchema: JSONSchema7 = {
$id: v4(), $id: v4(),
type: 'object', type: 'object',
properties: { properties: {
enabled: { type: 'boolean', enum: [true, false] }, enabled: { type: 'boolean' },
url: { type: 'string' }, url: { type: 'string' },
typebot: { type: 'string' }, typebot: { type: 'string' },
expire: { type: 'integer' }, expire: { type: 'integer' },
delayMessage: { type: 'integer' }, delayMessage: { type: 'integer' },
unknownMessage: { type: 'string' }, unknownMessage: { type: 'string' },
listeningFromMe: { type: 'boolean', enum: [true, false] }, listeningFromMe: { type: 'boolean' },
}, },
required: ['enabled', 'url', 'typebot', 'expire', 'delayMessage', 'unknownMessage', 'listeningFromMe'], required: ['enabled', 'url', 'typebot', 'expire', 'delayMessage', 'unknownMessage', 'listeningFromMe'],
...isNotEmpty('enabled', 'url', 'typebot', 'expire', 'delayMessage', 'unknownMessage', 'listeningFromMe'), ...isNotEmpty('enabled', 'url', 'typebot', 'expire', 'delayMessage', 'unknownMessage', 'listeningFromMe'),

View File

@ -54,7 +54,7 @@ export const waMonitor = new WAMonitoringService(
const authService = new AuthService(prismaRepository); const authService = new AuthService(prismaRepository);
const typebotService = new TypebotService(waMonitor, configService, eventEmitter); const typebotService = new TypebotService(waMonitor, configService, prismaRepository, eventEmitter);
export const typebotController = new TypebotController(typebotService); export const typebotController = new TypebotController(typebotService);
const webhookService = new WebhookService(waMonitor); const webhookService = new WebhookService(waMonitor);

View File

@ -71,7 +71,7 @@ export class ChannelStartupService {
this.chatwootCache, this.chatwootCache,
); );
public typebotService = new TypebotService(waMonitor, this.configService, this.eventEmitter); public typebotService = new TypebotService(waMonitor, this.configService, this.prismaRepository, this.eventEmitter);
public setInstance(instance: InstanceDto) { public setInstance(instance: InstanceDto) {
this.instance.name = instance.instanceName; this.instance.name = instance.instanceName;
@ -547,17 +547,7 @@ export class ChannelStartupService {
throw new NotFoundException('Typebot not found'); throw new NotFoundException('Typebot not found');
} }
return { return data;
enabled: data.enabled,
url: data.url,
typebot: data.typebot,
expire: data.expire,
keywordFinish: data.keywordFinish,
delayMessage: data.delayMessage,
unknownMessage: data.unknownMessage,
listeningFromMe: data.listeningFromMe,
sessions: data.sessions,
};
} }
public async loadProxy() { public async loadProxy() {

View File

@ -794,7 +794,7 @@ export class BaileysStartupService extends ChannelStartupService {
remoteJid: chat.id, remoteJid: chat.id,
}, },
data: { data: {
lastMsgTimestamp: Long.fromValue(chat.lastMessageRecvTimestamp).toString(), remoteJid: chat.id,
}, },
}); });
} }
@ -936,7 +936,7 @@ export class BaileysStartupService extends ChannelStartupService {
chatsRaw.push({ chatsRaw.push({
remoteJid: chat.id, remoteJid: chat.id,
instanceId: this.instanceId, instanceId: this.instanceId,
lastMsgTimestamp: chat.lastMessageRecvTimestamp, lastMsgTimestamp: parseInt(chat.lastMessageRecvTimestamp?.toString()).toString(),
}); });
} }
@ -1190,7 +1190,7 @@ export class BaileysStartupService extends ChannelStartupService {
if (!(this.localTypebot.listeningFromMe === false && messageRaw.key.fromMe === true)) { if (!(this.localTypebot.listeningFromMe === false && messageRaw.key.fromMe === true)) {
if (messageRaw.messageType !== 'reactionMessage') if (messageRaw.messageType !== 'reactionMessage')
await this.typebotService.sendTypebot( await this.typebotService.sendTypebot(
{ instanceName: this.instance.name }, { instanceName: this.instance.name, instanceId: this.instanceId },
messageRaw.key.remoteJid, messageRaw.key.remoteJid,
messageRaw, messageRaw,
); );
@ -1312,7 +1312,7 @@ export class BaileysStartupService extends ChannelStartupService {
fromMe: key.fromMe, fromMe: key.fromMe,
participant: key?.remoteJid, participant: key?.remoteJid,
status: 'DELETED', status: 'DELETED',
dateTime: Date.now(), dateTime: parseInt(new Date().getTime().toString()).toString(),
instanceId: this.instanceId, instanceId: this.instanceId,
}; };
@ -1338,7 +1338,7 @@ export class BaileysStartupService extends ChannelStartupService {
fromMe: key.fromMe, fromMe: key.fromMe,
participant: key?.remoteJid, participant: key?.remoteJid,
status: status[update.status], status: status[update.status],
dateTime: Date.now(), dateTime: parseInt(new Date().getTime().toString()).toString(),
pollUpdates, pollUpdates,
instanceId: this.instanceId, instanceId: this.instanceId,
}; };
@ -1878,13 +1878,17 @@ export class BaileysStartupService extends ChannelStartupService {
const contentMsg = messageSent.message[getContentType(messageSent.message)] as any; const contentMsg = messageSent.message[getContentType(messageSent.message)] as any;
if (Long.isLong(messageSent?.messageTimestamp)) {
messageSent.messageTimestamp = messageSent.messageTimestamp?.toNumber();
}
const messageRaw: any = { const messageRaw: any = {
key: messageSent.key, key: messageSent.key,
pushName: messageSent.pushName, pushName: messageSent.pushName,
message: { ...messageSent.message }, message: { ...messageSent.message },
contextInfo: contentMsg?.contextInfo, contextInfo: contentMsg?.contextInfo,
messageType: getContentType(messageSent.message), messageType: getContentType(messageSent.message),
messageTimestamp: Long.fromValue(messageSent.messageTimestamp).toString(), messageTimestamp: messageSent.messageTimestamp as number,
instanceId: this.instanceId, instanceId: this.instanceId,
source: getDevice(messageSent.key.id), source: getDevice(messageSent.key.id),
}; };