mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-09 01:49:37 -06:00
Merge pull request #1927 from josiasmaceda/hotfix/change-typebot-status-webhook
fix: integrate Typebot status change events for webhook in chatbot controller e service
This commit is contained in:
commit
5015cfbc9d
@ -2,6 +2,7 @@ import { IgnoreJidDto } from '@api/dto/chatbot.dto';
|
||||
import { InstanceDto } from '@api/dto/instance.dto';
|
||||
import { PrismaRepository } from '@api/repository/repository.service';
|
||||
import { WAMonitoringService } from '@api/services/monitor.service';
|
||||
import { Events } from '@api/types/wa.types';
|
||||
import { Logger } from '@config/logger.config';
|
||||
import { BadRequestException } from '@exceptions';
|
||||
import { TriggerOperator, TriggerType } from '@prisma/client';
|
||||
@ -446,6 +447,16 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
|
||||
|
||||
const remoteJid = data.remoteJid;
|
||||
const status = data.status;
|
||||
const session = await this.getSession(remoteJid, instance);
|
||||
|
||||
if (this.integrationName === 'Typebot') {
|
||||
const typebotData = {
|
||||
remoteJid: remoteJid,
|
||||
status: status,
|
||||
session,
|
||||
};
|
||||
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_CHANGE_STATUS, typebotData);
|
||||
}
|
||||
|
||||
if (status === 'delete') {
|
||||
await this.sessionRepository.deleteMany({
|
||||
@ -867,6 +878,16 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
|
||||
status: 'paused',
|
||||
},
|
||||
});
|
||||
|
||||
if (this.integrationName === 'Typebot') {
|
||||
const typebotData = {
|
||||
remoteJid: remoteJid,
|
||||
status: 'paused',
|
||||
session,
|
||||
};
|
||||
this.waMonitor.waInstances[instance.instanceName].sendDataWebhook(Events.TYPEBOT_CHANGE_STATUS, typebotData);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { PrismaRepository } from '@api/repository/repository.service';
|
||||
import { WAMonitoringService } from '@api/services/monitor.service';
|
||||
import { Events } from '@api/types/wa.types';
|
||||
import { Auth, ConfigService, HttpServer, Typebot } from '@config/env.config';
|
||||
import { Instance, IntegrationSession, Message, Typebot as TypebotModel } from '@prisma/client';
|
||||
import { getConversationMessage } from '@utils/getConversationMessage';
|
||||
@ -151,6 +152,14 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const typebotData = {
|
||||
remoteJid: data.remoteJid,
|
||||
status: 'opened',
|
||||
session,
|
||||
};
|
||||
this.waMonitor.waInstances[instance.name].sendDataWebhook(Events.TYPEBOT_CHANGE_STATUS, typebotData);
|
||||
|
||||
return { ...request.data, session };
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
@ -399,12 +408,14 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
},
|
||||
});
|
||||
} else {
|
||||
let statusChange = 'closed';
|
||||
if (!settings?.keepOpen) {
|
||||
await prismaRepository.integrationSession.deleteMany({
|
||||
where: {
|
||||
id: session.id,
|
||||
},
|
||||
});
|
||||
statusChange = 'delete';
|
||||
} else {
|
||||
await prismaRepository.integrationSession.update({
|
||||
where: {
|
||||
@ -415,6 +426,13 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const typebotData = {
|
||||
remoteJid: session.remoteJid,
|
||||
status: statusChange,
|
||||
session,
|
||||
};
|
||||
instance.sendDataWebhook(Events.TYPEBOT_CHANGE_STATUS, typebotData);
|
||||
}
|
||||
}
|
||||
|
||||
@ -639,6 +657,7 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
}
|
||||
|
||||
if (keywordFinish && content.toLowerCase() === keywordFinish.toLowerCase()) {
|
||||
let statusChange = 'closed';
|
||||
if (keepOpen) {
|
||||
await this.prismaRepository.integrationSession.update({
|
||||
where: {
|
||||
@ -649,6 +668,7 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
},
|
||||
});
|
||||
} else {
|
||||
statusChange = 'delete';
|
||||
await this.prismaRepository.integrationSession.deleteMany({
|
||||
where: {
|
||||
botId: findTypebot.id,
|
||||
@ -656,6 +676,14 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const typebotData = {
|
||||
remoteJid: remoteJid,
|
||||
status: statusChange,
|
||||
session,
|
||||
};
|
||||
waInstance.sendDataWebhook(Events.TYPEBOT_CHANGE_STATUS, typebotData);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -788,6 +816,7 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
}
|
||||
|
||||
if (keywordFinish && content.toLowerCase() === keywordFinish.toLowerCase()) {
|
||||
let statusChange = 'closed';
|
||||
if (keepOpen) {
|
||||
await this.prismaRepository.integrationSession.update({
|
||||
where: {
|
||||
@ -798,6 +827,7 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
},
|
||||
});
|
||||
} else {
|
||||
statusChange = 'delete';
|
||||
await this.prismaRepository.integrationSession.deleteMany({
|
||||
where: {
|
||||
botId: findTypebot.id,
|
||||
@ -806,6 +836,13 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
});
|
||||
}
|
||||
|
||||
const typebotData = {
|
||||
remoteJid: remoteJid,
|
||||
status: statusChange,
|
||||
session,
|
||||
};
|
||||
waInstance.sendDataWebhook(Events.TYPEBOT_CHANGE_STATUS, typebotData);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -881,6 +918,7 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
}
|
||||
|
||||
if (keywordFinish && content.toLowerCase() === keywordFinish.toLowerCase()) {
|
||||
let statusChange = 'closed';
|
||||
if (keepOpen) {
|
||||
await this.prismaRepository.integrationSession.update({
|
||||
where: {
|
||||
@ -891,6 +929,7 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
},
|
||||
});
|
||||
} else {
|
||||
statusChange = 'delete';
|
||||
await this.prismaRepository.integrationSession.deleteMany({
|
||||
where: {
|
||||
botId: findTypebot.id,
|
||||
@ -898,6 +937,15 @@ export class TypebotService extends BaseChatbotService<TypebotModel, any> {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const typebotData = {
|
||||
remoteJid: remoteJid,
|
||||
status: statusChange,
|
||||
session,
|
||||
};
|
||||
|
||||
waInstance.sendDataWebhook(Events.TYPEBOT_CHANGE_STATUS, typebotData);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user