mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 09:51:24 -06:00
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:
parent
ff31ef912e
commit
56df0caab0
@ -10,6 +10,7 @@
|
|||||||
* Removed excessive verbose logs
|
* Removed excessive verbose logs
|
||||||
* Optimization in instance registration
|
* Optimization in instance registration
|
||||||
* Correction of variables breaking lines in typebot
|
* 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
|
### Break changes
|
||||||
* jwt authentication removed
|
* jwt authentication removed
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
"start:prod": "bash start.sh",
|
"start:prod": "bash start.sh",
|
||||||
"dev:server": "clear && tsnd --files --transpile-only --respawn --ignore-watch node_modules ./src/main.ts",
|
"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",
|
"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": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -70,13 +70,13 @@ 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)
|
||||||
labels Json? @db.JsonB
|
labels Json? @db.JsonB
|
||||||
createdAt DateTime? @default(now()) @db.Timestamp
|
createdAt DateTime? @default(now()) @db.Timestamp
|
||||||
updatedAt DateTime? @updatedAt @db.Timestamp
|
updatedAt DateTime? @updatedAt @db.Timestamp
|
||||||
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
|
||||||
instanceId String
|
instanceId String
|
||||||
}
|
}
|
||||||
|
|
||||||
model Contact {
|
model Contact {
|
||||||
@ -256,6 +256,7 @@ model TypebotSession {
|
|||||||
sessionId String @db.VarChar(100)
|
sessionId String @db.VarChar(100)
|
||||||
status String @db.VarChar(100)
|
status String @db.VarChar(100)
|
||||||
prefilledVariables Json? @db.JsonB
|
prefilledVariables Json? @db.JsonB
|
||||||
|
awaitUser Boolean @default(false) @db.Boolean
|
||||||
createdAt DateTime? @default(now()) @db.Timestamp
|
createdAt DateTime? @default(now()) @db.Timestamp
|
||||||
updatedAt DateTime @updatedAt @db.Timestamp
|
updatedAt DateTime @updatedAt @db.Timestamp
|
||||||
Typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade)
|
Typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade)
|
||||||
|
@ -309,6 +309,7 @@ export class TypebotService {
|
|||||||
pushName: data.pushName || '',
|
pushName: data.pushName || '',
|
||||||
instanceName: instance.instanceName,
|
instanceName: instance.instanceName,
|
||||||
},
|
},
|
||||||
|
awaitUser: false,
|
||||||
typebotId: data.typebotId,
|
typebotId: data.typebotId,
|
||||||
instanceId: instance.instanceId,
|
instanceId: instance.instanceId,
|
||||||
},
|
},
|
||||||
@ -337,6 +338,7 @@ export class TypebotService {
|
|||||||
clientSideActions,
|
clientSideActions,
|
||||||
this.eventEmitter,
|
this.eventEmitter,
|
||||||
applyFormatting,
|
applyFormatting,
|
||||||
|
this.prismaRepository,
|
||||||
).catch((err) => {
|
).catch((err) => {
|
||||||
console.error('Erro ao processar mensagens:', err);
|
console.error('Erro ao processar mensagens:', err);
|
||||||
});
|
});
|
||||||
@ -420,10 +422,10 @@ export class TypebotService {
|
|||||||
clientSideActions,
|
clientSideActions,
|
||||||
eventEmitter,
|
eventEmitter,
|
||||||
applyFormatting,
|
applyFormatting,
|
||||||
|
prismaRepository,
|
||||||
) {
|
) {
|
||||||
for (const message of messages) {
|
for (const message of messages) {
|
||||||
if (message.type === 'text') {
|
if (message.type === 'text') {
|
||||||
console.log('message.content.richText', message.content.richText);
|
|
||||||
let formattedText = '';
|
let formattedText = '';
|
||||||
|
|
||||||
for (const richText of message.content.richText) {
|
for (const richText of message.content.richText) {
|
||||||
@ -471,7 +473,6 @@ export class TypebotService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(clientSideActions);
|
|
||||||
const wait = findItemAndGetSecondsToWait(clientSideActions, message.id);
|
const wait = findItemAndGetSecondsToWait(clientSideActions, message.id);
|
||||||
|
|
||||||
if (wait) {
|
if (wait) {
|
||||||
@ -497,6 +498,15 @@ export class TypebotService {
|
|||||||
text: formattedText,
|
text: formattedText,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await prismaRepository.typebotSession.update({
|
||||||
|
where: {
|
||||||
|
id: session.id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
awaitUser: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
eventEmitter.emit('typebot:end', {
|
eventEmitter.emit('typebot:end', {
|
||||||
sessionId: session.id,
|
sessionId: session.id,
|
||||||
@ -522,6 +532,8 @@ export class TypebotService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (session && !session.awaitUser) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (session && expire && expire > 0) {
|
if (session && expire && expire > 0) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
@ -712,13 +724,12 @@ export class TypebotService {
|
|||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
status: 'opened',
|
status: 'opened',
|
||||||
|
awaitUser: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const content = this.getConversationMessage(msg.message);
|
const content = this.getConversationMessage(msg.message);
|
||||||
|
|
||||||
console.log('content', content);
|
|
||||||
|
|
||||||
if (!content) {
|
if (!content) {
|
||||||
if (unknownMessage) {
|
if (unknownMessage) {
|
||||||
this.waMonitor.waInstances[instance.instanceName].textMessage({
|
this.waMonitor.waInstances[instance.instanceName].textMessage({
|
||||||
@ -755,11 +766,8 @@ export class TypebotService {
|
|||||||
sessionId: session.sessionId.split('-')[1],
|
sessionId: session.sessionId.split('-')[1],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
console.log('reqData', reqData);
|
|
||||||
const request = await axios.post(urlTypebot, reqData);
|
const request = await axios.post(urlTypebot, reqData);
|
||||||
|
|
||||||
console.log('request', request.data);
|
|
||||||
|
|
||||||
await this.sendWAMessage(
|
await this.sendWAMessage(
|
||||||
instance,
|
instance,
|
||||||
session,
|
session,
|
||||||
|
Loading…
Reference in New Issue
Block a user