Adding SMS automation
This commit is contained in:
@@ -16,6 +16,7 @@ import { PipelinesService } from './pipelines.service';
|
||||
import { toJsonCustomFields } from '../common/custom-fields';
|
||||
import { NotificationsService } from '../notifications/notifications.service';
|
||||
import { AutomationsService } from '../automations/automations.service';
|
||||
import { MessageAutomationsService } from '../message-automations/message-automations.service';
|
||||
import {
|
||||
type Actor,
|
||||
canReassignOwner,
|
||||
@@ -39,6 +40,7 @@ export class DealsService {
|
||||
private readonly pipelines: PipelinesService,
|
||||
private readonly notifications: NotificationsService,
|
||||
private readonly automations: AutomationsService,
|
||||
private readonly messageAutomations: MessageAutomationsService,
|
||||
) {}
|
||||
|
||||
async get(
|
||||
@@ -147,16 +149,18 @@ export class DealsService {
|
||||
include: dealInclude,
|
||||
});
|
||||
|
||||
await this.automations.runTrigger('deal_created', {
|
||||
const createdCtx = {
|
||||
organizationId,
|
||||
entityType: 'deal',
|
||||
entityType: 'deal' as const,
|
||||
entityId: created.id,
|
||||
title: created.title,
|
||||
personId: created.personId,
|
||||
companyId: created.companyId,
|
||||
dealId: created.id,
|
||||
ownerId: created.ownerId,
|
||||
});
|
||||
};
|
||||
await this.automations.runTrigger('deal_created', createdCtx);
|
||||
await this.messageAutomations.onEvent('deal_created', createdCtx);
|
||||
|
||||
return this.pipelines.toDealDto(created);
|
||||
}
|
||||
@@ -313,11 +317,14 @@ export class DealsService {
|
||||
ownerId: deal.ownerId,
|
||||
};
|
||||
await this.automations.runTrigger('deal_stage_changed', ctx);
|
||||
await this.messageAutomations.onEvent('deal_stage_changed', ctx);
|
||||
if (status === 'won' && deal.status !== 'won') {
|
||||
await this.automations.runTrigger('deal_won', ctx);
|
||||
await this.messageAutomations.onEvent('deal_won', ctx);
|
||||
}
|
||||
if (status === 'lost' && deal.status !== 'lost') {
|
||||
await this.automations.runTrigger('deal_lost', ctx);
|
||||
await this.messageAutomations.onEvent('deal_lost', ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,15 @@ import { PipelinesService } from './pipelines.service';
|
||||
import { NotificationsModule } from '../notifications/notifications.module';
|
||||
import { AuthModule } from '../auth/auth.module';
|
||||
import { AutomationsModule } from '../automations/automations.module';
|
||||
import { MessageAutomationsModule } from '../message-automations/message-automations.module';
|
||||
|
||||
@Module({
|
||||
imports: [NotificationsModule, AuthModule, forwardRef(() => AutomationsModule)],
|
||||
imports: [
|
||||
NotificationsModule,
|
||||
AuthModule,
|
||||
forwardRef(() => AutomationsModule),
|
||||
MessageAutomationsModule,
|
||||
],
|
||||
controllers: [PipelinesController, DealsController],
|
||||
providers: [PipelinesService, DealsService],
|
||||
exports: [PipelinesService, DealsService],
|
||||
|
||||
Reference in New Issue
Block a user