fix: now in typebot we wait until the terminal block to accept the user's message, if it arrives before the block is sent, it is ignored

This commit is contained in:
Davidson Gomes 2024-06-08 15:09:55 -03:00
parent ff31ef912e
commit 56df0caab0
4 changed files with 27 additions and 15 deletions

View File

@ -10,6 +10,7 @@
* Removed excessive verbose logs
* Optimization in instance registration
* Correction of variables breaking lines in typebot
* Now in typebot we wait until the terminal block to accept the user's message, if it arrives before the block is sent, it is ignored
### Break changes
* jwt authentication removed

View File

@ -9,7 +9,9 @@
"start:prod": "bash start.sh",
"dev:server": "clear && tsnd --files --transpile-only --respawn --ignore-watch node_modules ./src/main.ts",
"test": "clear && tsnd --files --transpile-only --respawn --ignore-watch node_modules ./test/all.test.ts",
"lint": "eslint --fix --ext .ts src"
"lint": "eslint --fix --ext .ts src",
"db:migrate:postgres": "npx prisma migrate dev --name init --schema ./prisma/postgresql-schema.prisma",
"db:migrate:mysql": "npx prisma migrate dev --name init --schema ./prisma/mysql-schema.prisma"
},
"repository": {
"type": "git",

View File

@ -256,6 +256,7 @@ model TypebotSession {
sessionId String @db.VarChar(100)
status String @db.VarChar(100)
prefilledVariables Json? @db.JsonB
awaitUser Boolean @default(false) @db.Boolean
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade)

View File

@ -309,6 +309,7 @@ export class TypebotService {
pushName: data.pushName || '',
instanceName: instance.instanceName,
},
awaitUser: false,
typebotId: data.typebotId,
instanceId: instance.instanceId,
},
@ -337,6 +338,7 @@ export class TypebotService {
clientSideActions,
this.eventEmitter,
applyFormatting,
this.prismaRepository,
).catch((err) => {
console.error('Erro ao processar mensagens:', err);
});
@ -420,10 +422,10 @@ export class TypebotService {
clientSideActions,
eventEmitter,
applyFormatting,
prismaRepository,
) {
for (const message of messages) {
if (message.type === 'text') {
console.log('message.content.richText', message.content.richText);
let formattedText = '';
for (const richText of message.content.richText) {
@ -471,7 +473,6 @@ export class TypebotService {
});
}
console.log(clientSideActions);
const wait = findItemAndGetSecondsToWait(clientSideActions, message.id);
if (wait) {
@ -497,6 +498,15 @@ export class TypebotService {
text: formattedText,
});
}
await prismaRepository.typebotSession.update({
where: {
id: session.id,
},
data: {
awaitUser: true,
},
});
} else {
eventEmitter.emit('typebot:end', {
sessionId: session.id,
@ -522,6 +532,8 @@ export class TypebotService {
},
});
if (session && !session.awaitUser) return;
try {
if (session && expire && expire > 0) {
const now = Date.now();
@ -712,13 +724,12 @@ export class TypebotService {
},
data: {
status: 'opened',
awaitUser: false,
},
});
const content = this.getConversationMessage(msg.message);
console.log('content', content);
if (!content) {
if (unknownMessage) {
this.waMonitor.waInstances[instance.instanceName].textMessage({
@ -755,11 +766,8 @@ export class TypebotService {
sessionId: session.sessionId.split('-')[1],
};
}
console.log('reqData', reqData);
const request = await axios.post(urlTypebot, reqData);
console.log('request', request.data);
await this.sendWAMessage(
instance,
session,