mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-22 20:12:02 -06:00
fix: corrected typebot trigger validation
Explanation: This commit fixes an issue in the validation of typebot triggers. The 'findFirst' method was used to search for triggers, but it only returns the first match found. To solve this problem, the 'findMany' method was used instead, and a loop was added to search for all matches. This change ensures that all triggers that match the validation criteria are returned. The modified file is: - typebot.service.ts: this is the main file where the changes were made. It was necessary to modify the function that validates the triggers, replacing the 'findFirst' method with the 'findMany' method and adding a loop to search for all matches. This change improves the validation of typebot triggers, ensuring that all matches are returned, and prevents errors in the trigger validation process.
This commit is contained in:
parent
b3b1fb30c7
commit
c03e0cc954
@ -1292,48 +1292,66 @@ export class TypebotService {
|
||||
if (findTriggerRegex) return findTriggerRegex;
|
||||
|
||||
// Check for startsWith match
|
||||
const findTriggerStartsWith = await this.prismaRepository.typebot.findFirst({
|
||||
const findStartsWith = await this.prismaRepository.typebot.findMany({
|
||||
where: {
|
||||
enabled: true,
|
||||
triggerType: 'keyword',
|
||||
triggerOperator: 'startsWith',
|
||||
triggerValue: {
|
||||
startsWith: content,
|
||||
},
|
||||
instanceId: instanceId,
|
||||
},
|
||||
});
|
||||
|
||||
let findTriggerStartsWith = null;
|
||||
|
||||
for (const startsWith of findStartsWith) {
|
||||
if (content.startsWith(startsWith.triggerValue)) {
|
||||
findTriggerStartsWith = startsWith;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (findTriggerStartsWith) return findTriggerStartsWith;
|
||||
|
||||
// Check for endsWith match
|
||||
const findTriggerEndsWith = await this.prismaRepository.typebot.findFirst({
|
||||
const findEndsWith = await this.prismaRepository.typebot.findMany({
|
||||
where: {
|
||||
enabled: true,
|
||||
triggerType: 'keyword',
|
||||
triggerOperator: 'endsWith',
|
||||
triggerValue: {
|
||||
endsWith: content,
|
||||
},
|
||||
instanceId: instanceId,
|
||||
},
|
||||
});
|
||||
|
||||
let findTriggerEndsWith = null;
|
||||
|
||||
for (const endsWith of findEndsWith) {
|
||||
if (content.endsWith(endsWith.triggerValue)) {
|
||||
findTriggerEndsWith = endsWith;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (findTriggerEndsWith) return findTriggerEndsWith;
|
||||
|
||||
// Check for contains match
|
||||
const findTriggerContains = await this.prismaRepository.typebot.findFirst({
|
||||
const findContains = await this.prismaRepository.typebot.findMany({
|
||||
where: {
|
||||
enabled: true,
|
||||
triggerType: 'keyword',
|
||||
triggerOperator: 'contains',
|
||||
triggerValue: {
|
||||
contains: content,
|
||||
},
|
||||
instanceId: instanceId,
|
||||
},
|
||||
});
|
||||
|
||||
let findTriggerContains = null;
|
||||
|
||||
for (const contains of findContains) {
|
||||
if (content.includes(contains.triggerValue)) {
|
||||
findTriggerContains = contains;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (findTriggerContains) return findTriggerContains;
|
||||
|
||||
const fallback = await this.prismaRepository.typebotSetting.findFirst({
|
||||
|
Loading…
Reference in New Issue
Block a user